libtasks Documentation  1.6
uwsgi_task.h
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 #ifndef _UWSGI_TASK_H_
9 #define _UWSGI_TASK_H_
10 
11 #include <vector>
12 #include <unordered_map>
13 #include <string>
14 #include <cassert>
15 
16 #include <tasks/worker.h>
17 #include <tasks/net_io_task.h>
20 
21 // The nginx uwsgi module does not support keepalive connections. If
22 // this gets implemented one day or we find a different webserver that
23 // supports this, we can enable the following flag.
24 #define UWSGI_KEEPALIVE 0
25 
26 namespace tasks {
27 namespace net {
28 
31  public:
32  uwsgi_task(net::socket& sock) : tasks::net_io_task(sock, EV_READ) {}
33  virtual ~uwsgi_task() {}
34 
36  bool handle_event(tasks::worker* worker, int revents);
37 
40  virtual bool handle_request() = 0;
41 
43  inline uwsgi_request& request() { return m_request; }
44 
46  inline const uwsgi_request& request() const { return m_request; }
47 
49  inline uwsgi_request* request_p() { return &m_request; }
50 
52  inline const uwsgi_request* request_p() const { return &m_request; }
53 
55  inline http_response& response() { return m_response; }
56 
58  inline const http_response& response() const { return m_response; }
59 
61  inline http_response* response_p() { return &m_response; }
62 
64  inline const http_response* response_p() const { return &m_response; }
65 
67  inline void send_response() {
68  worker* w = worker::get();
69  assert(nullptr != w);
70  set_events(EV_WRITE);
71  update_watcher(w);
72  }
73 
74  protected:
77 
79  inline void finish_request() { m_response.clear(); }
80 };
81 
82 } // net
83 } // tasks
84 
85 #endif // _UWSGI_TASK_H_
The HTTP response implementation.
Definition: http_response.h:19
http_response & response()
Definition: uwsgi_task.h:55
uwsgi_request * request_p()
Definition: uwsgi_task.h:49
The net_io_task implements the base for socket based network tasks.
Definition: net_io_task.h:21
uwsgi_task(net::socket &sock)
Definition: uwsgi_task.h:32
static worker * get()
Provide access to the executing worker thread object in the current thread context.
Definition: worker.h:64
The socket class.
Definition: socket.h:35
uwsgi_request m_request
Definition: uwsgi_task.h:75
const http_response * response_p() const
Definition: uwsgi_task.h:64
void clear()
Reset the http object.
Definition: http_response.h:41
void send_response()
Send the resonse back.
Definition: uwsgi_task.h:67
virtual void update_watcher(worker *worker)
Udate a watcher in the context of the given worker.
The base class for the uwsgi protocol implementation.
Definition: uwsgi_task.h:30
The uwsgi protocol implementation for a request. The response is a HTTP/1.1 response.
Definition: uwsgi_request.h:27
void finish_request()
Called after a request has been responded.
Definition: uwsgi_task.h:79
const http_response & response() const
Definition: uwsgi_task.h:58
http_response * response_p()
Definition: uwsgi_task.h:61
http_response m_response
Definition: uwsgi_task.h:76
uwsgi_request & request()
Definition: uwsgi_task.h:43
bool handle_event(tasks::worker *worker, int revents)
Definition: uwsgi_task.cpp:16
void set_events(int events)
Update the events the object monitors.
virtual bool handle_request()=0
const uwsgi_request & request() const
Definition: uwsgi_task.h:46
const uwsgi_request * request_p() const
Definition: uwsgi_task.h:52