libtasks Documentation  1.6
uwsgi_task.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <tasks/logging.h>
9 #include <tasks/net/uwsgi_task.h>
10 
11 #include <sstream>
12 
13 namespace tasks {
14 namespace net {
15 
16 bool uwsgi_task::handle_event(tasks::worker* /* worker */, int revents) {
17  bool success = true;
18  try {
19  if (EV_READ & revents) {
21  if (m_request.done()) {
22  if (UWSGI_VARS == m_request.header().modifier1) {
23  success = handle_request();
24  m_request.clear();
25  } else {
26  // No suuport for anything else for now
27  std::ostringstream os;
28  os << "uwsgi_task: unsupported uwsgi packet: "
29  << "modifier1=" << (int)m_request.header().modifier1
30  << " datasize=" << m_request.header().datasize
31  << " modifier2=" << (int)m_request.header().modifier2;
33  set_exception(e);
34  success = false;
35  }
36  }
37  } else if (EV_WRITE & revents) {
39  if (m_response.done()) {
41 #if UWSGI_KEEPALIVE == 1
42  set_events(EV_READ);
44 #else
45  success = false;
46 #endif
47  }
48  }
49  } catch (tasks::tasks_exception& e) {
50  tdbg("uwsgi_task(" << this << "): exception: " << e.what() << std::endl);
51  set_exception(e);
52  success = false;
53  }
54  return success;
55 }
56 
57 } // net
58 } // tasks
void read_data(socket &sock)
Read request data from a socket.
void write_data(socket &sock)
Write a HTTP object to a socket.
Definition: http_base.cpp:19
#define tdbg(m)
Definition: logging.h:54
uwsgi_request m_request
Definition: uwsgi_task.h:75
Tasks execption class.
virtual void update_watcher(worker *worker)
Udate a watcher in the context of the given worker.
net::socket & socket()
Provide access to the underlying socket object.
Definition: net_io_task.h:35
void finish_request()
Called after a request has been responded.
Definition: uwsgi_task.h:79
uwsgi_packet_header & header()
Definition: uwsgi_request.h:83
const char * what() const noexcept
Return the error message.
void set_exception(tasks_exception &e)
Set an exception to report an error.
Definition: error_base.h:54
http_response m_response
Definition: uwsgi_task.h:76
bool handle_event(tasks::worker *worker, int revents)
Definition: uwsgi_task.cpp:16
void clear()
Reset an object.
Definition: uwsgi_request.h:86
void set_events(int events)
Update the events the object monitors.
virtual bool handle_request()=0
bool done() const
Definition: http_base.h:116