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

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

Issue 2718663005: Replace NULL with nullptr or null in webrtc/base/. (Closed)
Patch Set: Fixing Windows and formatting issues. Created 3 years, 9 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/httpserver.h ('k') | webrtc/base/httpserver_unittest.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
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 for (std::list<Connection*>::const_iterator it = connections.begin(); 85 for (std::list<Connection*>::const_iterator it = connections.begin();
86 it != connections.end(); ++it) { 86 it != connections.end(); ++it) {
87 (*it)->InitiateClose(force); 87 (*it)->InitiateClose(force);
88 } 88 }
89 } 89 }
90 90
91 HttpServer::Connection* 91 HttpServer::Connection*
92 HttpServer::Find(int connection_id) { 92 HttpServer::Find(int connection_id) {
93 ConnectionMap::iterator it = connections_.find(connection_id); 93 ConnectionMap::iterator it = connections_.find(connection_id);
94 if (it == connections_.end()) 94 if (it == connections_.end())
95 return NULL; 95 return nullptr;
96 return it->second; 96 return it->second;
97 } 97 }
98 98
99 void 99 void
100 HttpServer::Remove(int connection_id) { 100 HttpServer::Remove(int connection_id) {
101 ConnectionMap::iterator it = connections_.find(connection_id); 101 ConnectionMap::iterator it = connections_.find(connection_id);
102 if (it == connections_.end()) { 102 if (it == connections_.end()) {
103 RTC_NOTREACHED(); 103 RTC_NOTREACHED();
104 return; 104 return;
105 } 105 }
106 Connection* connection = it->second; 106 Connection* connection = it->second;
107 connections_.erase(it); 107 connections_.erase(it);
108 SignalConnectionClosed(this, connection_id, connection->EndProcess()); 108 SignalConnectionClosed(this, connection_id, connection->EndProcess());
109 delete connection; 109 delete connection;
110 if (closing_ && connections_.empty()) { 110 if (closing_ && connections_.empty()) {
111 closing_ = false; 111 closing_ = false;
112 SignalCloseAllComplete(this); 112 SignalCloseAllComplete(this);
113 } 113 }
114 } 114 }
115 115
116 /////////////////////////////////////////////////////////////////////////////// 116 ///////////////////////////////////////////////////////////////////////////////
117 // HttpServer::Connection 117 // HttpServer::Connection
118 /////////////////////////////////////////////////////////////////////////////// 118 ///////////////////////////////////////////////////////////////////////////////
119 119
120 HttpServer::Connection::Connection(int connection_id, HttpServer* server) 120 HttpServer::Connection::Connection(int connection_id, HttpServer* server)
121 : connection_id_(connection_id), server_(server), 121 : connection_id_(connection_id),
122 current_(NULL), signalling_(false), close_(false) { 122 server_(server),
123 } 123 current_(nullptr),
124 signalling_(false),
125 close_(false) {}
124 126
125 HttpServer::Connection::~Connection() { 127 HttpServer::Connection::~Connection() {
126 // It's possible that an object hosted inside this transaction signalled 128 // It's possible that an object hosted inside this transaction signalled
127 // an event which caused the connection to close. 129 // an event which caused the connection to close.
128 Thread::Current()->Dispose(current_); 130 Thread::Current()->Dispose(current_);
129 } 131 }
130 132
131 void 133 void
132 HttpServer::Connection::BeginProcess(StreamInterface* stream) { 134 HttpServer::Connection::BeginProcess(StreamInterface* stream) {
133 base_.notify(this); 135 base_.notify(this);
134 base_.attach(stream); 136 base_.attach(stream);
135 current_ = new HttpServerTransaction(connection_id_); 137 current_ = new HttpServerTransaction(connection_id_);
136 if (base_.mode() != HM_CONNECT) 138 if (base_.mode() != HM_CONNECT)
137 base_.recv(&current_->request); 139 base_.recv(&current_->request);
138 } 140 }
139 141
140 StreamInterface* 142 StreamInterface*
141 HttpServer::Connection::EndProcess() { 143 HttpServer::Connection::EndProcess() {
142 base_.notify(NULL); 144 base_.notify(nullptr);
143 base_.abort(HE_DISCONNECTED); 145 base_.abort(HE_DISCONNECTED);
144 return base_.detach(); 146 return base_.detach();
145 } 147 }
146 148
147 void 149 void
148 HttpServer::Connection::Respond(HttpServerTransaction* transaction) { 150 HttpServer::Connection::Respond(HttpServerTransaction* transaction) {
149 RTC_DCHECK(current_ == NULL); 151 RTC_DCHECK(current_ == nullptr);
150 current_ = transaction; 152 current_ = transaction;
151 if (current_->response.begin() == current_->response.end()) { 153 if (current_->response.begin() == current_->response.end()) {
152 current_->response.set_error(HC_INTERNAL_SERVER_ERROR); 154 current_->response.set_error(HC_INTERNAL_SERVER_ERROR);
153 } 155 }
154 bool keep_alive = HttpShouldKeepAlive(current_->request); 156 bool keep_alive = HttpShouldKeepAlive(current_->request);
155 current_->response.setHeader(HH_CONNECTION, 157 current_->response.setHeader(HH_CONNECTION,
156 keep_alive ? "Keep-Alive" : "Close", 158 keep_alive ? "Keep-Alive" : "Close",
157 false); 159 false);
158 close_ = !HttpShouldKeepAlive(current_->response); 160 close_ = !HttpShouldKeepAlive(current_->response);
159 base_.send(&current_->response); 161 base_.send(&current_->response);
160 } 162 }
161 163
162 void 164 void
163 HttpServer::Connection::InitiateClose(bool force) { 165 HttpServer::Connection::InitiateClose(bool force) {
164 bool request_in_progress = (HM_SEND == base_.mode()) || (NULL == current_); 166 bool request_in_progress = (HM_SEND == base_.mode()) || (nullptr == current_);
165 if (!signalling_ && (force || !request_in_progress)) { 167 if (!signalling_ && (force || !request_in_progress)) {
166 server_->Remove(connection_id_); 168 server_->Remove(connection_id_);
167 } else { 169 } else {
168 close_ = true; 170 close_ = true;
169 } 171 }
170 } 172 }
171 173
172 // 174 //
173 // IHttpNotify Implementation 175 // IHttpNotify Implementation
174 // 176 //
175 177
176 HttpError 178 HttpError
177 HttpServer::Connection::onHttpHeaderComplete(bool chunked, size_t& data_size) { 179 HttpServer::Connection::onHttpHeaderComplete(bool chunked, size_t& data_size) {
178 if (data_size == SIZE_UNKNOWN) { 180 if (data_size == SIZE_UNKNOWN) {
179 data_size = 0; 181 data_size = 0;
180 } 182 }
181 RTC_DCHECK(current_ != NULL); 183 RTC_DCHECK(current_ != nullptr);
182 bool custom_document = false; 184 bool custom_document = false;
183 server_->SignalHttpRequestHeader(server_, current_, &custom_document); 185 server_->SignalHttpRequestHeader(server_, current_, &custom_document);
184 if (!custom_document) { 186 if (!custom_document) {
185 current_->request.document.reset(new MemoryStream); 187 current_->request.document.reset(new MemoryStream);
186 } 188 }
187 return HE_NONE; 189 return HE_NONE;
188 } 190 }
189 191
190 void 192 void
191 HttpServer::Connection::onHttpComplete(HttpMode mode, HttpError err) { 193 HttpServer::Connection::onHttpComplete(HttpMode mode, HttpError err) {
192 if (mode == HM_SEND) { 194 if (mode == HM_SEND) {
193 RTC_DCHECK(current_ != NULL); 195 RTC_DCHECK(current_ != nullptr);
194 signalling_ = true; 196 signalling_ = true;
195 server_->SignalHttpRequestComplete(server_, current_, err); 197 server_->SignalHttpRequestComplete(server_, current_, err);
196 signalling_ = false; 198 signalling_ = false;
197 if (close_) { 199 if (close_) {
198 // Force a close 200 // Force a close
199 err = HE_DISCONNECTED; 201 err = HE_DISCONNECTED;
200 } 202 }
201 } 203 }
202 if (err != HE_NONE) { 204 if (err != HE_NONE) {
203 server_->Remove(connection_id_); 205 server_->Remove(connection_id_);
204 } else if (mode == HM_CONNECT) { 206 } else if (mode == HM_CONNECT) {
205 base_.recv(&current_->request); 207 base_.recv(&current_->request);
206 } else if (mode == HM_RECV) { 208 } else if (mode == HM_RECV) {
207 RTC_DCHECK(current_ != NULL); 209 RTC_DCHECK(current_ != nullptr);
208 // TODO: do we need this? 210 // TODO: do we need this?
209 //request_.document_->rewind(); 211 //request_.document_->rewind();
210 HttpServerTransaction* transaction = current_; 212 HttpServerTransaction* transaction = current_;
211 current_ = NULL; 213 current_ = nullptr;
212 server_->SignalHttpRequest(server_, transaction); 214 server_->SignalHttpRequest(server_, transaction);
213 } else if (mode == HM_SEND) { 215 } else if (mode == HM_SEND) {
214 Thread::Current()->Dispose(current_->response.document.release()); 216 Thread::Current()->Dispose(current_->response.document.release());
215 current_->request.clear(true); 217 current_->request.clear(true);
216 current_->response.clear(true); 218 current_->response.clear(true);
217 base_.recv(&current_->request); 219 base_.recv(&current_->request);
218 } else { 220 } else {
219 RTC_NOTREACHED(); 221 RTC_NOTREACHED();
220 } 222 }
221 } 223 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 262 }
261 263
262 void HttpListenServer::StopListening() { 264 void HttpListenServer::StopListening() {
263 if (listener_) { 265 if (listener_) {
264 listener_->Close(); 266 listener_->Close();
265 } 267 }
266 } 268 }
267 269
268 void HttpListenServer::OnReadEvent(AsyncSocket* socket) { 270 void HttpListenServer::OnReadEvent(AsyncSocket* socket) {
269 RTC_DCHECK(socket == listener_.get()); 271 RTC_DCHECK(socket == listener_.get());
270 AsyncSocket* incoming = listener_->Accept(NULL); 272 AsyncSocket* incoming = listener_->Accept(nullptr);
271 if (incoming) { 273 if (incoming) {
272 StreamInterface* stream = new SocketStream(incoming); 274 StreamInterface* stream = new SocketStream(incoming);
273 //stream = new LoggingAdapter(stream, LS_VERBOSE, "HttpServer", false); 275 //stream = new LoggingAdapter(stream, LS_VERBOSE, "HttpServer", false);
274 HandleConnection(stream); 276 HandleConnection(stream);
275 } 277 }
276 } 278 }
277 279
278 void HttpListenServer::OnConnectionClosed(HttpServer* server, 280 void HttpListenServer::OnConnectionClosed(HttpServer* server,
279 int connection_id, 281 int connection_id,
280 StreamInterface* stream) { 282 StreamInterface* stream) {
281 Thread::Current()->Dispose(stream); 283 Thread::Current()->Dispose(stream);
282 } 284 }
283 285
284 /////////////////////////////////////////////////////////////////////////////// 286 ///////////////////////////////////////////////////////////////////////////////
285 287
286 } // namespace rtc 288 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/httpserver.h ('k') | webrtc/base/httpserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698