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

Unified Diff: net/server/http_server.h

Issue 497223003: Revert of Replace StreamListenSocket with StreamSocket in HttpServer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « net/server/http_connection_unittest.cc ('k') | net/server/http_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/server/http_server.h
diff --git a/net/server/http_server.h b/net/server/http_server.h
index 2ae698b98c5329424e31b2b2bfab616fad85c3ac..4309d122f1ead040eb28f2c2557a489b9fbff1b6 100644
--- a/net/server/http_server.h
+++ b/net/server/http_server.h
@@ -5,14 +5,13 @@
#ifndef NET_SERVER_HTTP_SERVER_H_
#define NET_SERVER_HTTP_SERVER_H_
+#include <list>
#include <map>
-#include <string>
#include "base/basictypes.h"
-#include "base/macros.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"
namespace net {
@@ -20,28 +19,30 @@
class HttpServerRequestInfo;
class HttpServerResponseInfo;
class IPEndPoint;
-class ServerSocket;
-class StreamSocket;
class WebSocket;
-class HttpServer {
+class HttpServer : public StreamListenSocket::Delegate,
+ public base::RefCountedThreadSafe<HttpServer> {
public:
- // Delegate to handle http/websocket events. Beware that it is not safe to
- // destroy the HttpServer in any of these callbacks.
class Delegate {
public:
virtual void OnHttpRequest(int connection_id,
const HttpServerRequestInfo& info) = 0;
+
virtual void OnWebSocketRequest(int connection_id,
const HttpServerRequestInfo& info) = 0;
+
virtual void OnWebSocketMessage(int connection_id,
const std::string& data) = 0;
+
virtual void OnClose(int connection_id) = 0;
+
+ protected:
+ virtual ~Delegate() {}
};
- HttpServer(scoped_ptr<ServerSocket> server_socket,
+ HttpServer(const StreamListenSocketFactory& socket_factory,
HttpServer::Delegate* delegate);
- ~HttpServer();
void AcceptWebSocket(int connection_id,
const HttpServerRequestInfo& request);
@@ -50,7 +51,6 @@
// performed that data constitutes a valid HTTP response. A valid HTTP
// response may be split across multiple calls to SendRaw.
void SendRaw(int connection_id, const std::string& data);
- // TODO(byungchul): Consider replacing function name with SendResponseInfo
void SendResponse(int connection_id, const HttpServerResponseInfo& response);
void Send(int connection_id,
HttpStatusCode status_code,
@@ -64,50 +64,40 @@
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();
+
private:
- friend class HttpServerTest;
-
- typedef std::map<int, HttpConnection*> IdToConnectionMap;
-
- void DoAcceptLoop();
- void OnAcceptCompleted(int rv);
- int HandleAcceptResult(int rv);
-
- void DoReadLoop(HttpConnection* connection);
- void OnReadCompleted(int connection_id, int rv);
- int HandleReadResult(HttpConnection* connection, int rv);
-
- void DoWriteLoop(HttpConnection* connection);
- void OnWriteCompleted(int connection_id, int rv);
- int HandleWriteResult(HttpConnection* connection, int rv);
+ friend class base::RefCountedThreadSafe<HttpServer>;
+ friend class HttpConnection;
// 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(const char* data,
- size_t data_len,
+ bool ParseHeaders(HttpConnection* connection,
HttpServerRequestInfo* info,
size_t* pos);
HttpConnection* FindConnection(int connection_id);
+ HttpConnection* FindConnection(StreamListenSocket* socket);
- // Whether or not Close() has been called during delegate callback processing.
- bool HasClosedConnection(HttpConnection* connection);
-
- const scoped_ptr<ServerSocket> server_socket_;
- scoped_ptr<StreamSocket> accepted_socket_;
- HttpServer::Delegate* const delegate_;
-
- int last_id_;
+ HttpServer::Delegate* delegate_;
+ scoped_ptr<StreamListenSocket> server_;
+ typedef std::map<int, HttpConnection*> IdToConnectionMap;
IdToConnectionMap id_to_connection_;
-
- base::WeakPtrFactory<HttpServer> weak_ptr_factory_;
+ typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap;
+ SocketToConnectionMap socket_to_connection_;
DISALLOW_COPY_AND_ASSIGN(HttpServer);
};
« no previous file with comments | « net/server/http_connection_unittest.cc ('k') | net/server/http_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698