Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nacl_io/pipe/pipe_node.h" | 5 #include "nacl_io/pipe/pipe_node.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include "nacl_io/ioctl.h" | 12 #include "nacl_io/ioctl.h" |
| 13 #include "nacl_io/kernel_handle.h" | 13 #include "nacl_io/kernel_handle.h" |
| 14 #include "nacl_io/pipe/pipe_event_emitter.h" | 14 #include "nacl_io/pipe/pipe_event_emitter.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 const size_t kDefaultPipeSize = 512 * 1024; | 17 const size_t kDefaultPipeSize = 512 * 1024; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace nacl_io { | 20 namespace nacl_io { |
| 21 | 21 |
| 22 PipeNode::PipeNode(Filesystem* fs) | 22 PipeNode::PipeNode(Filesystem* fs) |
| 23 : StreamNode(fs), pipe_(new PipeEventEmitter(kDefaultPipeSize)) {} | 23 : StreamNode(fs), pipe_(new PipeEventEmitter(kDefaultPipeSize)) { |
| 24 } | |
| 24 | 25 |
| 25 EventEmitter* PipeNode::GetEventEmitter() { return pipe_.get(); } | 26 PipeEventEmitter* PipeNode::GetEventEmitter() { |
| 27 return pipe_.get(); | |
| 28 } | |
| 26 | 29 |
| 27 Error PipeNode::Read(const HandleAttr& attr, | 30 Error PipeNode::Read(const HandleAttr& attr, |
| 28 void* buf, | 31 void* buf, |
| 29 size_t count, | 32 size_t count, |
| 30 int* out_bytes) { | 33 int* out_bytes) { |
| 31 int ms = attr.IsBlocking() ? read_timeout_ : 0; | 34 int ms = attr.IsBlocking() ? read_timeout_ : 0; |
| 32 | 35 |
| 33 EventListenerLock wait(GetEventEmitter()); | 36 EventListenerLock wait(GetEventEmitter()); |
| 34 Error err = wait.WaitOnEvent(POLLIN, ms); | 37 Error err = wait.WaitOnEvent(POLLIN, ms); |
| 38 if (err == ETIMEDOUT) | |
|
binji
2014/05/01 20:22:31
Do we want to do this everywhere?
If not, it stil
Sam Clegg
2014/05/01 22:16:55
There may be test code that expects otherwise but
| |
| 39 err = EWOULDBLOCK; | |
| 35 if (err) | 40 if (err) |
| 36 return err; | 41 return err; |
| 37 | 42 |
| 38 *out_bytes = pipe_->Read_Locked(static_cast<char*>(buf), count); | 43 *out_bytes = GetEventEmitter()->Read_Locked(static_cast<char*>(buf), count); |
| 39 return 0; | 44 return 0; |
| 40 } | 45 } |
| 41 | 46 |
| 42 Error PipeNode::Write(const HandleAttr& attr, | 47 Error PipeNode::Write(const HandleAttr& attr, |
| 43 const void* buf, | 48 const void* buf, |
| 44 size_t count, | 49 size_t count, |
| 45 int* out_bytes) { | 50 int* out_bytes) { |
| 46 int ms = attr.IsBlocking() ? write_timeout_ : 0; | 51 int ms = attr.IsBlocking() ? write_timeout_ : 0; |
| 47 | 52 |
| 48 EventListenerLock wait(GetEventEmitter()); | 53 EventListenerLock wait(GetEventEmitter()); |
| 49 Error err = wait.WaitOnEvent(POLLOUT, ms); | 54 Error err = wait.WaitOnEvent(POLLOUT, ms); |
| 55 if (err == ETIMEDOUT) | |
| 56 err = EWOULDBLOCK; | |
| 50 if (err) | 57 if (err) |
| 51 return err; | 58 return err; |
| 52 | 59 |
| 53 *out_bytes = pipe_->Write_Locked(static_cast<const char*>(buf), count); | 60 *out_bytes = GetEventEmitter()->Write_Locked(static_cast<const char*>(buf), |
| 61 count); | |
| 54 return 0; | 62 return 0; |
| 55 } | 63 } |
| 56 | 64 |
| 57 } // namespace nacl_io | 65 } // namespace nacl_io |
| OLD | NEW |