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

Unified Diff: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc

Issue 22587003: [NaCl SDK] Add UDP and TCP Sockets (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Running tests on package Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
index a64a80013c6cb0457685c1fa0f08321fa4c1ad1a..eaefd12a4f6a449032b0b994da235885f0cca876 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
@@ -27,6 +27,8 @@
#include "nacl_io/mount_http.h"
#include "nacl_io/mount_mem.h"
#include "nacl_io/mount_node.h"
+#include "nacl_io/mount_node_tcp.h"
+#include "nacl_io/mount_node_udp.h"
#include "nacl_io/mount_passthrough.h"
#include "nacl_io/osmman.h"
#include "nacl_io/ossocket.h"
@@ -82,6 +84,10 @@ void KernelProxy::Init(PepperInterface* ppapi) {
#ifdef PROVIDES_SOCKET_API
host_resolver_.Init(ppapi_);
#endif
+
+ StringMap_t args;
+ socket_mount_.reset(new MountSocket());
+ socket_mount_->Init(0, args, ppapi);
}
int KernelProxy::open_resource(const char* path) {
@@ -907,8 +913,16 @@ int KernelProxy::bind(int fd, const struct sockaddr* addr, socklen_t len) {
if (AcquireSocketHandle(fd, &handle) == -1)
binji 2013/08/09 19:28:06 no errno set if the handle cannot be acquired? (h
noelallen1 2013/08/09 22:53:22 Set by acquire socket handle. The convention is
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
binji 2013/08/09 19:28:06 Why reinterpret_cast? If this is a downcast you ca
noelallen1 2013/08/09 22:53:22 Done.
+
+ Error err = sock->Bind(addr, len);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return 0;
}
int KernelProxy::connect(int fd, const struct sockaddr* addr, socklen_t len) {
@@ -921,8 +935,16 @@ int KernelProxy::connect(int fd, const struct sockaddr* addr, socklen_t len) {
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EACCES;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ Error err = sock->Connect(addr, len);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return 0;
}
struct hostent* KernelProxy::gethostbyname(const char* name) {
@@ -939,8 +961,16 @@ int KernelProxy::getpeername(int fd, struct sockaddr* addr, socklen_t* len) {
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ Error err = sock->GetPeerName(addr, len);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return 0;
}
int KernelProxy::getsockname(int fd, struct sockaddr* addr, socklen_t* len) {
@@ -953,8 +983,16 @@ int KernelProxy::getsockname(int fd, struct sockaddr* addr, socklen_t* len) {
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ Error err = sock->GetPeerName(addr, len);
binji 2013/08/09 19:28:06 GetSockName?
noelallen1 2013/08/09 22:53:22 Done.
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return 0;
}
int KernelProxy::getsockopt(int fd,
@@ -1005,8 +1043,17 @@ ssize_t KernelProxy::recv(int fd,
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ int out_len = 0;
+ Error err = sock->Recv(buf, len, flags, &out_len);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return static_cast<ssize_t>(out_len);
}
ssize_t KernelProxy::recvfrom(int fd,
@@ -1029,8 +1076,17 @@ ssize_t KernelProxy::recvfrom(int fd,
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ int out_len = 0;
+ Error err = sock->RecvFrom(buf, len, flags, addr, addrlen, &out_len);
binji 2013/08/09 19:28:06 why not make the RecvFrom out parameter ssize_t he
noelallen1 2013/08/09 22:53:22 it should match Read. Read(x, y, z) = Recv(x, y,
binji 2013/08/09 23:08:27 OK
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return static_cast<ssize_t>(out_len);
}
ssize_t KernelProxy::recvmsg(int fd, struct msghdr* msg, int flags) {
@@ -1057,8 +1113,17 @@ ssize_t KernelProxy::send(int fd, const void* buf, size_t len, int flags) {
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ int out_len = 0;
+ Error err = sock->Send(buf, len, flags, &out_len);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return static_cast<ssize_t>(out_len);
}
ssize_t KernelProxy::sendto(int fd,
@@ -1081,8 +1146,17 @@ ssize_t KernelProxy::sendto(int fd,
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ int out_len = 0;
+ Error err = sock->SendTo(buf, len, flags, addr, addrlen, &out_len);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return static_cast<ssize_t>(out_len);
}
ssize_t KernelProxy::sendmsg(int fd, const struct msghdr* msg, int flags) {
@@ -1122,8 +1196,16 @@ int KernelProxy::shutdown(int fd, int how) {
if (AcquireSocketHandle(fd, &handle) == -1)
return -1;
- errno = EINVAL;
- return -1;
+ MountNodeSocket* sock =
+ reinterpret_cast<MountNodeSocket*>(handle->node().get());
+
+ Error err = sock->Shutdown(how);
+ if (err != 0) {
+ errno = err;
+ return -1;
+ }
+
+ return 0;
}
int KernelProxy::socket(int domain, int type, int protocol) {
@@ -1132,12 +1214,30 @@ int KernelProxy::socket(int domain, int type, int protocol) {
return -1;
}
- if (SOCK_STREAM != type && SOCK_DGRAM != type) {
- errno = EPROTONOSUPPORT;
+ if (SOCK_DGRAM == type) {
+ MountNodeSocket* sock = new MountNodeUDP(socket_mount_.get());
+ ScopedMountNode node(sock);
+
+ if (sock->Init(S_IREAD | S_IWRITE) == 0) {
+ ScopedKernelHandle handle(new KernelHandle(socket_mount_, node));
+ return AllocateFD(handle);
+ }
+
+ errno = EACCES;
return -1;
}
- errno = EACCES;
+ if (SOCK_STREAM == type) {
+ MountNodeSocket* sock = new MountNodeTCP(socket_mount_.get());
+ ScopedMountNode node(sock);
+
+ if (sock->Init(S_IREAD | S_IWRITE) == 0) {
binji 2013/08/09 19:28:06 Init part here and above is identical, can you com
noelallen1 2013/08/09 22:53:22 Done.
+ ScopedKernelHandle handle(new KernelHandle(socket_mount_, node));
+ return AllocateFD(handle);
+ }
+ }
binji 2013/08/09 19:28:06 EACCES here too if sock->Init fails?
noelallen1 2013/08/09 22:53:22 Done.
+
+ errno = EPROTONOSUPPORT;
return -1;
}

Powered by Google App Engine
This is Rietveld 408576698