Add a couple more things to the socket portability layer
authorChristopher Dykes <cdykes@fb.com>
Thu, 4 Aug 2016 22:44:27 +0000 (15:44 -0700)
committerFacebook Github Bot 8 <facebook-github-bot-8-bot@fb.com>
Thu, 4 Aug 2016 22:54:26 +0000 (15:54 -0700)
Summary: To make it possible for things to actually compile, this adds `socketpair` and the `sockaddr_un` struct, and also removes the `FOLLY_HAVE_UNIX_SOCKETS` define, as it is no longer needed.

Reviewed By: yfeldblum

Differential Revision: D3671158

fbshipit-source-id: 7333470f2e85c24edb935be5e1b94b4edc6e7267

folly/portability/Sockets.cpp
folly/portability/Sockets.h

index d96091cb51fa8d62f9f676e9e645dca891e6b3be..928573d3bd3873c235990fb33b52427fb8cd67e3 100755 (executable)
@@ -307,6 +307,11 @@ int shutdown(int s, int how) {
 int socket(int af, int type, int protocol) {
   return socket_to_fd(::socket(af, type, protocol));
 }
+
+int socketpair(int domain, int type, int protocol, int sv[2]) {
+  // Stub this out for now, to get things compiling.
+  return -1;
+}
 }
 }
 }
index de0db0ace4b66fbce5d0ad4381093673509742dc..dcabc13f7610159e25ca186f2a43fe7449ce366c 100755 (executable)
 
 #pragma once
 
-#ifdef _WIN32
-#define FOLLY_HAVE_UNIX_SOCKETS 0
-#else
-#define FOLLY_HAVE_UNIX_SOCKETS 1
-#endif
-
 #ifndef _WIN32
 #include <netdb.h>
 #include <poll.h>
@@ -38,6 +32,9 @@
 
 #include <WS2tcpip.h>
 
+using nfds_t = int;
+using sa_family_t = ADDRESS_FAMILY;
+
 // We don't actually support either of these flags
 // currently.
 #define MSG_DONTWAIT 1
@@ -52,14 +49,19 @@ struct msghdr {
   int msg_flags;
 };
 
+struct sockaddr_un {
+  sa_family_t sun_family;
+  char sun_path[108];
+};
+
 #define SHUT_RD SD_RECEIVE
 #define SHUT_WR SD_SEND
 #define SHUT_RDWR SD_BOTH
 
-using nfds_t = int;
+// These are the same, but PF_LOCAL
+// isn't defined by WinSock.
+#define PF_LOCAL PF_UNIX
 
-// This is named differently in posix.
-#define sa_family_t ADDRESS_FAMILY
 // Someone thought it would be a good idea
 // to define a field via a macro...
 #undef s_host
@@ -96,6 +98,7 @@ int socket_to_fd(SOCKET s);
 // implement.
 int accept(int s, struct sockaddr* addr, socklen_t* addrlen);
 int inet_aton(const char* cp, struct in_addr* inp);
+int socketpair(int domain, int type, int protocol, int sv[2]);
 
 // Unless you have a case where you would normally have
 // to reference the function as being explicitly in the