| 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 both FD_CLOSE and FD_READ are set we only call Read(). |
| 256 // The object was reset by WSAEnumNetworkEvents. Watch for the next signal. | 256 // This will cause OnObjectSignaled to be called immediately again |
| 257 watcher_.StartWatching(object, this); | 257 // unless this socket is destroyed in Read(). |
| 258 if ((ev.lNetworkEvents & (FD_CLOSE | FD_READ)) == FD_CLOSE) { |
| 259 Close(); |
| 260 // Close might have deleted this object. We should return immediately. |
| 261 return; |
| 258 } | 262 } |
| 259 | 263 // The object was reset by WSAEnumNetworkEvents. Watch for the next signal. |
| 264 watcher_.StartWatching(object, this); |
| 260 | 265 |
| 261 if (ev.lNetworkEvents == 0) { | 266 if (ev.lNetworkEvents == 0) { |
| 262 // Occasionally the event is set even though there is no new data. | 267 // Occasionally the event is set even though there is no new data. |
| 263 // The net seems to think that this is ignorable. | 268 // The net seems to think that this is ignorable. |
| 264 return; | 269 return; |
| 265 } | 270 } |
| 266 if (ev.lNetworkEvents & FD_ACCEPT) { | 271 if (ev.lNetworkEvents & FD_ACCEPT) { |
| 267 Accept(); | 272 Accept(); |
| 268 } | 273 } |
| 269 if (ev.lNetworkEvents & FD_READ) { | 274 if (ev.lNetworkEvents & FD_READ) { |
| 270 if (reads_paused_) { | 275 if (reads_paused_) { |
| 271 has_pending_reads_ = true; | 276 has_pending_reads_ = true; |
| 272 } else { | 277 } else { |
| 273 Read(); | 278 Read(); |
| 274 // Read doesn't call Close() in Windows case. We keep going. | 279 // Read might have deleted this object. We should return immediately. |
| 275 } | 280 } |
| 276 } | 281 } |
| 277 if (ev.lNetworkEvents & FD_CLOSE) { | |
| 278 Close(); | |
| 279 // Close might have deleted this object. We should return immediately. | |
| 280 return; | |
| 281 } | |
| 282 } | 282 } |
| 283 #elif defined(OS_POSIX) | 283 #elif defined(OS_POSIX) |
| 284 void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) { | 284 void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) { |
| 285 switch (wait_state_) { | 285 switch (wait_state_) { |
| 286 case WAITING_ACCEPT: | 286 case WAITING_ACCEPT: |
| 287 Accept(); | 287 Accept(); |
| 288 break; | 288 break; |
| 289 case WAITING_READ: | 289 case WAITING_READ: |
| 290 if (reads_paused_) { | 290 if (reads_paused_) { |
| 291 has_pending_reads_ = true; | 291 has_pending_reads_ = true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 316 void StreamListenSocket::ResumeReads() { | 316 void StreamListenSocket::ResumeReads() { |
| 317 DCHECK(reads_paused_); | 317 DCHECK(reads_paused_); |
| 318 reads_paused_ = false; | 318 reads_paused_ = false; |
| 319 if (has_pending_reads_) { | 319 if (has_pending_reads_) { |
| 320 has_pending_reads_ = false; | 320 has_pending_reads_ = false; |
| 321 Read(); | 321 Read(); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace net | 325 } // namespace net |
| OLD | NEW |