return Undefined();
}
- #define ADDRESS_TO_JS(info, address_storage) \
+
+#ifdef __POSIX__
+
+ #define ADDRESS_TO_JS(info, address_storage, addrlen) \
do { \
char ip[INET6_ADDRSTRLEN]; \
int port; \
} \
} while (0)
- #define ADDRESS_TO_JS(info, address_storage) \
+#else // __MINGW32__
+
- switch ((address_storage).ss_family) { \
- case AF_INET6: \
- a6 = (struct sockaddr_in6*)&(address_storage); \
- inet_ntop(AF_INET6, &(a6->sin6_addr), ip, INET6_ADDRSTRLEN); \
- port = ntohs(a6->sin6_port); \
- (info)->Set(address_symbol, String::New(ip)); \
- (info)->Set(port_symbol, Integer::New(port)); \
- break; \
- case AF_INET: \
- a4 = (struct sockaddr_in*)&(address_storage); \
- inet_ntop(AF_INET, &(a4->sin_addr), ip, INET6_ADDRSTRLEN); \
- port = ntohs(a4->sin_port); \
- (info)->Set(address_symbol, String::New(ip)); \
- (info)->Set(port_symbol, Integer::New(port)); \
- break; \
- default: \
- (info)->Set(address_symbol, String::Empty()); \
++#define ADDRESS_TO_JS(info, address_storage, addrlen) \
+do { \
+ char ip[INET6_ADDRSTRLEN]; \
+ int port; \
+ struct sockaddr_in *a4; \
+ struct sockaddr_in6 *a6; \
++ if (addrlen == 0) { \
++ (info)->Set(address_symbol, String::Empty()); \
++ } else { \
++ switch ((address_storage).ss_family) { \
++ case AF_INET6: \
++ a6 = (struct sockaddr_in6*)&(address_storage); \
++ inet_ntop(AF_INET6, &(a6->sin6_addr), ip, INET6_ADDRSTRLEN); \
++ port = ntohs(a6->sin6_port); \
++ (info)->Set(address_symbol, String::New(ip)); \
++ (info)->Set(port_symbol, Integer::New(port)); \
++ break; \
++ case AF_INET: \
++ a4 = (struct sockaddr_in*)&(address_storage); \
++ inet_ntop(AF_INET, &(a4->sin_addr), ip, INET6_ADDRSTRLEN); \
++ port = ntohs(a4->sin_port); \
++ (info)->Set(address_symbol, String::New(ip)); \
++ (info)->Set(port_symbol, Integer::New(port)); \
++ break; \
++ default: \
++ (info)->Set(address_symbol, String::Empty()); \
++ } \
+ } \
+} while (0)
+
+#endif // __MINGW32__
+
+
+#ifdef __POSIX__
static Handle<Value> GetSockName(const Arguments& args) {
HandleScope scope;
if (peer_fd < 0) {
if (errno == EAGAIN) return scope.Close(Null());
+ if (errno == ECONNABORTED) return scope.Close(Null());
return ThrowException(ErrnoException(errno, "accept"));
}
+#else // __MINGW32__
+ int peer_handle = accept(_get_osfhandle(fd), (struct sockaddr*) &address_storage, &len);
+
+ if (peer_handle == INVALID_SOCKET) {
+ int wsaErrno = WSAGetLastError();
+ if (wsaErrno == WSAEWOULDBLOCK) return scope.Close(Null());
+ return ThrowException(ErrnoException(wsaErrno, "accept"));
+ }
+
+ int peer_fd = _open_osfhandle(peer_handle, 0);
+#endif // __MINGW32__
if (!SetSockFlags(peer_fd)) {
+#ifdef __POSIX__
int fcntl_errno = errno;
+#else // __MINGW32__
+ int fcntl_errno = WSAGetLastError();
+#endif // __MINGW32__
close(peer_fd);
return ThrowException(ErrnoException(fcntl_errno, "fcntl"));
}