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

Side by Side Diff: net/server/http_server.h

Issue 10161005: Add DefaultListenSocket. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build on Windows Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/server/http_connection.cc ('k') | net/server/http_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SERVER_HTTP_SERVER_H_ 5 #ifndef NET_SERVER_HTTP_SERVER_H_
6 #define NET_SERVER_HTTP_SERVER_H_ 6 #define NET_SERVER_HTTP_SERVER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <map> 10 #include <map>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "net/base/listen_socket.h" 14 #include "net/base/stream_listen_socket.h"
15 15
16 namespace net { 16 namespace net {
17 17
18 class HttpConnection; 18 class HttpConnection;
19 class HttpServerRequestInfo; 19 class HttpServerRequestInfo;
20 class WebSocket; 20 class WebSocket;
21 21
22 class HttpServer : public ListenSocket::ListenSocketDelegate, 22 class HttpServer : public StreamListenSocket::Delegate,
23 public base::RefCountedThreadSafe<HttpServer> { 23 public base::RefCountedThreadSafe<HttpServer> {
24 public: 24 public:
25 class Delegate { 25 class Delegate {
26 public: 26 public:
27 virtual void OnHttpRequest(int connection_id, 27 virtual void OnHttpRequest(int connection_id,
28 const HttpServerRequestInfo& info) = 0; 28 const HttpServerRequestInfo& info) = 0;
29 29
30 virtual void OnWebSocketRequest(int connection_id, 30 virtual void OnWebSocketRequest(int connection_id,
31 const HttpServerRequestInfo& info) = 0; 31 const HttpServerRequestInfo& info) = 0;
32 32
(...skipping 14 matching lines...) Expand all
47 void Send(int connection_id, const std::string& data); 47 void Send(int connection_id, const std::string& data);
48 void Send(int connection_id, const char* bytes, int len); 48 void Send(int connection_id, const char* bytes, int len);
49 void Send200(int connection_id, 49 void Send200(int connection_id,
50 const std::string& data, 50 const std::string& data,
51 const std::string& mime_type); 51 const std::string& mime_type);
52 void Send404(int connection_id); 52 void Send404(int connection_id);
53 void Send500(int connection_id, const std::string& message); 53 void Send500(int connection_id, const std::string& message);
54 void Close(int connection_id); 54 void Close(int connection_id);
55 55
56 // ListenSocketDelegate 56 // ListenSocketDelegate
57 virtual void DidAccept(ListenSocket* server, ListenSocket* socket) OVERRIDE; 57 virtual void DidAccept(StreamListenSocket* server,
58 virtual void DidRead(ListenSocket* socket, 58 StreamListenSocket* socket) OVERRIDE;
59 virtual void DidRead(StreamListenSocket* socket,
59 const char* data, 60 const char* data,
60 int len) OVERRIDE; 61 int len) OVERRIDE;
61 virtual void DidClose(ListenSocket* socket) OVERRIDE; 62 virtual void DidClose(StreamListenSocket* socket) OVERRIDE;
62 63
63 protected: 64 protected:
64 virtual ~HttpServer(); 65 virtual ~HttpServer();
65 66
66 private: 67 private:
67 friend class base::RefCountedThreadSafe<HttpServer>; 68 friend class base::RefCountedThreadSafe<HttpServer>;
68 friend class HttpConnection; 69 friend class HttpConnection;
69 70
70 // Expects the raw data to be stored in recv_data_. If parsing is successful, 71 // Expects the raw data to be stored in recv_data_. If parsing is successful,
71 // will remove the data parsed from recv_data_, leaving only the unused 72 // will remove the data parsed from recv_data_, leaving only the unused
72 // recv data. 73 // recv data.
73 bool ParseHeaders(HttpConnection* connection, 74 bool ParseHeaders(HttpConnection* connection,
74 HttpServerRequestInfo* info, 75 HttpServerRequestInfo* info,
75 size_t* pos); 76 size_t* pos);
76 77
77 HttpConnection* FindConnection(int connection_id); 78 HttpConnection* FindConnection(int connection_id);
78 HttpConnection* FindConnection(ListenSocket* socket); 79 HttpConnection* FindConnection(StreamListenSocket* socket);
79 80
80 HttpServer::Delegate* delegate_; 81 HttpServer::Delegate* delegate_;
81 scoped_refptr<ListenSocket> server_; 82 scoped_refptr<StreamListenSocket> server_;
82 typedef std::map<int, HttpConnection*> IdToConnectionMap; 83 typedef std::map<int, HttpConnection*> IdToConnectionMap;
83 IdToConnectionMap id_to_connection_; 84 IdToConnectionMap id_to_connection_;
84 typedef std::map<ListenSocket*, HttpConnection*> SocketToConnectionMap; 85 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap;
85 SocketToConnectionMap socket_to_connection_; 86 SocketToConnectionMap socket_to_connection_;
86 87
87 DISALLOW_COPY_AND_ASSIGN(HttpServer); 88 DISALLOW_COPY_AND_ASSIGN(HttpServer);
88 }; 89 };
89 90
90 } // namespace net 91 } // namespace net
91 92
92 #endif // NET_SERVER_HTTP_SERVER_H_ 93 #endif // NET_SERVER_HTTP_SERVER_H_
OLDNEW
« no previous file with comments | « net/server/http_connection.cc ('k') | net/server/http_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698