| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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/mount_node_pipe.h" |
| 6 |
| 7 #include <errno.h> |
| 8 #include <fcntl.h> |
| 9 #include <pthread.h> |
| 10 #include <string.h> |
| 11 |
| 12 #include "nacl_io/event_emitter_pipe.h" |
| 13 #include "nacl_io/ioctl.h" |
| 14 |
| 15 namespace { |
| 16 const size_t kDefaultPipeSize = 512 * 1024; |
| 17 } |
| 18 |
| 19 namespace nacl_io { |
| 20 |
| 21 MountNodePipe::MountNodePipe(Mount* mnt) |
| 22 : MountNodeStream(mnt), |
| 23 pipe_(new EventEmitterPipe(kDefaultPipeSize)) { |
| 24 } |
| 25 |
| 26 EventEmitter* MountNodePipe::GetEventEmitter() { |
| 27 return pipe_.get(); |
| 28 } |
| 29 |
| 30 Error MountNodePipe::Read(size_t offs, |
| 31 void *buf, |
| 32 size_t count, |
| 33 int* out_bytes) { |
| 34 int ms = (GetMode() & O_NONBLOCK) ? 0 : read_timeout_; |
| 35 |
| 36 EventListenerLock wait(GetEventEmitter()); |
| 37 Error err = wait.WaitOnEvent(POLLIN, ms); |
| 38 if (err) |
| 39 return err; |
| 40 |
| 41 *out_bytes = pipe_->Read_Locked(static_cast<char *>(buf), count); |
| 42 return 0; |
| 43 } |
| 44 |
| 45 Error MountNodePipe::Write(size_t offs, |
| 46 const void *buf, |
| 47 size_t count, |
| 48 int* out_bytes) { |
| 49 int ms = (GetMode() & O_NONBLOCK) ? 0 : write_timeout_; |
| 50 |
| 51 EventListenerLock wait(GetEventEmitter()); |
| 52 Error err = wait.WaitOnEvent(POLLOUT, ms); |
| 53 if (err) |
| 54 return err; |
| 55 |
| 56 *out_bytes = pipe_->Write_Locked(static_cast<const char *>(buf), count); |
| 57 return 0; |
| 58 } |
| 59 |
| 60 } // namespace nacl_io |
| 61 |
| OLD | NEW |