X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnet%2Fserver%2Fhttp_connection.h;h=c7225e1a01d24d9088e5c10d92a92da5b89cd385;hb=3545e9f2671f595d2a2f3ee75ca0393b01e35ef6;hp=17faa46eb6b77304085635364f4a73b65c3c7821;hpb=7d210d4c7e9ba36e635eabc5b5780495f8a63292;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/net/server/http_connection.h b/src/net/server/http_connection.h index 17faa46..c7225e1 100644 --- a/src/net/server/http_connection.h +++ b/src/net/server/http_connection.h @@ -5,43 +5,130 @@ #ifndef NET_SERVER_HTTP_CONNECTION_H_ #define NET_SERVER_HTTP_CONNECTION_H_ +#include #include #include "base/basictypes.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "net/http/http_status_code.h" +#include "net/base/io_buffer.h" namespace net { -class HttpServer; -class HttpServerResponseInfo; -class StreamListenSocket; +class StreamSocket; class WebSocket; +// A container which has all information of an http connection. It includes +// id, underlying socket, and pending read/write data. class HttpConnection { public: - ~HttpConnection(); + // IOBuffer for data read. It's a wrapper around GrowableIOBuffer, with more + // functions for buffer management. It moves unconsumed data to the start of + // buffer. + class ReadIOBuffer : public IOBuffer { + public: + static const int kInitialBufSize = 1024; + static const int kMinimumBufSize = 128; + static const int kCapacityIncreaseFactor = 2; + static const int kDefaultMaxBufferSize = 1 * 1024 * 1024; // 1 Mbytes. + + ReadIOBuffer(); + + // Capacity. + int GetCapacity() const; + void SetCapacity(int capacity); + // Increases capacity and returns true if capacity is not beyond the limit. + bool IncreaseCapacity(); + + // Start of read data. + char* StartOfBuffer() const; + // Returns the bytes of read data. + int GetSize() const; + // More read data was appended. + void DidRead(int bytes); + // Capacity for which more read data can be appended. + int RemainingCapacity() const; + + // Removes consumed data and moves unconsumed data to the start of buffer. + void DidConsume(int bytes); + + // Limit of how much internal capacity can increase. + int max_buffer_size() const { return max_buffer_size_; } + void set_max_buffer_size(int max_buffer_size) { + max_buffer_size_ = max_buffer_size; + } + + private: + virtual ~ReadIOBuffer(); + + scoped_refptr base_; + int max_buffer_size_; + + DISALLOW_COPY_AND_ASSIGN(ReadIOBuffer); + }; + + // IOBuffer of pending data to write which has a queue of pending data. Each + // pending data is stored in std::string. data() is the data of first + // std::string stored. + class QueuedWriteIOBuffer : public IOBuffer { + public: + static const int kDefaultMaxBufferSize = 1 * 1024 * 1024; // 1 Mbytes. + + QueuedWriteIOBuffer(); + + // Whether or not pending data exists. + bool IsEmpty() const; - void Send(const std::string& data); - void Send(const char* bytes, int len); - void Send(const HttpServerResponseInfo& response); + // Appends new pending data and returns true if total size doesn't exceed + // the limit, |total_size_limit_|. It would change data() if new data is + // the first pending data. + bool Append(const std::string& data); - void Shift(int num_bytes); + // Consumes data and changes data() accordingly. It cannot be more than + // GetSizeToWrite(). + void DidConsume(int size); + + // Gets size of data to write this time. It is NOT total data size. + int GetSizeToWrite() const; + + // Total size of all pending data. + int total_size() const { return total_size_; } + + // Limit of how much data can be pending. + int max_buffer_size() const { return max_buffer_size_; } + void set_max_buffer_size(int max_buffer_size) { + max_buffer_size_ = max_buffer_size; + } + + private: + virtual ~QueuedWriteIOBuffer(); + + std::queue pending_data_; + int total_size_; + int max_buffer_size_; + + DISALLOW_COPY_AND_ASSIGN(QueuedWriteIOBuffer); + }; + + HttpConnection(int id, scoped_ptr socket); + ~HttpConnection(); - const std::string& recv_data() const { return recv_data_; } int id() const { return id_; } + StreamSocket* socket() const { return socket_.get(); } + ReadIOBuffer* read_buf() const { return read_buf_.get(); } + QueuedWriteIOBuffer* write_buf() const { return write_buf_.get(); } - private: - friend class HttpServer; - static int last_id_; + WebSocket* web_socket() const { return web_socket_.get(); } + void SetWebSocket(scoped_ptr web_socket); - HttpConnection(HttpServer* server, scoped_ptr sock); + private: + const int id_; + const scoped_ptr socket_; + const scoped_refptr read_buf_; + const scoped_refptr write_buf_; - HttpServer* server_; - scoped_ptr socket_; scoped_ptr web_socket_; - std::string recv_data_; - int id_; + DISALLOW_COPY_AND_ASSIGN(HttpConnection); };