Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/pipe/pipe_node.cc

Issue 242533005: [NaCl SDK] nacl_io: Add flow control the JavaScript pipes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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)
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 return GetEventEmitter()->Read_Locked(static_cast<char*>(buf), count,
39 return 0; 44 out_bytes);
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 return GetEventEmitter()->Write_Locked(static_cast<const char*>(buf),
54 return 0; 61 count, out_bytes);
55 } 62 }
56 63
57 } // namespace nacl_io 64 } // namespace nacl_io
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/pipe/pipe_node.h ('k') | native_client_sdk/src/libraries/nacl_io/typed_fs_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698