| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 waiting_connect_ = false; | 433 waiting_connect_ = false; |
| 434 base::ResetAndReturn(&write_callback_).Run(rv); | 434 base::ResetAndReturn(&write_callback_).Run(rv); |
| 435 } | 435 } |
| 436 | 436 |
| 437 int SocketLibevent::DoRead(IOBuffer* buf, int buf_len) { | 437 int SocketLibevent::DoRead(IOBuffer* buf, int buf_len) { |
| 438 int rv = HANDLE_EINTR(read(socket_fd_, buf->data(), buf_len)); | 438 int rv = HANDLE_EINTR(read(socket_fd_, buf->data(), buf_len)); |
| 439 return rv >= 0 ? rv : MapSystemError(errno); | 439 return rv >= 0 ? rv : MapSystemError(errno); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void SocketLibevent::ReadCompleted() { | 442 void SocketLibevent::ReadCompleted() { |
| 443 int rv = DoRead(read_buf_, read_buf_len_); | 443 int rv = DoRead(read_buf_.get(), read_buf_len_); |
| 444 if (rv == ERR_IO_PENDING) | 444 if (rv == ERR_IO_PENDING) |
| 445 return; | 445 return; |
| 446 | 446 |
| 447 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); | 447 bool ok = read_socket_watcher_.StopWatchingFileDescriptor(); |
| 448 DCHECK(ok); | 448 DCHECK(ok); |
| 449 read_buf_ = NULL; | 449 read_buf_ = NULL; |
| 450 read_buf_len_ = 0; | 450 read_buf_len_ = 0; |
| 451 base::ResetAndReturn(&read_callback_).Run(rv); | 451 base::ResetAndReturn(&read_callback_).Run(rv); |
| 452 } | 452 } |
| 453 | 453 |
| 454 int SocketLibevent::DoWrite(IOBuffer* buf, int buf_len) { | 454 int SocketLibevent::DoWrite(IOBuffer* buf, int buf_len) { |
| 455 int rv = HANDLE_EINTR(write(socket_fd_, buf->data(), buf_len)); | 455 int rv = HANDLE_EINTR(write(socket_fd_, buf->data(), buf_len)); |
| 456 return rv >= 0 ? rv : MapSystemError(errno); | 456 return rv >= 0 ? rv : MapSystemError(errno); |
| 457 } | 457 } |
| 458 | 458 |
| 459 void SocketLibevent::WriteCompleted() { | 459 void SocketLibevent::WriteCompleted() { |
| 460 int rv = DoWrite(write_buf_, write_buf_len_); | 460 int rv = DoWrite(write_buf_.get(), write_buf_len_); |
| 461 if (rv == ERR_IO_PENDING) | 461 if (rv == ERR_IO_PENDING) |
| 462 return; | 462 return; |
| 463 | 463 |
| 464 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); | 464 bool ok = write_socket_watcher_.StopWatchingFileDescriptor(); |
| 465 DCHECK(ok); | 465 DCHECK(ok); |
| 466 write_buf_ = NULL; | 466 write_buf_ = NULL; |
| 467 write_buf_len_ = 0; | 467 write_buf_len_ = 0; |
| 468 base::ResetAndReturn(&write_callback_).Run(rv); | 468 base::ResetAndReturn(&write_callback_).Run(rv); |
| 469 } | 469 } |
| 470 | 470 |
| 471 } // namespace net | 471 } // namespace net |
| OLD | NEW |