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

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

Issue 1335783005: [NaCl SDK] nacl_io: Add support for basic socketpairs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/library.dsc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b554ade35226994cee50d28578dfc2fba3e156db..a141923de0dec3ada5f6a2b3a7d9d10a07a9e908 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc
@@ -39,6 +39,7 @@
#include "nacl_io/pipe/pipe_node.h"
#include "nacl_io/socket/tcp_node.h"
#include "nacl_io/socket/udp_node.h"
+#include "nacl_io/socket/unix_node.h"
#include "nacl_io/stream/stream_fs.h"
#include "nacl_io/typed_fs_factory.h"
#include "sdk_util/auto_lock.h"
@@ -1813,21 +1814,73 @@ int KernelProxy::socketpair(int domain, int type, int protocol, int* sv) {
return -1;
}
- // Catch-22: We don't support AF_UNIX, but any other AF doesn't support
- // socket pairs. Thus, this function always fails.
- if (AF_UNIX != domain) {
- errno = EPROTONOSUPPORT;
+ if (AF_INET == domain || AF_INET6 == domain) {
+ errno = EOPNOTSUPP;
return -1;
}
- if (AF_INET != domain && AF_INET6 != domain) {
+ if (AF_UNIX != domain) {
errno = EAFNOSUPPORT;
return -1;
}
- // We cannot reach this point.
- errno = ENOSYS;
- return -1;
+ if (SOCK_STREAM != type) {
+ errno = EPROTOTYPE;
+ return -1;
+ }
+
+ int open_flags = O_RDWR;
+
+#if defined(SOCK_CLOEXEC)
+ if (type & SOCK_CLOEXEC) {
+#if defined(O_CLOEXEC)
+ // The NaCl newlib version of fcntl.h doesn't currently define
+ // O_CLOEXEC.
+ // TODO(sbc): remove this guard once it gets added.
+ open_flags |= O_CLOEXEC;
+#endif
+ type &= ~SOCK_CLOEXEC;
+ }
+#endif
+
+#if defined(SOCK_NONBLOCK)
+ if (type & SOCK_NONBLOCK) {
+ open_flags |= O_NONBLOCK;
+ type &= ~SOCK_NONBLOCK;
+ }
+#endif
+
+ UnixNode* socket = new UnixNode(stream_fs_.get());
+ Error rtn = socket->Init(O_RDWR);
+ if (rtn != 0) {
+ errno = rtn;
+ return -1;
+ }
+ ScopedNode node0(socket);
+ socket = new UnixNode(stream_fs_.get(), *socket);
+ rtn = socket->Init(O_RDWR);
+ if (rtn != 0) {
+ errno = rtn;
+ return -1;
+ }
+ ScopedNode node1(socket);
+ ScopedKernelHandle handle0(new KernelHandle(stream_fs_, node0));
+ rtn = handle0->Init(open_flags);
+ if (rtn != 0) {
+ errno = rtn;
+ return -1;
+ }
+ ScopedKernelHandle handle1(new KernelHandle(stream_fs_, node1));
+ rtn = handle1->Init(open_flags);
+ if (rtn != 0) {
+ errno = rtn;
+ return -1;
+ }
+
+ sv[0] = AllocateFD(handle0);
+ sv[1] = AllocateFD(handle1);
+
+ return 0;
}
int KernelProxy::AcquireSocketHandle(int fd, ScopedKernelHandle* handle) {
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/library.dsc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698