1 // Copyright 2014 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.
5 #include "nacl_io/devfs/jspipe_node.h"
9 #include "nacl_io/devfs/dev_fs.h"
10 #include "nacl_io/error.h"
11 #include "nacl_io/ioctl.h"
12 #include "nacl_io/kernel_handle.h"
13 #include "nacl_io/log.h"
14 #include "nacl_io/pepper_interface.h"
16 #define TRACE(format, ...) LOG_TRACE("jspipe: " format, ##__VA_ARGS__)
17 #define ERROR(format, ...) LOG_TRACE("jspipe: " format, ##__VA_ARGS__)
20 const size_t kPostMessageBufferSize
= 512 * 1024;
25 JSPipeNode::JSPipeNode(Filesystem
* filesystem
)
27 pipe_(new JSPipeEventEmitter(filesystem_
->ppapi(),
28 kPostMessageBufferSize
)) {
31 JSPipeEventEmitter
* JSPipeNode::GetEventEmitter() {
35 Error
JSPipeNode::Read(const HandleAttr
& attr
,
39 int ms
= attr
.IsBlocking() ? -1 : 0;
41 EventListenerLock
wait(GetEventEmitter());
42 Error err
= wait
.WaitOnEvent(POLLIN
, ms
);
48 return GetEventEmitter()->Read_Locked(static_cast<char*>(buf
), count
,
52 Error
JSPipeNode::Write(const HandleAttr
& attr
,
56 int ms
= attr
.IsBlocking() ? -1 : 0;
57 TRACE("write timeout=%d", ms
);
59 EventListenerLock
wait(GetEventEmitter());
60 Error err
= wait
.WaitOnEvent(POLLOUT
, ms
);
66 return GetEventEmitter()->Write_Locked(static_cast<const char*>(buf
),
70 Error
JSPipeNode::VIoctl(int request
, va_list args
) {
71 AUTO_LOCK(node_lock_
);
74 case NACL_IOC_PIPE_SETNAME
: {
75 const char* new_name
= va_arg(args
, char*);
76 return GetEventEmitter()->SetName(new_name
);
78 case NACL_IOC_PIPE_GETISPACE
: {
79 int* space
= va_arg(args
, int*);
80 *space
= GetEventEmitter()->GetISpace();
83 case NACL_IOC_PIPE_GETOSPACE
: {
84 int* space
= va_arg(args
, int*);
85 *space
= GetEventEmitter()->GetOSpace();
88 case NACL_IOC_HANDLEMESSAGE
: {
89 struct PP_Var
* message
= va_arg(args
, struct PP_Var
*);
90 return GetEventEmitter()->HandleJSMessage(*message
);
93 TRACE("unknown ioctl: %#x", request
);
100 } // namespace nacl_io