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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/mount_node_pipe.cc

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge emitter changes Created 7 years, 3 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
(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;
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 EventListenerSingle wait;
37 sdk_util::AutoUnlock unlock;
38
39 Error err = wait.WaitOnLock(GetEventEmitter(), POLLIN, ms, &unlock);
40 if (err)
41 return err;
42
43 *out_bytes = pipe_->Read(static_cast<char *>(buf), count);
44 return 0;
45 }
46
47 Error MountNodePipe::Write(size_t offs,
48 const void *buf,
49 size_t count,
50 int* out_bytes) {
51
52 int ms = (GetMode() & O_NONBLOCK) ? 0 : write_timeout_;
53 EventListenerSingle wait;
54 sdk_util::AutoUnlock unlock;
55
56 Error err = wait.WaitOnLock(GetEventEmitter(), POLLOUT, ms, &unlock);
57 if (err)
58 return err;
59
60 *out_bytes = pipe_->Write(static_cast<const char *>(buf), count);
61 GetEventEmitter()->GetLock().Unlock();
62 return 0;
63 }
64
65 } // namespace nacl_io
66
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698