opal-up 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,76 +20,80 @@
20
20
 
21
21
  /* This data belongs to the HttpResponse */
22
22
 
23
- #include "HttpParser.h"
24
23
  #include "AsyncSocketData.h"
24
+ #include "HttpParser.h"
25
25
  #include "ProxyParser.h"
26
26
 
27
27
  #include "MoveOnlyFunction.h"
28
28
 
29
29
  namespace uWS {
30
30
 
31
- template <bool SSL>
32
- struct HttpResponseData : AsyncSocketData<SSL>, HttpParser {
33
- template <bool> friend struct HttpResponse;
34
- template <bool> friend struct HttpContext;
35
-
36
- /* When we are done with a response we mark it like so */
37
- void markDone() {
38
- onAborted = nullptr;
39
- /* Also remove onWritable so that we do not emit when draining behind the scenes. */
40
- onWritable = nullptr;
41
-
42
- /* We are done with this request */
43
- state &= ~HttpResponseData<SSL>::HTTP_RESPONSE_PENDING;
31
+ template <bool SSL> struct HttpResponseData : AsyncSocketData<SSL>, HttpParser {
32
+ template <bool> friend struct HttpResponse;
33
+ template <bool> friend struct HttpContext;
34
+
35
+ /* When we are done with a response we mark it like so */
36
+ void markDone() {
37
+ onAborted = nullptr;
38
+ /* Also remove onWritable so that we do not emit when draining behind the
39
+ * scenes. */
40
+ onWritable = nullptr;
41
+
42
+ /* We are done with this request */
43
+ state &= ~HttpResponseData<SSL>::HTTP_RESPONSE_PENDING;
44
+ }
45
+
46
+ /* Caller of onWritable. It is possible onWritable calls markDone so we need
47
+ * to borrow it. */
48
+ bool callOnWritable(uintmax_t offset) {
49
+ /* Borrow real onWritable */
50
+ MoveOnlyFunction<bool(uintmax_t)> borrowedOnWritable =
51
+ std::move(onWritable);
52
+
53
+ /* Set onWritable to placeholder */
54
+ onWritable = [](uintmax_t) { return true; };
55
+
56
+ /* Run borrowed onWritable */
57
+ bool ret = borrowedOnWritable(offset);
58
+
59
+ /* If we still have onWritable (the placeholder) then move back the real one
60
+ */
61
+ if (onWritable) {
62
+ /* We haven't reset onWritable, so give it back */
63
+ onWritable = std::move(borrowedOnWritable);
44
64
  }
45
65
 
46
- /* Caller of onWritable. It is possible onWritable calls markDone so we need to borrow it. */
47
- bool callOnWritable(uintmax_t offset) {
48
- /* Borrow real onWritable */
49
- MoveOnlyFunction<bool(uintmax_t)> borrowedOnWritable = std::move(onWritable);
66
+ return ret;
67
+ }
50
68
 
51
- /* Set onWritable to placeholder */
52
- onWritable = [](uintmax_t) {return true;};
53
-
54
- /* Run borrowed onWritable */
55
- bool ret = borrowedOnWritable(offset);
56
-
57
- /* If we still have onWritable (the placeholder) then move back the real one */
58
- if (onWritable) {
59
- /* We haven't reset onWritable, so give it back */
60
- onWritable = std::move(borrowedOnWritable);
61
- }
62
-
63
- return ret;
64
- }
65
69
  private:
66
- /* Bits of status */
67
- enum {
68
- HTTP_STATUS_CALLED = 1, // used
69
- HTTP_WRITE_CALLED = 2, // used
70
- HTTP_END_CALLED = 4, // used
71
- HTTP_RESPONSE_PENDING = 8, // used
72
- HTTP_CONNECTION_CLOSE = 16 // used
73
- };
74
-
75
- /* Per socket event handlers */
76
- MoveOnlyFunction<bool(uintmax_t)> onWritable;
77
- MoveOnlyFunction<void()> onAborted;
78
- MoveOnlyFunction<void(std::string_view, bool)> inStream; // onData
79
- /* Outgoing offset */
80
- uintmax_t offset = 0;
81
-
82
- /* Let's track number of bytes since last timeout reset in data handler */
83
- unsigned int received_bytes_per_timeout = 0;
84
-
85
- /* Current state (content-length sent, status sent, write called, etc */
86
- int state = 0;
70
+ /* Bits of status */
71
+ enum {
72
+ HTTP_STATUS_CALLED = 1, // used
73
+ HTTP_WRITE_CALLED = 2, // used
74
+ HTTP_END_CALLED = 4, // used
75
+ HTTP_RESPONSE_PENDING = 8, // used
76
+ HTTP_CONNECTION_CLOSE = 16 // used
77
+ };
78
+
79
+ /* Per socket event handlers */
80
+ MoveOnlyFunction<bool(uintmax_t)> onWritable;
81
+ MoveOnlyFunction<void()> onAborted;
82
+ MoveOnlyFunction<void(std::string_view, bool)> inStream; // onData
83
+ /* Outgoing offset */
84
+ uintmax_t offset = 0;
85
+
86
+ /* Let's track number of bytes since last timeout reset in data handler */
87
+ unsigned int received_bytes_per_timeout = 0;
88
+
89
+ /* Current state (content-length sent, status sent, write called, etc */
90
+ int state = 0;
87
91
 
88
92
  #ifdef UWS_WITH_PROXY
89
- ProxyParser proxyParser;
93
+ ProxyParser proxyParser;
90
94
  #endif
91
95
  };
92
96
 
93
- }
97
+ } // namespace uWS
94
98
 
95
99
  #endif // UWS_HTTPRESPONSEDATA_H