| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "nacl_io/socket/tcp_event_emitter.h" | 5 #include "nacl_io/socket/tcp_event_emitter.h" |
| 6 | 6 |
| 7 #include <poll.h> | 7 #include <poll.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 | 10 |
| 11 #include "nacl_io/fifo_char.h" | 11 #include "nacl_io/fifo_char.h" |
| 12 #include "sdk_util/auto_lock.h" | 12 #include "sdk_util/auto_lock.h" |
| 13 | 13 |
| 14 namespace nacl_io { | 14 namespace nacl_io { |
| 15 | 15 |
| 16 TcpEventEmitter::TcpEventEmitter(size_t rsize, size_t wsize) | 16 TcpEventEmitter::TcpEventEmitter(size_t rsize, size_t wsize) |
| 17 : in_fifo_(rsize), | 17 : in_fifo_(rsize), |
| 18 out_fifo_(wsize), | 18 out_fifo_(wsize), |
| 19 error_(false), | 19 error_(false), |
| 20 listening_(false), | 20 listening_(false), |
| 21 accepted_socket_(0) {} | 21 accepted_socket_(0) { |
| 22 } |
| 22 | 23 |
| 23 uint32_t TcpEventEmitter::ReadIn_Locked(char* data, uint32_t len) { | 24 uint32_t TcpEventEmitter::ReadIn_Locked(char* data, uint32_t len) { |
| 24 uint32_t count = in_fifo_.Read(data, len); | 25 uint32_t count = in_fifo_.Read(data, len); |
| 25 UpdateStatus_Locked(); | 26 UpdateStatus_Locked(); |
| 26 return count; | 27 return count; |
| 27 } | 28 } |
| 28 | 29 |
| 29 void TcpEventEmitter::UpdateStatus_Locked() { | 30 void TcpEventEmitter::UpdateStatus_Locked() { |
| 30 if (error_) { | 31 if (error_) { |
| 31 RaiseEvents_Locked(POLLIN | POLLOUT); | 32 RaiseEvents_Locked(POLLIN | POLLOUT); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 UpdateStatus_Locked(); | 67 UpdateStatus_Locked(); |
| 67 return count; | 68 return count; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void TcpEventEmitter::ConnectDone_Locked() { | 71 void TcpEventEmitter::ConnectDone_Locked() { |
| 71 RaiseEvents_Locked(POLLOUT); | 72 RaiseEvents_Locked(POLLOUT); |
| 72 UpdateStatus_Locked(); | 73 UpdateStatus_Locked(); |
| 73 } | 74 } |
| 74 | 75 |
| 75 bool TcpEventEmitter::GetError_Locked() { return error_; } | 76 bool TcpEventEmitter::GetError_Locked() { |
| 77 return error_; |
| 78 } |
| 76 | 79 |
| 77 void TcpEventEmitter::SetError_Locked() { | 80 void TcpEventEmitter::SetError_Locked() { |
| 78 error_ = true; | 81 error_ = true; |
| 79 UpdateStatus_Locked(); | 82 UpdateStatus_Locked(); |
| 80 } | 83 } |
| 81 | 84 |
| 82 void TcpEventEmitter::SetAcceptedSocket_Locked(PP_Resource socket) { | 85 void TcpEventEmitter::SetAcceptedSocket_Locked(PP_Resource socket) { |
| 83 accepted_socket_ = socket; | 86 accepted_socket_ = socket; |
| 84 UpdateStatus_Locked(); | 87 UpdateStatus_Locked(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 PP_Resource TcpEventEmitter::GetAcceptedSocket_Locked() { | 90 PP_Resource TcpEventEmitter::GetAcceptedSocket_Locked() { |
| 88 int rtn = accepted_socket_; | 91 int rtn = accepted_socket_; |
| 89 accepted_socket_ = 0; | 92 accepted_socket_ = 0; |
| 90 UpdateStatus_Locked(); | 93 UpdateStatus_Locked(); |
| 91 return rtn; | 94 return rtn; |
| 92 } | 95 } |
| 93 | 96 |
| 94 uint32_t TcpEventEmitter::BytesInOutputFIFO() { | 97 uint32_t TcpEventEmitter::BytesInOutputFIFO() { |
| 95 return out_fifo()->ReadAvailable(); | 98 return out_fifo()->ReadAvailable(); |
| 96 } | 99 } |
| 97 | 100 |
| 98 uint32_t TcpEventEmitter::SpaceInInputFIFO() { | 101 uint32_t TcpEventEmitter::SpaceInInputFIFO() { |
| 99 return in_fifo()->WriteAvailable(); | 102 return in_fifo()->WriteAvailable(); |
| 100 } | 103 } |
| 101 | 104 |
| 102 } // namespace nacl_io | 105 } // namespace nacl_io |
| OLD | NEW |