OLD | NEW |
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 |
(...skipping 27 matching lines...) Expand all Loading... |
38 ++it) { | 38 ++it) { |
39 StreamInterface* stream = it->second->EndProcess(); | 39 StreamInterface* stream = it->second->EndProcess(); |
40 delete stream; | 40 delete stream; |
41 delete it->second; | 41 delete it->second; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 int | 45 int |
46 HttpServer::HandleConnection(StreamInterface* stream) { | 46 HttpServer::HandleConnection(StreamInterface* stream) { |
47 int connection_id = next_connection_id_++; | 47 int connection_id = next_connection_id_++; |
48 ASSERT(connection_id != HTTP_INVALID_CONNECTION_ID); | 48 RTC_DCHECK(connection_id != HTTP_INVALID_CONNECTION_ID); |
49 Connection* connection = new Connection(connection_id, this); | 49 Connection* connection = new Connection(connection_id, this); |
50 connections_.insert(ConnectionMap::value_type(connection_id, connection)); | 50 connections_.insert(ConnectionMap::value_type(connection_id, connection)); |
51 connection->BeginProcess(stream); | 51 connection->BeginProcess(stream); |
52 return connection_id; | 52 return connection_id; |
53 } | 53 } |
54 | 54 |
55 void | 55 void |
56 HttpServer::Respond(HttpServerTransaction* transaction) { | 56 HttpServer::Respond(HttpServerTransaction* transaction) { |
57 int connection_id = transaction->connection_id(); | 57 int connection_id = transaction->connection_id(); |
58 if (Connection* connection = Find(connection_id)) { | 58 if (Connection* connection = Find(connection_id)) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 StreamInterface* | 141 StreamInterface* |
142 HttpServer::Connection::EndProcess() { | 142 HttpServer::Connection::EndProcess() { |
143 base_.notify(NULL); | 143 base_.notify(NULL); |
144 base_.abort(HE_DISCONNECTED); | 144 base_.abort(HE_DISCONNECTED); |
145 return base_.detach(); | 145 return base_.detach(); |
146 } | 146 } |
147 | 147 |
148 void | 148 void |
149 HttpServer::Connection::Respond(HttpServerTransaction* transaction) { | 149 HttpServer::Connection::Respond(HttpServerTransaction* transaction) { |
150 ASSERT(current_ == NULL); | 150 RTC_DCHECK(current_ == NULL); |
151 current_ = transaction; | 151 current_ = transaction; |
152 if (current_->response.begin() == current_->response.end()) { | 152 if (current_->response.begin() == current_->response.end()) { |
153 current_->response.set_error(HC_INTERNAL_SERVER_ERROR); | 153 current_->response.set_error(HC_INTERNAL_SERVER_ERROR); |
154 } | 154 } |
155 bool keep_alive = HttpShouldKeepAlive(current_->request); | 155 bool keep_alive = HttpShouldKeepAlive(current_->request); |
156 current_->response.setHeader(HH_CONNECTION, | 156 current_->response.setHeader(HH_CONNECTION, |
157 keep_alive ? "Keep-Alive" : "Close", | 157 keep_alive ? "Keep-Alive" : "Close", |
158 false); | 158 false); |
159 close_ = !HttpShouldKeepAlive(current_->response); | 159 close_ = !HttpShouldKeepAlive(current_->response); |
160 base_.send(¤t_->response); | 160 base_.send(¤t_->response); |
(...skipping 11 matching lines...) Expand all Loading... |
172 | 172 |
173 // | 173 // |
174 // IHttpNotify Implementation | 174 // IHttpNotify Implementation |
175 // | 175 // |
176 | 176 |
177 HttpError | 177 HttpError |
178 HttpServer::Connection::onHttpHeaderComplete(bool chunked, size_t& data_size) { | 178 HttpServer::Connection::onHttpHeaderComplete(bool chunked, size_t& data_size) { |
179 if (data_size == SIZE_UNKNOWN) { | 179 if (data_size == SIZE_UNKNOWN) { |
180 data_size = 0; | 180 data_size = 0; |
181 } | 181 } |
182 ASSERT(current_ != NULL); | 182 RTC_DCHECK(current_ != NULL); |
183 bool custom_document = false; | 183 bool custom_document = false; |
184 server_->SignalHttpRequestHeader(server_, current_, &custom_document); | 184 server_->SignalHttpRequestHeader(server_, current_, &custom_document); |
185 if (!custom_document) { | 185 if (!custom_document) { |
186 current_->request.document.reset(new MemoryStream); | 186 current_->request.document.reset(new MemoryStream); |
187 } | 187 } |
188 return HE_NONE; | 188 return HE_NONE; |
189 } | 189 } |
190 | 190 |
191 void | 191 void |
192 HttpServer::Connection::onHttpComplete(HttpMode mode, HttpError err) { | 192 HttpServer::Connection::onHttpComplete(HttpMode mode, HttpError err) { |
193 if (mode == HM_SEND) { | 193 if (mode == HM_SEND) { |
194 ASSERT(current_ != NULL); | 194 RTC_DCHECK(current_ != NULL); |
195 signalling_ = true; | 195 signalling_ = true; |
196 server_->SignalHttpRequestComplete(server_, current_, err); | 196 server_->SignalHttpRequestComplete(server_, current_, err); |
197 signalling_ = false; | 197 signalling_ = false; |
198 if (close_) { | 198 if (close_) { |
199 // Force a close | 199 // Force a close |
200 err = HE_DISCONNECTED; | 200 err = HE_DISCONNECTED; |
201 } | 201 } |
202 } | 202 } |
203 if (err != HE_NONE) { | 203 if (err != HE_NONE) { |
204 server_->Remove(connection_id_); | 204 server_->Remove(connection_id_); |
205 } else if (mode == HM_CONNECT) { | 205 } else if (mode == HM_CONNECT) { |
206 base_.recv(¤t_->request); | 206 base_.recv(¤t_->request); |
207 } else if (mode == HM_RECV) { | 207 } else if (mode == HM_RECV) { |
208 ASSERT(current_ != NULL); | 208 RTC_DCHECK(current_ != NULL); |
209 // TODO: do we need this? | 209 // TODO: do we need this? |
210 //request_.document_->rewind(); | 210 //request_.document_->rewind(); |
211 HttpServerTransaction* transaction = current_; | 211 HttpServerTransaction* transaction = current_; |
212 current_ = NULL; | 212 current_ = NULL; |
213 server_->SignalHttpRequest(server_, transaction); | 213 server_->SignalHttpRequest(server_, transaction); |
214 } else if (mode == HM_SEND) { | 214 } else if (mode == HM_SEND) { |
215 Thread::Current()->Dispose(current_->response.document.release()); | 215 Thread::Current()->Dispose(current_->response.document.release()); |
216 current_->request.clear(true); | 216 current_->request.clear(true); |
217 current_->response.clear(true); | 217 current_->response.clear(true); |
218 base_.recv(¤t_->request); | 218 base_.recv(¤t_->request); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 return !address->IsNil(); | 261 return !address->IsNil(); |
262 } | 262 } |
263 | 263 |
264 void HttpListenServer::StopListening() { | 264 void HttpListenServer::StopListening() { |
265 if (listener_) { | 265 if (listener_) { |
266 listener_->Close(); | 266 listener_->Close(); |
267 } | 267 } |
268 } | 268 } |
269 | 269 |
270 void HttpListenServer::OnReadEvent(AsyncSocket* socket) { | 270 void HttpListenServer::OnReadEvent(AsyncSocket* socket) { |
271 ASSERT(socket == listener_.get()); | 271 RTC_DCHECK(socket == listener_.get()); |
272 AsyncSocket* incoming = listener_->Accept(NULL); | 272 AsyncSocket* incoming = listener_->Accept(NULL); |
273 if (incoming) { | 273 if (incoming) { |
274 StreamInterface* stream = new SocketStream(incoming); | 274 StreamInterface* stream = new SocketStream(incoming); |
275 //stream = new LoggingAdapter(stream, LS_VERBOSE, "HttpServer", false); | 275 //stream = new LoggingAdapter(stream, LS_VERBOSE, "HttpServer", false); |
276 HandleConnection(stream); | 276 HandleConnection(stream); |
277 } | 277 } |
278 } | 278 } |
279 | 279 |
280 void HttpListenServer::OnConnectionClosed(HttpServer* server, | 280 void HttpListenServer::OnConnectionClosed(HttpServer* server, |
281 int connection_id, | 281 int connection_id, |
282 StreamInterface* stream) { | 282 StreamInterface* stream) { |
283 Thread::Current()->Dispose(stream); | 283 Thread::Current()->Dispose(stream); |
284 } | 284 } |
285 | 285 |
286 /////////////////////////////////////////////////////////////////////////////// | 286 /////////////////////////////////////////////////////////////////////////////// |
287 | 287 |
288 } // namespace rtc | 288 } // namespace rtc |
OLD | NEW |