OLD | NEW |
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 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "net/http/http_status_code.h" | 13 #include "net/http/http_status_code.h" |
14 #include "net/socket/stream_listen_socket.h" | 14 #include "net/socket/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 HttpServerResponseInfo; | 20 class HttpServerResponseInfo; |
21 class IPEndPoint; | 21 class IPEndPoint; |
22 class WebSocket; | 22 class WebSocket; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 void Send404(int connection_id); | 58 void Send404(int connection_id); |
59 void Send500(int connection_id, const std::string& message); | 59 void Send500(int connection_id, const std::string& message); |
60 | 60 |
61 void Close(int connection_id); | 61 void Close(int connection_id); |
62 | 62 |
63 // Copies the local address to |address|. Returns a network error code. | 63 // Copies the local address to |address|. Returns a network error code. |
64 int GetLocalAddress(IPEndPoint* address); | 64 int GetLocalAddress(IPEndPoint* address); |
65 | 65 |
66 // ListenSocketDelegate | 66 // ListenSocketDelegate |
67 virtual void DidAccept(StreamListenSocket* server, | 67 virtual void DidAccept(StreamListenSocket* server, |
68 StreamListenSocket* socket) OVERRIDE; | 68 scoped_ptr<StreamListenSocket> socket) OVERRIDE; |
69 virtual void DidRead(StreamListenSocket* socket, | 69 virtual void DidRead(StreamListenSocket* socket, |
70 const char* data, | 70 const char* data, |
71 int len) OVERRIDE; | 71 int len) OVERRIDE; |
72 virtual void DidClose(StreamListenSocket* socket) OVERRIDE; | 72 virtual void DidClose(StreamListenSocket* socket) OVERRIDE; |
73 | 73 |
74 protected: | 74 protected: |
75 virtual ~HttpServer(); | 75 virtual ~HttpServer(); |
76 | 76 |
77 private: | 77 private: |
78 friend class base::RefCountedThreadSafe<HttpServer>; | 78 friend class base::RefCountedThreadSafe<HttpServer>; |
79 friend class HttpConnection; | 79 friend class HttpConnection; |
80 | 80 |
81 // Expects the raw data to be stored in recv_data_. If parsing is successful, | 81 // Expects the raw data to be stored in recv_data_. If parsing is successful, |
82 // will remove the data parsed from recv_data_, leaving only the unused | 82 // will remove the data parsed from recv_data_, leaving only the unused |
83 // recv data. | 83 // recv data. |
84 bool ParseHeaders(HttpConnection* connection, | 84 bool ParseHeaders(HttpConnection* connection, |
85 HttpServerRequestInfo* info, | 85 HttpServerRequestInfo* info, |
86 size_t* pos); | 86 size_t* pos); |
87 | 87 |
88 HttpConnection* FindConnection(int connection_id); | 88 HttpConnection* FindConnection(int connection_id); |
89 HttpConnection* FindConnection(StreamListenSocket* socket); | 89 HttpConnection* FindConnection(StreamListenSocket* socket); |
90 | 90 |
91 HttpServer::Delegate* delegate_; | 91 HttpServer::Delegate* delegate_; |
92 scoped_refptr<StreamListenSocket> server_; | 92 scoped_ptr<StreamListenSocket> server_; |
93 typedef std::map<int, HttpConnection*> IdToConnectionMap; | 93 typedef std::map<int, HttpConnection*> IdToConnectionMap; |
94 IdToConnectionMap id_to_connection_; | 94 IdToConnectionMap id_to_connection_; |
95 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; | 95 typedef std::map<StreamListenSocket*, HttpConnection*> SocketToConnectionMap; |
96 SocketToConnectionMap socket_to_connection_; | 96 SocketToConnectionMap socket_to_connection_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(HttpServer); | 98 DISALLOW_COPY_AND_ASSIGN(HttpServer); |
99 }; | 99 }; |
100 | 100 |
101 } // namespace net | 101 } // namespace net |
102 | 102 |
103 #endif // NET_SERVER_HTTP_SERVER_H_ | 103 #endif // NET_SERVER_HTTP_SERVER_H_ |
OLD | NEW |