• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef LIBRARIES_NACL_IO_SOCKET_TCP_EVENT_EMITTER_H_
6 #define LIBRARIES_NACL_IO_SOCKET_TCP_EVENT_EMITTER_H_
7 
8 #include "nacl_io/fifo_char.h"
9 #include "nacl_io/stream/stream_event_emitter.h"
10 
11 #include <ppapi/c/pp_resource.h>
12 
13 #include "sdk_util/macros.h"
14 #include "sdk_util/scoped_ref.h"
15 
16 namespace nacl_io {
17 
18 class TcpEventEmitter;
19 class Node;
20 
21 typedef sdk_util::ScopedRef<TcpEventEmitter> ScopedTcpEventEmitter;
22 
23 class TcpEventEmitter : public StreamEventEmitter {
24  public:
25   TcpEventEmitter(size_t rsize, size_t wsize);
26 
27   uint32_t ReadIn_Locked(char* buffer, uint32_t len);
28   uint32_t WriteIn_Locked(const char* buffer, uint32_t len);
29 
30   uint32_t ReadOut_Locked(char* buffer, uint32_t len);
31   uint32_t WriteOut_Locked(const char* buffer, uint32_t len);
32 
33   bool GetError_Locked();
34   void SetError_Locked();
35   void ConnectDone_Locked();
36   PP_Resource GetAcceptedSocket_Locked();
37   void SetAcceptedSocket_Locked(PP_Resource socket);
38   void UpdateStatus_Locked();
39   void SetListening_Locked();
40 
41   uint32_t BytesInOutputFIFO();
42   uint32_t SpaceInInputFIFO();
43 
44  protected:
in_fifo()45   virtual FIFOChar* in_fifo() { return &in_fifo_; }
out_fifo()46   virtual FIFOChar* out_fifo() { return &out_fifo_; }
47 
48  private:
49   FIFOChar in_fifo_;
50   FIFOChar out_fifo_;
51   bool error_;
52   bool listening_;
53   PP_Resource accepted_socket_;
54   DISALLOW_COPY_AND_ASSIGN(TcpEventEmitter);
55 };
56 
57 }  // namespace nacl_io
58 
59 #endif  // LIBRARIES_NACL_IO_SOCKET_TCP_EVENT_EMITTER_H_
60