| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/event_emitter_tcp.h" | 5 #include "nacl_io/event_emitter_tcp.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 EventEmitterTCP::EventEmitterTCP(size_t rsize, size_t wsize) | 16 EventEmitterTCP::EventEmitterTCP(size_t rsize, size_t wsize) |
| 17 : in_fifo_(std::max<size_t>(65536, rsize)), | 17 : in_fifo_(std::max<size_t>(65536, rsize)), |
| 18 out_fifo_(std::max<size_t>(65536, wsize)) { | 18 out_fifo_(std::max<size_t>(65536, wsize)) { |
| 19 UpdateStatus_Locked(); | |
| 20 } | 19 } |
| 21 | 20 |
| 22 uint32_t EventEmitterTCP::ReadIn_Locked(char* data, uint32_t len) { | 21 uint32_t EventEmitterTCP::ReadIn_Locked(char* data, uint32_t len) { |
| 23 uint32_t count = in_fifo_.Read(data, len); | 22 uint32_t count = in_fifo_.Read(data, len); |
| 24 | 23 |
| 25 UpdateStatus_Locked(); | 24 UpdateStatus_Locked(); |
| 26 return count; | 25 return count; |
| 27 } | 26 } |
| 28 | 27 |
| 29 uint32_t EventEmitterTCP::WriteIn_Locked(const char* data, uint32_t len) { | 28 uint32_t EventEmitterTCP::WriteIn_Locked(const char* data, uint32_t len) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 return count; | 39 return count; |
| 41 } | 40 } |
| 42 | 41 |
| 43 uint32_t EventEmitterTCP::WriteOut_Locked(const char* data, uint32_t len) { | 42 uint32_t EventEmitterTCP::WriteOut_Locked(const char* data, uint32_t len) { |
| 44 uint32_t count = out_fifo_.Write(data, len); | 43 uint32_t count = out_fifo_.Write(data, len); |
| 45 | 44 |
| 46 UpdateStatus_Locked(); | 45 UpdateStatus_Locked(); |
| 47 return count; | 46 return count; |
| 48 } | 47 } |
| 49 | 48 |
| 49 void EventEmitterTCP::ConnectDone_Locked() { |
| 50 RaiseEvents_Locked(POLLOUT); |
| 51 UpdateStatus_Locked(); |
| 52 } |
| 53 |
| 54 void EventEmitterTCP::SetAcceptedSocket_Locked(PP_Resource socket) { |
| 55 accepted_socket_ = socket; |
| 56 RaiseEvents_Locked(POLLIN); |
| 57 } |
| 58 |
| 59 PP_Resource EventEmitterTCP::GetAcceptedSocket_Locked() { |
| 60 int rtn = accepted_socket_; |
| 61 accepted_socket_ = 0; |
| 62 ClearEvents_Locked(POLLIN); |
| 63 return rtn; |
| 64 } |
| 50 | 65 |
| 51 } // namespace nacl_io | 66 } // namespace nacl_io |
| 52 | |
| 53 | |
| OLD | NEW |