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 #include "net/socket/stream_listen_socket.h" | 5 #include "net/socket/stream_listen_socket.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 // winsock2.h must be included first in order to ensure it is included before | 8 // winsock2.h must be included first in order to ensure it is included before |
9 // windows.h. | 9 // windows.h. |
10 #include <winsock2.h> | 10 #include <winsock2.h> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // TODO(ibrar): We can add these functions into OS dependent files. | 245 // TODO(ibrar): We can add these functions into OS dependent files. |
246 #if defined(OS_WIN) | 246 #if defined(OS_WIN) |
247 // MessageLoop watcher callback. | 247 // MessageLoop watcher callback. |
248 void StreamListenSocket::OnObjectSignaled(HANDLE object) { | 248 void StreamListenSocket::OnObjectSignaled(HANDLE object) { |
249 WSANETWORKEVENTS ev; | 249 WSANETWORKEVENTS ev; |
250 if (kSocketError == WSAEnumNetworkEvents(socket_, socket_event_, &ev)) { | 250 if (kSocketError == WSAEnumNetworkEvents(socket_, socket_event_, &ev)) { |
251 // TODO | 251 // TODO |
252 return; | 252 return; |
253 } | 253 } |
254 | 254 |
255 if (ev.lNetworkEvents & FD_CLOSE) { | 255 if (!(ev.lNetworkEvents & FD_CLOSE)) { |
256 Close(); | 256 // The object was reset by WSAEnumNetworkEvents. Watch for the next signal. |
257 // Close might have deleted this object. We should return immediately. | 257 watcher_.StartWatching(object, this); |
258 return; | |
259 } | 258 } |
260 | 259 |
261 // The object was reset by WSAEnumNetworkEvents. Watch for the next signal. | |
262 watcher_.StartWatching(object, this); | |
263 | 260 |
264 if (ev.lNetworkEvents == 0) { | 261 if (ev.lNetworkEvents == 0) { |
265 // Occasionally the event is set even though there is no new data. | 262 // Occasionally the event is set even though there is no new data. |
266 // The net seems to think that this is ignorable. | 263 // The net seems to think that this is ignorable. |
267 return; | 264 return; |
268 } | 265 } |
269 if (ev.lNetworkEvents & FD_ACCEPT) { | 266 if (ev.lNetworkEvents & FD_ACCEPT) { |
270 Accept(); | 267 Accept(); |
271 } | 268 } |
272 if (ev.lNetworkEvents & FD_READ) { | 269 if (ev.lNetworkEvents & FD_READ) { |
273 if (reads_paused_) { | 270 if (reads_paused_) { |
274 has_pending_reads_ = true; | 271 has_pending_reads_ = true; |
275 } else { | 272 } else { |
276 Read(); | 273 Read(); |
277 // Read() might call Close() internally and 'this' can be invalid here | 274 // Read doesn't call Close() in Windows case. We keep going. |
278 return; | |
279 } | 275 } |
280 } | 276 } |
| 277 if (ev.lNetworkEvents & FD_CLOSE) { |
| 278 Close(); |
| 279 // Close might have deleted this object. We should return immediately. |
| 280 return; |
| 281 } |
281 } | 282 } |
282 #elif defined(OS_POSIX) | 283 #elif defined(OS_POSIX) |
283 void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) { | 284 void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) { |
284 switch (wait_state_) { | 285 switch (wait_state_) { |
285 case WAITING_ACCEPT: | 286 case WAITING_ACCEPT: |
286 Accept(); | 287 Accept(); |
287 break; | 288 break; |
288 case WAITING_READ: | 289 case WAITING_READ: |
289 if (reads_paused_) { | 290 if (reads_paused_) { |
290 has_pending_reads_ = true; | 291 has_pending_reads_ = true; |
(...skipping 24 matching lines...) Expand all Loading... |
315 void StreamListenSocket::ResumeReads() { | 316 void StreamListenSocket::ResumeReads() { |
316 DCHECK(reads_paused_); | 317 DCHECK(reads_paused_); |
317 reads_paused_ = false; | 318 reads_paused_ = false; |
318 if (has_pending_reads_) { | 319 if (has_pending_reads_) { |
319 has_pending_reads_ = false; | 320 has_pending_reads_ = false; |
320 Read(); | 321 Read(); |
321 } | 322 } |
322 } | 323 } |
323 | 324 |
324 } // namespace net | 325 } // namespace net |
OLD | NEW |