| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/socket_libevent.h" | 5 #include "net/socket/socket_libevent.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <netinet/in.h> | 8 #include <netinet/in.h> |
| 9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 | 10 |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 return; | 411 return; |
| 412 | 412 |
| 413 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); | 413 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); |
| 414 DCHECK(ok); | 414 DCHECK(ok); |
| 415 waiting_connect_ = false; | 415 waiting_connect_ = false; |
| 416 base::ResetAndReturn(&write_callback_).Run(rv); | 416 base::ResetAndReturn(&write_callback_).Run(rv); |
| 417 } | 417 } |
| 418 | 418 |
| 419 int SocketLibevent::DoRead(IOBuffer* buf, int buf_len) { | 419 int SocketLibevent::DoRead(IOBuffer* buf, int buf_len) { |
| 420 int rv = HANDLE_EINTR(read(socket_fd_, buf->data(), buf_len)); | 420 int rv = HANDLE_EINTR(read(socket_fd_, buf->data(), buf_len)); |
| 421 return rv >= 0 ? rv : MapSystemError(errno); | 421 if (rv >= 0) { |
| 422 return rv; |
| 423 } else if (errno != EAGAIN) { |
| 424 return MapSystemError(errno); |
| 425 } |
| 426 |
| 427 // The socket may have OOB data waiting, and libevent does not distinguish |
| 428 // between ready inline and out-of-band data when it activates the |
| 429 // callback. See if there is OOB data available. |
| 430 rv = HANDLE_EINTR(recv(socket_fd_, buf->data(), buf_len, MSG_OOB)); |
| 431 if (rv >= 0) { |
| 432 return ERR_OOB_DATA; |
| 433 } |
| 434 return ERR_IO_PENDING; |
| 422 } | 435 } |
| 423 | 436 |
| 424 void SocketLibevent::ReadCompleted() { | 437 void SocketLibevent::ReadCompleted() { |
| 425 int rv = DoRead(read_buf_.get(), read_buf_len_); | 438 int rv = DoRead(read_buf_.get(), read_buf_len_); |
| 426 if (rv == ERR_IO_PENDING) | 439 if (rv == ERR_IO_PENDING) |
| 427 return; | 440 return; |
| 428 | 441 |
| 429 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); | 442 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); |
| 430 DCHECK(ok); | 443 DCHECK(ok); |
| 431 read_buf_ = NULL; | 444 read_buf_ = NULL; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 write_buf_ = NULL; | 486 write_buf_ = NULL; |
| 474 write_buf_len_ = 0; | 487 write_buf_len_ = 0; |
| 475 write_callback_.Reset(); | 488 write_callback_.Reset(); |
| 476 } | 489 } |
| 477 | 490 |
| 478 waiting_connect_ = false; | 491 waiting_connect_ = false; |
| 479 peer_address_.reset(); | 492 peer_address_.reset(); |
| 480 } | 493 } |
| 481 | 494 |
| 482 } // namespace net | 495 } // namespace net |
| OLD | NEW |