| Index: net/server/http_connection.h
|
| diff --git a/net/server/http_connection.h b/net/server/http_connection.h
|
| index 17faa46eb6b77304085635364f4a73b65c3c7821..c5b6c979554bac11265d7391c33863552b3afdbb 100644
|
| --- a/net/server/http_connection.h
|
| +++ b/net/server/http_connection.h
|
| @@ -5,43 +5,140 @@
|
| #ifndef NET_SERVER_HTTP_CONNECTION_H_
|
| #define NET_SERVER_HTTP_CONNECTION_H_
|
|
|
| +#include <queue>
|
| #include <string>
|
|
|
| #include "base/basictypes.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. Not to move data when part of data has been
|
| + // consumed, It has 3 parts:
|
| + //
|
| + // 1) consumed data: [base_->StartOfBuffer(), data()]
|
| + // It is part cosumed by caller. If caller doesn't consume all data read,
|
| + // i.e. length of unconsumed data is greater than zero, ReadIOBuffer
|
| + // moves only data pointer, but not move data itself.
|
| + //
|
| + // 2) unconsumed data: [data(), base_->data()]
|
| + // It is part read from underlying socket but not consumed by caller yet.
|
| + //
|
| + // 3) not used buffer: [base_->data(),
|
| + // base_->data() + base_->RemainingCapacity()]
|
| + // It is part available for next reading operation of underlying socket.
|
| + class ReadIOBuffer : public IOBuffer {
|
| + public:
|
| + ReadIOBuffer();
|
| +
|
| + // Returns IOBuffer to append more data read.
|
| + IOBuffer* GetUnusedIOBuffer() const;
|
| + // Returns capacity not used yet.
|
| + int GetUnusedCapacity() const;
|
| +
|
| + // Capacity of |base_|.
|
| + int GetCapacity() const;
|
| + void SetCapacity(int capacity);
|
| + // Increases capacity and returns true if capacity is not beyond the limit.
|
| + bool IncreaseCapacity();
|
| +
|
| + // More data is appended. Refresh |data_| if base_->data() has changed.
|
| + void DidRead(int bytes);
|
| +
|
| + // Returns the bytes of unconsumed data.
|
| + int GetUnconsumedSize() const;
|
| +
|
| + // Changes |data_| so that |data_| always points to the first unconsumed
|
| + // byte.
|
| + void DidConsume(int bytes);
|
| +
|
| + // Limit of how much internal capacity can increase.
|
| + int capacity_limit() const { return capacity_limit_; }
|
| + void set_capacity_limit(int limit) { capacity_limit_ = limit; }
|
| +
|
| + private:
|
| + friend class HttpConnectionTest;
|
| +
|
| + static const int kInitialBufSize = 1024;
|
| + static const int kMinimumBufSize = 128;
|
| + static const int kCapacityIncreaseFactor = 2;
|
| + static const int kDefaultCapacityLimit = 1 * 1024 * 1024; // 1 Mbytes.
|
| +
|
| + virtual ~ReadIOBuffer();
|
| +
|
| + scoped_refptr<GrowableIOBuffer> base_;
|
| + int capacity_limit_;
|
| +
|
| + 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 PendingWriteIOBuffer : public IOBuffer {
|
| + public:
|
| + PendingWriteIOBuffer();
|
|
|
| - void Send(const std::string& data);
|
| - void Send(const char* bytes, int len);
|
| - void Send(const HttpServerResponseInfo& response);
|
| + // Whether or not pending data exists.
|
| + bool IsEmpty() const;
|
|
|
| - void Shift(int num_bytes);
|
| + // 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);
|
| +
|
| + // Consumes data and changes data() accordingly.
|
| + void DidConsume(int size);
|
| +
|
| + // Gets size of data to write this time. It is NOT total data size.
|
| + int GetSizeToWrite() const;
|
| +
|
| + int total_size() const { return total_size_; }
|
| + // Limit of how much total_size can increase.
|
| + int total_size_limit() const { return total_size_limit_; }
|
| + void set_total_size_limit(int limit) { total_size_limit_ = limit; }
|
| +
|
| + private:
|
| + friend class HttpConnectionTest;
|
| +
|
| + static const int kDefaultTotalSizeLimit = 1 * 1024 * 1024; // 1 Mbytes.
|
| +
|
| + virtual ~PendingWriteIOBuffer();
|
| +
|
| + std::queue<std::string> pending_data_;
|
| + int total_size_;
|
| + int total_size_limit_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(PendingWriteIOBuffer);
|
| + };
|
| +
|
| + HttpConnection(int id, scoped_ptr<StreamSocket> 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(); }
|
| + PendingWriteIOBuffer* 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<WebSocket> web_socket);
|
|
|
| - HttpConnection(HttpServer* server, scoped_ptr<StreamListenSocket> sock);
|
| + private:
|
| + const int id_;
|
| + const scoped_ptr<StreamSocket> socket_;
|
| + const scoped_refptr<ReadIOBuffer> read_buf_;
|
| + const scoped_refptr<PendingWriteIOBuffer> write_buf_;
|
|
|
| - HttpServer* server_;
|
| - scoped_ptr<StreamListenSocket> socket_;
|
| scoped_ptr<WebSocket> web_socket_;
|
| - std::string recv_data_;
|
| - int id_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(HttpConnection);
|
| };
|
|
|
|
|