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#include "nacl_io/stream/stream_node.h"
6
7#include <errno.h>
8#include <fcntl.h>
9#include <pthread.h>
10#include <string.h>
11
12#include "nacl_io/ioctl.h"
13#include "nacl_io/stream/stream_fs.h"
14#include "sdk_util/atomicops.h"
15
16namespace nacl_io {
17
18StreamNode::StreamNode(Filesystem* fs)
19    : Node(fs), read_timeout_(-1), write_timeout_(-1), stream_state_flags_(0) {
20}
21
22Error StreamNode::Init(int open_flags) {
23  Node::Init(open_flags);
24  if (open_flags & O_NONBLOCK)
25    SetStreamFlags(SSF_NON_BLOCK);
26
27  return 0;
28}
29
30void StreamNode::SetStreamFlags(uint32_t bits) {
31  sdk_util::AtomicOrFetch(&stream_state_flags_, bits);
32}
33
34void StreamNode::ClearStreamFlags(uint32_t bits) {
35  sdk_util::AtomicAndFetch(&stream_state_flags_, ~bits);
36}
37
38uint32_t StreamNode::GetStreamFlags() {
39  return stream_state_flags_;
40}
41
42bool StreamNode::TestStreamFlags(uint32_t bits) {
43  return (stream_state_flags_ & bits) == bits;
44}
45
46void StreamNode::QueueInput() {
47}
48void StreamNode::QueueOutput() {
49}
50
51StreamFs* StreamNode::stream() {
52  return static_cast<StreamFs*>(filesystem_);
53}
54
55}  // namespace nacl_io
56