2013-07-26 13:12:55 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2013-07-26 13:12:55 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef SHRPX_SPDY_UPSTREAM_H
|
|
|
|
#define SHRPX_SPDY_UPSTREAM_H
|
|
|
|
|
|
|
|
#include "shrpx.h"
|
|
|
|
|
2014-08-18 15:59:31 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <ev.h>
|
|
|
|
|
2013-07-26 13:12:55 +02:00
|
|
|
#include <spdylay/spdylay.h>
|
|
|
|
|
|
|
|
#include "shrpx_upstream.h"
|
|
|
|
#include "shrpx_downstream_queue.h"
|
2014-12-27 18:59:06 +01:00
|
|
|
#include "memchunk.h"
|
2014-03-04 16:23:33 +01:00
|
|
|
#include "util.h"
|
2013-07-26 13:12:55 +02:00
|
|
|
|
|
|
|
namespace shrpx {
|
|
|
|
|
|
|
|
class ClientHandler;
|
|
|
|
|
|
|
|
class SpdyUpstream : public Upstream {
|
|
|
|
public:
|
|
|
|
SpdyUpstream(uint16_t version, ClientHandler *handler);
|
|
|
|
virtual ~SpdyUpstream();
|
|
|
|
virtual int on_read();
|
|
|
|
virtual int on_write();
|
2014-08-09 11:47:45 +02:00
|
|
|
virtual int on_timeout(Downstream *downstream);
|
2014-06-27 15:34:54 +02:00
|
|
|
virtual int on_downstream_abort_request(Downstream *downstream,
|
|
|
|
unsigned int status_code);
|
2014-11-27 15:39:04 +01:00
|
|
|
virtual ClientHandler *get_client_handler() const;
|
2014-12-27 18:59:06 +01:00
|
|
|
virtual int downstream_read(DownstreamConnection *dconn);
|
|
|
|
virtual int downstream_write(DownstreamConnection *dconn);
|
|
|
|
virtual int downstream_eof(DownstreamConnection *dconn);
|
|
|
|
virtual int downstream_error(DownstreamConnection *dconn, int events);
|
2014-11-27 15:39:04 +01:00
|
|
|
Downstream *add_pending_downstream(int32_t stream_id, int32_t priority);
|
2013-07-26 13:12:55 +02:00
|
|
|
void remove_downstream(Downstream *downstream);
|
2014-11-27 15:39:04 +01:00
|
|
|
Downstream *find_downstream(int32_t stream_id);
|
2013-07-26 13:12:55 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
spdylay_session *get_http2_session();
|
2013-07-26 13:12:55 +02:00
|
|
|
|
|
|
|
int rst_stream(Downstream *downstream, int status_code);
|
2013-10-02 16:29:44 +02:00
|
|
|
int error_reply(Downstream *downstream, unsigned int status_code);
|
2013-07-26 13:12:55 +02:00
|
|
|
|
|
|
|
virtual void pause_read(IOCtrlReason reason);
|
2014-08-21 14:22:16 +02:00
|
|
|
virtual int resume_read(IOCtrlReason reason, Downstream *downstream,
|
|
|
|
size_t consumed);
|
2013-07-26 13:12:55 +02:00
|
|
|
|
|
|
|
virtual int on_downstream_header_complete(Downstream *downstream);
|
2014-11-27 15:39:04 +01:00
|
|
|
virtual int on_downstream_body(Downstream *downstream, const uint8_t *data,
|
|
|
|
size_t len, bool flush);
|
2013-07-26 13:12:55 +02:00
|
|
|
virtual int on_downstream_body_complete(Downstream *downstream);
|
|
|
|
|
2014-11-18 17:59:09 +01:00
|
|
|
virtual void on_handler_delete();
|
nghttpx: Check HTTP/2 downstream connection after certain idle time
Previously when requests are issued to HTTP/2 downstream connection,
but it turns out that connection is down, handlers of those requests
are deleted. In some situations, we only know connection is down when
we write something to network, so we'd like to handle this kind of
situation in more robust manner. In this change, certain seconds
passed after last network activity, we first issue PING frame to
downstream connection before issuing new HTTP request. If writing
PING frame is failed, it means connection was lost. In this case,
instead of deleting handler, pending requests are migrated to new
HTTP2/ downstream connection, so that it can continue without
affecting upstream connection.
2014-12-08 17:30:15 +01:00
|
|
|
virtual int on_downstream_reset();
|
2014-11-18 17:59:09 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
virtual MemchunkPool4K *get_mcpool();
|
2014-09-18 16:03:36 +02:00
|
|
|
|
2013-07-26 13:12:55 +02:00
|
|
|
bool get_flow_control() const;
|
2014-03-03 13:18:24 +01:00
|
|
|
|
2014-08-21 14:22:16 +02:00
|
|
|
int consume(int32_t stream_id, size_t len);
|
2014-07-02 16:07:46 +02:00
|
|
|
|
2014-12-04 17:07:00 +01:00
|
|
|
void start_downstream(Downstream *downstream);
|
2014-08-18 15:59:31 +02:00
|
|
|
void initiate_downstream(std::unique_ptr<Downstream> downstream);
|
2014-08-16 14:29:20 +02:00
|
|
|
|
2013-07-26 13:12:55 +02:00
|
|
|
private:
|
2014-12-27 18:59:06 +01:00
|
|
|
// must be put before downstream_queue_
|
|
|
|
MemchunkPool4K mcpool_;
|
2013-12-06 15:17:38 +01:00
|
|
|
DownstreamQueue downstream_queue_;
|
2013-07-26 13:12:55 +02:00
|
|
|
ClientHandler *handler_;
|
|
|
|
spdylay_session *session_;
|
|
|
|
int32_t initial_window_size_;
|
2013-12-06 15:17:38 +01:00
|
|
|
bool flow_control_;
|
2013-07-26 13:12:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace shrpx
|
|
|
|
|
|
|
|
#endif // SHRPX_SPDY_UPSTREAM_H
|