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
3 // found in the LICENSE file.
5 #include "nacl_io/socket/tcp_event_emitter.h"
11 #include "nacl_io/fifo_char.h"
12 #include "sdk_util/auto_lock.h"
16 TcpEventEmitter::TcpEventEmitter(size_t rsize
, size_t wsize
)
21 recv_endofstream_(false),
25 uint32_t TcpEventEmitter::ReadIn_Locked(char* data
, uint32_t len
) {
26 uint32_t count
= in_fifo_
.Read(data
, len
);
27 UpdateStatus_Locked();
31 void TcpEventEmitter::UpdateStatus_Locked() {
33 RaiseEvents_Locked(POLLIN
| POLLOUT
);
37 if (recv_endofstream_
) {
38 RaiseEvents_Locked(POLLIN
);
44 RaiseEvents_Locked(POLLIN
);
48 StreamEventEmitter::UpdateStatus_Locked();
51 void TcpEventEmitter::SetListening_Locked() {
53 UpdateStatus_Locked();
56 uint32_t TcpEventEmitter::WriteIn_Locked(const char* data
, uint32_t len
) {
57 uint32_t count
= in_fifo_
.Write(data
, len
);
59 UpdateStatus_Locked();
63 uint32_t TcpEventEmitter::ReadOut_Locked(char* data
, uint32_t len
) {
64 uint32_t count
= out_fifo_
.Read(data
, len
);
66 UpdateStatus_Locked();
70 uint32_t TcpEventEmitter::WriteOut_Locked(const char* data
, uint32_t len
) {
71 uint32_t count
= out_fifo_
.Write(data
, len
);
73 UpdateStatus_Locked();
77 void TcpEventEmitter::ConnectDone_Locked() {
78 RaiseEvents_Locked(POLLOUT
);
79 UpdateStatus_Locked();
82 bool TcpEventEmitter::GetError_Locked() {
86 void TcpEventEmitter::SetError_Locked() {
88 UpdateStatus_Locked();
91 void TcpEventEmitter::SetAcceptedSocket_Locked(PP_Resource socket
) {
92 accepted_socket_
= socket
;
93 UpdateStatus_Locked();
96 PP_Resource
TcpEventEmitter::GetAcceptedSocket_Locked() {
97 int rtn
= accepted_socket_
;
99 UpdateStatus_Locked();
103 void TcpEventEmitter::SetRecvEndOfStream_Locked() {
104 recv_endofstream_
= true;
105 UpdateStatus_Locked();
108 uint32_t TcpEventEmitter::BytesInOutputFIFO() {
109 return out_fifo()->ReadAvailable();
112 uint32_t TcpEventEmitter::SpaceInInputFIFO() {
113 return in_fifo()->WriteAvailable();
116 } // namespace nacl_io