• 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_STREAM_STREAM_NODE_H_
6 #define LIBRARIES_NACL_IO_STREAM_STREAM_NODE_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include "nacl_io/node.h"
12 #include "nacl_io/pipe/pipe_event_emitter.h"
13 #include "sdk_util/atomicops.h"
14 
15 namespace nacl_io {
16 
17 class StreamNode;
18 class StreamFs;
19 
20 typedef sdk_util::ScopedRef<StreamNode> ScopedStreamNode;
21 
22 enum StreamStateFlags {
23   SSF_CONNECTING = 0x0001,
24   SSF_SENDING = 0x0002,
25   SSF_RECVING = 0x0004,
26   SSF_CLOSING = 0x0008,
27   SSF_LISTENING = 0x000f,
28   SSF_CAN_SEND = 0x0020,
29   SSF_CAN_RECV = 0x0040,
30   SSF_CAN_ACCEPT = 0x0080,
31   SSF_CAN_CONNECT = 0x00f0,
32   SSF_NON_BLOCK = 0x1000,
33   SSF_ERROR = 0x4000,
34   SSF_CLOSED = 0x8000
35 };
36 
37 class StreamNode : public Node {
38  public:
39   explicit StreamNode(Filesystem* fs);
40 
41   virtual Error Init(int open_flags);
42 
43   // Attempts to pump input and output
44   virtual void QueueInput();
45   virtual void QueueOutput();
46 
47   void SetStreamFlags(uint32_t bits);
48   void ClearStreamFlags(uint32_t bits);
49   uint32_t GetStreamFlags();
50   bool TestStreamFlags(uint32_t bits);
51 
52   StreamFs* stream();
53 
54  protected:
55   int read_timeout_;
56   int write_timeout_;
57 
58  private:
59   sdk_util::Atomic32 stream_state_flags_;
60 };
61 
62 }  // namespace nacl_io
63 
64 #endif  // LIBRARIES_NACL_IO_STREAM_STREAM_NODE_H_
65