Index: net/server/http_server.h |
diff --git a/net/server/http_server.h b/net/server/http_server.h |
index 4309d122f1ead040eb28f2c2557a489b9fbff1b6..d33dfd35c6da065b3e8e22b14118f9ee7b4d6e1a 100644 |
--- a/net/server/http_server.h |
+++ b/net/server/http_server.h |
@@ -5,24 +5,23 @@ |
#ifndef NET_SERVER_HTTP_SERVER_H_ |
#define NET_SERVER_HTTP_SERVER_H_ |
-#include <list> |
#include <map> |
-#include "base/basictypes.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
#include "net/http/http_status_code.h" |
-#include "net/socket/stream_listen_socket.h" |
+#include "net/server/http_connection.h" |
namespace net { |
-class HttpConnection; |
class HttpServerRequestInfo; |
class HttpServerResponseInfo; |
class IPEndPoint; |
+class ServerSocket; |
+class StreamSocket; |
class WebSocket; |
-class HttpServer : public StreamListenSocket::Delegate, |
- public base::RefCountedThreadSafe<HttpServer> { |
+class NET_EXPORT HttpServer { |
public: |
class Delegate { |
public: |
@@ -36,13 +35,11 @@ class HttpServer : public StreamListenSocket::Delegate, |
const std::string& data) = 0; |
virtual void OnClose(int connection_id) = 0; |
- |
- protected: |
- virtual ~Delegate() {} |
}; |
- HttpServer(const StreamListenSocketFactory& socket_factory, |
+ HttpServer(scoped_ptr<ServerSocket> server_socket, |
HttpServer::Delegate* delegate); |
+ ~HttpServer(); |
void AcceptWebSocket(int connection_id, |
const HttpServerRequestInfo& request); |
@@ -64,40 +61,49 @@ class HttpServer : public StreamListenSocket::Delegate, |
void Close(int connection_id); |
+ void SetReceiveBufferSize(int connection_id, int32 size); |
+ void SetSendBufferSize(int connection_id, int32 size); |
+ |
// Copies the local address to |address|. Returns a network error code. |
int GetLocalAddress(IPEndPoint* address); |
- // ListenSocketDelegate |
- virtual void DidAccept(StreamListenSocket* server, |
- scoped_ptr<StreamListenSocket> socket) OVERRIDE; |
- virtual void DidRead(StreamListenSocket* socket, |
- const char* data, |
- int len) OVERRIDE; |
- virtual void DidClose(StreamListenSocket* socket) OVERRIDE; |
- |
- protected: |
- virtual ~HttpServer(); |
+ base::WeakPtr<HttpServer> GetWeakPtr(); |
private: |
- friend class base::RefCountedThreadSafe<HttpServer>; |
- friend class HttpConnection; |
+ friend class HttpServerTest; |
+ |
+ typedef std::map<int, HttpConnection*> IdToConnectionMap; |
+ |
+ void DoAcceptLoop(); |
+ void OnAcceptCompleted(int rv); |
+ int DidAccept(int rv); |
+ |
+ void DoReadLoop(HttpConnection* connection); |
+ void OnReadCompleted(int connection_id, int rv); |
+ int DidRead(HttpConnection* conn, int rv); |
+ |
+ void DoWriteLoop(HttpConnection* connection); |
+ void OnWriteCompleted(int connection_id, int rv); |
+ int DidWrite(HttpConnection* conn, int rv); |
// Expects the raw data to be stored in recv_data_. If parsing is successful, |
// will remove the data parsed from recv_data_, leaving only the unused |
// recv data. |
- bool ParseHeaders(HttpConnection* connection, |
+ bool ParseHeaders(const char* data, |
+ size_t data_len, |
HttpServerRequestInfo* info, |
size_t* pos); |
HttpConnection* FindConnection(int connection_id); |
- HttpConnection* FindConnection(StreamListenSocket* socket); |
- HttpServer::Delegate* delegate_; |
- scoped_ptr<StreamListenSocket> server_; |
- typedef std::map<int, HttpConnection*> IdToConnectionMap; |
+ const scoped_ptr<ServerSocket> server_socket_; |
+ scoped_ptr<StreamSocket> accepted_socket_; |
+ HttpServer::Delegate* const delegate_; |
+ |
+ int last_id_; |
IdToConnectionMap id_to_connection_; |
- typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; |
- SocketToConnectionMap socket_to_connection_; |
+ |
+ base::WeakPtrFactory<HttpServer> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(HttpServer); |
}; |