Chromium Code Reviews| Index: net/server/http_connection.h |
| diff --git a/net/server/http_connection.h b/net/server/http_connection.h |
| index 17faa46eb6b77304085635364f4a73b65c3c7821..452cc9d7befb78bfb05382a1a385e52175428fe9 100644 |
| --- a/net/server/http_connection.h |
| +++ b/net/server/http_connection.h |
| @@ -9,39 +9,107 @@ |
| #include "base/basictypes.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "net/base/io_buffer.h" |
| #include "net/http/http_status_code.h" |
| namespace net { |
| class HttpServer; |
| +class HttpServerRequestInfo; |
| class HttpServerResponseInfo; |
| -class StreamListenSocket; |
| +class StreamSocket; |
| class WebSocket; |
|
mmenke
2014/05/23 19:20:58
Could you please document these classes?
byungchul
2014/05/30 00:19:02
Done.
|
| -class HttpConnection { |
| +class HttpConnection : public base::SupportsWeakPtr<HttpConnection> { |
|
mmenke
2014/05/23 19:20:58
WeakPtrs should generally not be exposed to extern
Ryan Sleevi
2014/05/28 01:36:26
+1
Note that WeakPtrFactory should be the *last*
byungchul
2014/05/30 00:19:02
Removed here, and changed in HttpServer.
|
| public: |
| + class Delegate { |
| + public: |
| + // Called when new data is available. Data read can be retrieved by |
| + // conn->read_buf(). Whenever delegate consumes data, it must call |
| + // conn->read_buf()->DidConsume(). |
| + virtual void DidRead(HttpConnection* conn) = 0; |
| + |
| + // Called when underlying socket has been closed. |
| + virtual void DidClose(HttpConnection* conn) = 0; |
|
mmenke
2014/05/23 19:20:58
DISALLOW_COPY_AND_ASSIGN
mmenke
2014/05/23 19:20:58
Write out connection (Google style guide discourag
byungchul
2014/05/30 00:19:02
Removed.
|
| + }; |
| + |
| + // IOBuffer for data read. It has 3 parts: |
| + // 1) consumed data: [base_->StartOfBuffer(), data()] |
| + // 2) unconsumed data: [data(), base_->data()] |
| + // 3) not used buffer: [base_->data(), |
| + // base_->data() + base_->RemainingCapacity()] |
| + class ReadIOBuffer : public IOBuffer { |
| + public: |
| + // Returns the bytes of unconsumed data. |
| + size_t GetUnconsumedSize() const; |
|
mmenke
2014/05/23 19:20:58
IOBuffers use ints everything. I think mixing siz
byungchul
2014/05/30 00:19:02
Done.
|
| + |
| + // Changes |data_| so that |data_| always points to the first unconsumed |
| + // byte. |
| + void DidConsume(size_t bytes); |
| + |
| + private: |
| + friend class HttpConnection; |
| + |
| + ReadIOBuffer(); |
| + virtual ~ReadIOBuffer(); |
| + |
| + // Returns IOBuffer to append more data read. |
| + IOBuffer* GetUnusedIOBuffer() const; |
| + // Returns capacity not used yet. |
| + size_t GetUnusedCapacity() const; |
| + |
| + // Capacity of |base_|. |
| + size_t GetCapacity() const; |
| + void SetCapacity(size_t capacity); |
| + |
| + // More data is appended. Refresh |data_| if base_->data() has changed. |
| + void DidRead(size_t bytes); |
| + |
| + scoped_refptr<GrowableIOBuffer> base_; |
| + // Offset of data_ from base_->data(). |
| + size_t consumed_offset_; |
|
mmenke
2014/05/23 19:20:58
DISALLOW_COPY_AND_ASSIGN
byungchul
2014/05/30 00:19:02
Done.
|
| + }; |
| + |
| + HttpConnection(int id, scoped_ptr<StreamSocket> socket, Delegate* delegate); |
| ~HttpConnection(); |
| void Send(const std::string& data); |
| void Send(const char* bytes, int len); |
| void Send(const HttpServerResponseInfo& response); |
| - void Shift(int num_bytes); |
| + void Close(); |
| + |
| + // Upgrades this http connection to web socket connection. |
| + void UpgradeToWebSocket(const HttpServerRequestInfo& request, size_t* pos); |
| - const std::string& recv_data() const { return recv_data_; } |
| int id() const { return id_; } |
| + StreamSocket* socket() const { return socket_.get(); } |
| + WebSocket* web_socket() const { return web_socket_.get(); } |
| + scoped_refptr<ReadIOBuffer> read_buf() const { return read_buf_; } |
| private: |
| - friend class HttpServer; |
| - static int last_id_; |
| + class PendingWriteIOBuffer; |
| + |
| + void DoReadLoop(int rv); |
| + void OnReadCompleted(int rv); |
| + int DidRead(int rv); |
| - HttpConnection(HttpServer* server, scoped_ptr<StreamListenSocket> sock); |
| + void DoWriteLoop(int rv); |
| + void OnWriteCompleted(int rv); |
| + int DidWrite(int rv); |
| + |
| + void CloseInNextRunLoop(); |
| + |
| + const int id_; |
| + const scoped_ptr<StreamSocket> socket_; |
| + Delegate* const delegate_; |
| + |
| + const scoped_refptr<ReadIOBuffer> read_buf_; |
| + const scoped_refptr<PendingWriteIOBuffer> pending_write_buf_; |
| - HttpServer* server_; |
| - scoped_ptr<StreamListenSocket> socket_; |
| scoped_ptr<WebSocket> web_socket_; |
| - std::string recv_data_; |
| - int id_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(HttpConnection); |
| }; |