Imported Upstream version 1.0.0
[platform/upstream/nghttp2.git] / src / shrpx_spdy_upstream.h
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2012 Tatsuhiro Tsujikawa
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef SHRPX_SPDY_UPSTREAM_H
26 #define SHRPX_SPDY_UPSTREAM_H
27
28 #include "shrpx.h"
29
30 #include <memory>
31
32 #include <ev.h>
33
34 #include <spdylay/spdylay.h>
35
36 #include "shrpx_upstream.h"
37 #include "shrpx_downstream_queue.h"
38 #include "memchunk.h"
39 #include "util.h"
40
41 namespace shrpx {
42
43 class ClientHandler;
44
45 class SpdyUpstream : public Upstream {
46 public:
47   SpdyUpstream(uint16_t version, ClientHandler *handler);
48   virtual ~SpdyUpstream();
49   virtual int on_read();
50   virtual int on_write();
51   virtual int on_timeout(Downstream *downstream);
52   virtual int on_downstream_abort_request(Downstream *downstream,
53                                           unsigned int status_code);
54   virtual ClientHandler *get_client_handler() const;
55   virtual int downstream_read(DownstreamConnection *dconn);
56   virtual int downstream_write(DownstreamConnection *dconn);
57   virtual int downstream_eof(DownstreamConnection *dconn);
58   virtual int downstream_error(DownstreamConnection *dconn, int events);
59   Downstream *add_pending_downstream(int32_t stream_id, int32_t priority);
60   void remove_downstream(Downstream *downstream);
61
62   int rst_stream(Downstream *downstream, int status_code);
63   int error_reply(Downstream *downstream, unsigned int status_code);
64
65   virtual void pause_read(IOCtrlReason reason);
66   virtual int resume_read(IOCtrlReason reason, Downstream *downstream,
67                           size_t consumed);
68
69   virtual int on_downstream_header_complete(Downstream *downstream);
70   virtual int on_downstream_body(Downstream *downstream, const uint8_t *data,
71                                  size_t len, bool flush);
72   virtual int on_downstream_body_complete(Downstream *downstream);
73
74   virtual void on_handler_delete();
75   virtual int on_downstream_reset(bool no_retry);
76
77   bool get_flow_control() const;
78
79   int consume(int32_t stream_id, size_t len);
80
81   void start_downstream(Downstream *downstream);
82   void initiate_downstream(Downstream *downstream);
83
84 private:
85   DownstreamQueue downstream_queue_;
86   ClientHandler *handler_;
87   spdylay_session *session_;
88   int32_t initial_window_size_;
89   bool flow_control_;
90 };
91
92 } // namespace shrpx
93
94 #endif // SHRPX_SPDY_UPSTREAM_H