Chromium Code Reviews| 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 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.
| |
| 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 | |
|
binji
2013/09/12 01:47:57
nit: remove extra line
noelallen1
2013/09/12 23:19:03
Done.
| |
| 50 int ms = (GetMode() & O_NONBLOCK) ? 0 : write_timeout_; | |
| 51 | |
| 52 EventListenerLock wait(GetEventEmitter()); | |
| 53 Error err = wait.WaitOnEvent(POLLOUT, ms); | |
| 54 if (err) | |
| 55 return err; | |
| 56 | |
| 57 *out_bytes = pipe_->Write_Locked(static_cast<const char *>(buf), count); | |
| 58 return 0; | |
| 59 } | |
| 60 | |
| 61 } // namespace nacl_io | |
| 62 | |
| OLD | NEW |