This source file includes following definitions.
- Write
- VIoctl
#include "nacl_io/devfs/jspipe_node.h"
#include <cstring>
#include "nacl_io/devfs/dev_fs.h"
#include "nacl_io/error.h"
#include "nacl_io/ioctl.h"
#include "nacl_io/kernel_handle.h"
#include "nacl_io/pepper_interface.h"
namespace nacl_io {
#define MAX_MESSAGE_SIZE (64*1024)
Error JSPipeNode::Write(const HandleAttr& attr,
const void* buf,
size_t count,
int* out_bytes) {
PepperInterface* ppapi = filesystem_->ppapi();
MessagingInterface* iface = ppapi->GetMessagingInterface();
VarInterface* var_iface = ppapi->GetVarInterface();
VarArrayInterface* array_iface = ppapi->GetVarArrayInterface();
VarArrayBufferInterface* buffer_iface = ppapi->GetVarArrayBufferInterface();
if (!iface || !var_iface || !array_iface || !buffer_iface)
return ENOSYS;
if (name_.empty())
return EIO;
if (count > MAX_MESSAGE_SIZE)
count = MAX_MESSAGE_SIZE;
PP_Var buffer = buffer_iface->Create(count);
memcpy(buffer_iface->Map(buffer), buf, count);
buffer_iface->Unmap(buffer);
PP_Var string = var_iface->VarFromUtf8(name_.c_str(), name_.size());
PP_Var array = array_iface->Create();
array_iface->Set(array, 0, string);
array_iface->Set(array, 1, buffer);
var_iface->Release(string);
var_iface->Release(buffer);
iface->PostMessage(ppapi->GetInstance(), array);
var_iface->Release(array);
*out_bytes = count;
return 0;
}
Error JSPipeNode::VIoctl(int request, va_list args) {
switch (request) {
case TIOCNACLPIPENAME: {
if (!name_.empty())
return EIO;
const char* new_name = va_arg(args, char*);
if (!new_name || strlen(new_name) == 0)
return EIO;
name_ = new_name;
return 0;
}
case TIOCNACLINPUT: {
struct tioc_nacl_input_string* message =
va_arg(args, struct tioc_nacl_input_string*);
const char* buffer = message->buffer;
int num_bytes = message->length;
int wrote = 0;
HandleAttr data;
int error = PipeNode::Write(data, buffer, num_bytes, &wrote);
if (error || wrote != num_bytes)
return EIO;
return 0;
}
}
return EINVAL;
}
}