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

Side by Side Diff: webrtc/base/httpserver.h

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 5 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
« no previous file with comments | « webrtc/base/httpcommon_unittest.cc ('k') | webrtc/base/httpserver.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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_HTTPSERVER_H__ 11 #ifndef WEBRTC_BASE_HTTPSERVER_H_
12 #define WEBRTC_BASE_HTTPSERVER_H__ 12 #define WEBRTC_BASE_HTTPSERVER_H_
13 13
14 #include <map>
15 #include <memory>
16 14
17 #include "webrtc/base/httpbase.h" 15 // This header is deprecated and is just left here temporarily during
16 // refactoring. See https://bugs.webrtc.org/7634 for more details.
17 #include "webrtc/rtc_base/httpserver.h"
18 18
19 namespace rtc { 19 #endif // WEBRTC_BASE_HTTPSERVER_H_
20
21 class AsyncSocket;
22 class HttpServer;
23 class SocketAddress;
24
25 //////////////////////////////////////////////////////////////////////
26 // HttpServer
27 //////////////////////////////////////////////////////////////////////
28
29 const int HTTP_INVALID_CONNECTION_ID = 0;
30
31 struct HttpServerTransaction : public HttpTransaction {
32 public:
33 HttpServerTransaction(int id) : connection_id_(id) { }
34 int connection_id() const { return connection_id_; }
35
36 private:
37 int connection_id_;
38 };
39
40 class HttpServer {
41 public:
42 HttpServer();
43 virtual ~HttpServer();
44
45 int HandleConnection(StreamInterface* stream);
46 // Due to sigslot issues, we can't destroy some streams at an arbitrary time.
47 sigslot::signal3<HttpServer*, int, StreamInterface*> SignalConnectionClosed;
48
49 // This signal occurs when the HTTP request headers have been received, but
50 // before the request body is written to the request document. By default,
51 // the request document is a MemoryStream. By handling this signal, the
52 // document can be overridden, in which case the third signal argument should
53 // be set to true. In the case where the request body should be ignored,
54 // the document can be set to null. Note that the transaction object is still
55 // owened by the HttpServer at this point.
56 sigslot::signal3<HttpServer*, HttpServerTransaction*, bool*>
57 SignalHttpRequestHeader;
58
59 // An HTTP request has been made, and is available in the transaction object.
60 // Populate the transaction's response, and then return the object via the
61 // Respond method. Note that during this time, ownership of the transaction
62 // object is transferred, so it may be passed between threads, although
63 // respond must be called on the server's active thread.
64 sigslot::signal2<HttpServer*, HttpServerTransaction*> SignalHttpRequest;
65 void Respond(HttpServerTransaction* transaction);
66
67 // If you want to know when a request completes, listen to this event.
68 sigslot::signal3<HttpServer*, HttpServerTransaction*, int>
69 SignalHttpRequestComplete;
70
71 // Stop processing the connection indicated by connection_id.
72 // Unless force is true, the server will complete sending a response that is
73 // in progress.
74 void Close(int connection_id, bool force);
75 void CloseAll(bool force);
76
77 // After calling CloseAll, this event is signalled to indicate that all
78 // outstanding connections have closed.
79 sigslot::signal1<HttpServer*> SignalCloseAllComplete;
80
81 private:
82 class Connection : private IHttpNotify {
83 public:
84 Connection(int connection_id, HttpServer* server);
85 ~Connection() override;
86
87 void BeginProcess(StreamInterface* stream);
88 StreamInterface* EndProcess();
89
90 void Respond(HttpServerTransaction* transaction);
91 void InitiateClose(bool force);
92
93 // IHttpNotify Interface
94 HttpError onHttpHeaderComplete(bool chunked, size_t& data_size) override;
95 void onHttpComplete(HttpMode mode, HttpError err) override;
96 void onHttpClosed(HttpError err) override;
97
98 int connection_id_;
99 HttpServer* server_;
100 HttpBase base_;
101 HttpServerTransaction* current_;
102 bool signalling_, close_;
103 };
104
105 Connection* Find(int connection_id);
106 void Remove(int connection_id);
107
108 friend class Connection;
109 typedef std::map<int,Connection*> ConnectionMap;
110
111 ConnectionMap connections_;
112 int next_connection_id_;
113 bool closing_;
114 };
115
116 //////////////////////////////////////////////////////////////////////
117
118 class HttpListenServer : public HttpServer, public sigslot::has_slots<> {
119 public:
120 HttpListenServer();
121 ~HttpListenServer() override;
122
123 int Listen(const SocketAddress& address);
124 bool GetAddress(SocketAddress* address) const;
125 void StopListening();
126
127 private:
128 void OnReadEvent(AsyncSocket* socket);
129 void OnConnectionClosed(HttpServer* server, int connection_id,
130 StreamInterface* stream);
131
132 std::unique_ptr<AsyncSocket> listener_;
133 };
134
135 //////////////////////////////////////////////////////////////////////
136
137 } // namespace rtc
138
139 #endif // WEBRTC_BASE_HTTPSERVER_H__
OLDNEW
« no previous file with comments | « webrtc/base/httpcommon_unittest.cc ('k') | webrtc/base/httpserver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698