Chromium Code Reviews| Index: native_client_sdk/src/libraries/nacl_io/mount_node_pipe.cc |
| diff --git a/native_client_sdk/src/libraries/nacl_io/mount_node_pipe.cc b/native_client_sdk/src/libraries/nacl_io/mount_node_pipe.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a4d9d9387bd09ab15e560556e131387f5977fc57 |
| --- /dev/null |
| +++ b/native_client_sdk/src/libraries/nacl_io/mount_node_pipe.cc |
| @@ -0,0 +1,62 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "nacl_io/mount_node_pipe.h" |
| + |
| +#include <errno.h> |
| +#include <fcntl.h> |
| +#include <pthread.h> |
| +#include <string.h> |
| + |
| +#include "nacl_io/event_emitter_pipe.h" |
| +#include "nacl_io/ioctl.h" |
| + |
| +namespace { |
| + size_t kDefaultPipeSize = 65536 * 8; |
|
binji
2013/09/12 01:47:57
const size_t
binji
2013/09/12 01:47:57
Why this size? Also why written this way -- why no
noelallen1
2013/09/12 23:19:03
Done.
noelallen1
2013/09/12 23:19:03
Done.
|
| +} |
| + |
| +namespace nacl_io { |
| + |
| +MountNodePipe::MountNodePipe(Mount* mnt) |
| + : MountNodeStream(mnt), |
| + pipe_(new EventEmitterPipe(kDefaultPipeSize)) { |
| +} |
| + |
| +EventEmitter* MountNodePipe::GetEventEmitter() { |
| + return pipe_.get(); |
| +} |
| + |
| +Error MountNodePipe::Read(size_t offs, |
| + void *buf, |
| + size_t count, |
| + int* out_bytes) { |
| + int ms = (GetMode() & O_NONBLOCK) ? 0 : read_timeout_; |
| + |
| + EventListenerLock wait(GetEventEmitter()); |
| + Error err = wait.WaitOnEvent(POLLIN, ms); |
| + if (err) |
| + return err; |
| + |
| + *out_bytes = pipe_->Read_Locked(static_cast<char *>(buf), count); |
| + return 0; |
| +} |
| + |
| +Error MountNodePipe::Write(size_t offs, |
| + const void *buf, |
| + size_t count, |
| + int* out_bytes) { |
| + |
|
binji
2013/09/12 01:47:57
nit: remove extra line
noelallen1
2013/09/12 23:19:03
Done.
|
| + int ms = (GetMode() & O_NONBLOCK) ? 0 : write_timeout_; |
| + |
| + EventListenerLock wait(GetEventEmitter()); |
| + Error err = wait.WaitOnEvent(POLLOUT, ms); |
| + if (err) |
| + return err; |
| + |
| + *out_bytes = pipe_->Write_Locked(static_cast<const char *>(buf), count); |
| + return 0; |
| +} |
| + |
| +} // namespace nacl_io |
| + |