| 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..ed282ed80df205d194b279a2065866f85ea302e5
|
| --- /dev/null
|
| +++ b/native_client_sdk/src/libraries/nacl_io/mount_node_pipe.cc
|
| @@ -0,0 +1,66 @@
|
| +// 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;
|
| +}
|
| +
|
| +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_;
|
| +
|
| + EventListenerSingle wait;
|
| + sdk_util::AutoUnlock unlock;
|
| +
|
| + Error err = wait.WaitOnLock(GetEventEmitter(), POLLIN, ms, &unlock);
|
| + if (err)
|
| + return err;
|
| +
|
| + *out_bytes = pipe_->Read(static_cast<char *>(buf), count);
|
| + return 0;
|
| +}
|
| +
|
| +Error MountNodePipe::Write(size_t offs,
|
| + const void *buf,
|
| + size_t count,
|
| + int* out_bytes) {
|
| +
|
| + int ms = (GetMode() & O_NONBLOCK) ? 0 : write_timeout_;
|
| + EventListenerSingle wait;
|
| + sdk_util::AutoUnlock unlock;
|
| +
|
| + Error err = wait.WaitOnLock(GetEventEmitter(), POLLOUT, ms, &unlock);
|
| + if (err)
|
| + return err;
|
| +
|
| + *out_bytes = pipe_->Write(static_cast<const char *>(buf), count);
|
| + GetEventEmitter()->GetLock().Unlock();
|
| + return 0;
|
| +}
|
| +
|
| +} // namespace nacl_io
|
| +
|
|
|