Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: net/server/http_connection.h

Issue 296053012: Replace StreamListenSocket with StreamSocket in HttpServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Redo changes reverted with unknown reason. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/server/http_connection.h
diff --git a/net/server/http_connection.h b/net/server/http_connection.h
index 17faa46eb6b77304085635364f4a73b65c3c7821..4b27e8bc4b5d2510b12f67a2d1c453a498472964 100644
--- a/net/server/http_connection.h
+++ b/net/server/http_connection.h
@@ -5,43 +5,126 @@
#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. It is similar to GrowableIOBuffer, and has more
+ // functions for buffer management. It moves unconsumed data to the start of
mmenke 2014/08/08 18:35:43 Maybe replace second sentence with "It's a wrapper
byungchul 2014/08/12 21:36:54 Done.
+ // buffer.
+ class ReadIOBuffer : public IOBuffer {
+ public:
+ 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 is appended.
mmenke 2014/08/08 18:35:43 This doesn't actually append more data. Maybe "wa
byungchul 2014/08/12 21:36:53 Done.
+ 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 capacity_limit() const { return capacity_limit_; }
mmenke 2014/08/08 18:35:43 Really should use consistent terminology here and
byungchul 2014/08/12 21:36:54 Changed to max_buffer_size.
+ void set_capacity_limit(int limit) { capacity_limit_ = limit; }
mmenke 2014/08/08 18:35:43 nit: limit->capacity_limit
byungchul 2014/08/12 21:36:54 Done.
+
+ 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 {
mmenke 2014/08/08 18:35:43 I wonder if this really should be an IOBuffer - th
byungchul 2014/08/12 21:36:53 IOBuffer has only data() and doesn't imply anythin
+ public:
+ PendingWriteIOBuffer();
+
+ // 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.
mmenke 2014/08/08 18:35:43 Worth mentioning it can't be mroe than GetSizeToWr
byungchul 2014/08/12 21:36:54 Done.
+ 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_; }
mmenke 2014/08/08 18:35:43 I don't think this is used.
byungchul 2014/08/12 21:36:54 Used in unittests.
+ // Limit of how much total_size can increase.
+ int total_size_limit() const { return total_size_limit_; }
mmenke 2014/08/08 18:35:43 Is this used anywhere?
byungchul 2014/08/12 21:36:53 in unittests.
+ void set_total_size_limit(int limit) { total_size_limit_ = limit; }
mmenke 2014/08/08 18:35:43 Suggest renaming total_size_limit_ to max_buffer_s
byungchul 2014/08/12 21:36:53 Done.
+
+ private:
+ friend class HttpConnectionTest;
+
+ static const int kDefaultTotalSizeLimit = 1 * 1024 * 1024; // 1 Mbytes.
+
+ virtual ~PendingWriteIOBuffer();
+
+ std::queue<std::string> pending_data_;
+ int total_size_;
mmenke 2014/08/08 18:35:43 Is this used for anything other than sanity checks
byungchul 2014/08/12 21:36:53 Used in Append() not to queue more than capacity.
+ 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);
};
« no previous file with comments | « net/net.gypi ('k') | net/server/http_connection.cc » ('j') | net/server/http_connection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698