mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-02-07 11:50:13 +00:00
TCP connections work on Windows now.
This commit is contained in:
parent
9c68a343f6
commit
e8b613e625
@ -364,10 +364,6 @@ bool SocketManager::send(const InetAddress &to,bool tcp,const void *msg,unsigned
|
|||||||
SOCKET s = ::socket(to.isV4() ? AF_INET : AF_INET6,SOCK_STREAM,0);
|
SOCKET s = ::socket(to.isV4() ? AF_INET : AF_INET6,SOCK_STREAM,0);
|
||||||
if (s == INVALID_SOCKET)
|
if (s == INVALID_SOCKET)
|
||||||
return false;
|
return false;
|
||||||
if (s >= FD_SETSIZE) {
|
|
||||||
::closesocket(s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{ u_long iMode=1; ioctlsocket(s,FIONBIO,&iMode); }
|
{ u_long iMode=1; ioctlsocket(s,FIONBIO,&iMode); }
|
||||||
#ifdef ZT_TCP_NODELAY
|
#ifdef ZT_TCP_NODELAY
|
||||||
{ BOOL f = TRUE; setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&f,sizeof(f)); }
|
{ BOOL f = TRUE; setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&f,sizeof(f)); }
|
||||||
@ -387,8 +383,12 @@ bool SocketManager::send(const InetAddress &to,bool tcp,const void *msg,unsigned
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool connecting = false;
|
bool connecting = false;
|
||||||
if (connect(s,to.saddr(),to.saddrLen())) {
|
if (::connect(s,to.saddr(),to.saddrLen())) {
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
if (WSAGetLastError() != WSAEWOULDBLOCK) {
|
||||||
|
#else
|
||||||
if (errno != EINPROGRESS) {
|
if (errno != EINPROGRESS) {
|
||||||
|
#endif
|
||||||
CLOSE_SOCKET(s);
|
CLOSE_SOCKET(s);
|
||||||
return false;
|
return false;
|
||||||
} else connecting = true;
|
} else connecting = true;
|
||||||
@ -480,8 +480,8 @@ void SocketManager::poll(unsigned long timeout)
|
|||||||
if (sockfd != INVALID_SOCKET) {
|
if (sockfd != INVALID_SOCKET) {
|
||||||
#else
|
#else
|
||||||
if (sockfd > 0) {
|
if (sockfd > 0) {
|
||||||
#endif
|
|
||||||
if (sockfd < FD_SETSIZE) {
|
if (sockfd < FD_SETSIZE) {
|
||||||
|
#endif
|
||||||
InetAddress fromia((const struct sockaddr *)&from);
|
InetAddress fromia((const struct sockaddr *)&from);
|
||||||
Mutex::Lock _l2(_tcpSockets_m);
|
Mutex::Lock _l2(_tcpSockets_m);
|
||||||
try {
|
try {
|
||||||
@ -505,9 +505,11 @@ void SocketManager::poll(unsigned long timeout)
|
|||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
CLOSE_SOCKET(sockfd);
|
CLOSE_SOCKET(sockfd);
|
||||||
}
|
}
|
||||||
|
#ifndef __WINDOWS__
|
||||||
} else {
|
} else {
|
||||||
CLOSE_SOCKET(sockfd);
|
CLOSE_SOCKET(sockfd);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((_tcpV6ListenSocket != INVALID_SOCKET)&&(FD_ISSET(_tcpV6ListenSocket,&rfds))) {
|
if ((_tcpV6ListenSocket != INVALID_SOCKET)&&(FD_ISSET(_tcpV6ListenSocket,&rfds))) {
|
||||||
@ -518,8 +520,8 @@ void SocketManager::poll(unsigned long timeout)
|
|||||||
if (sockfd != INVALID_SOCKET) {
|
if (sockfd != INVALID_SOCKET) {
|
||||||
#else
|
#else
|
||||||
if (sockfd > 0) {
|
if (sockfd > 0) {
|
||||||
#endif
|
|
||||||
if (sockfd < FD_SETSIZE) {
|
if (sockfd < FD_SETSIZE) {
|
||||||
|
#endif
|
||||||
InetAddress fromia((const struct sockaddr *)&from);
|
InetAddress fromia((const struct sockaddr *)&from);
|
||||||
Mutex::Lock _l2(_tcpSockets_m);
|
Mutex::Lock _l2(_tcpSockets_m);
|
||||||
try {
|
try {
|
||||||
@ -543,9 +545,11 @@ void SocketManager::poll(unsigned long timeout)
|
|||||||
} catch ( ... ) {
|
} catch ( ... ) {
|
||||||
CLOSE_SOCKET(sockfd);
|
CLOSE_SOCKET(sockfd);
|
||||||
}
|
}
|
||||||
|
#ifndef __WINDOWS__
|
||||||
} else {
|
} else {
|
||||||
CLOSE_SOCKET(sockfd);
|
CLOSE_SOCKET(sockfd);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,6 +164,16 @@ bool TcpSocket::notifyAvailableForWrite(const SharedPtr<Socket> &self,SocketMana
|
|||||||
|
|
||||||
if (_outptr) {
|
if (_outptr) {
|
||||||
int n = (int)::send(_sock,(const char *)_outbuf,_outptr,0);
|
int n = (int)::send(_sock,(const char *)_outbuf,_outptr,0);
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
if (n == SOCKET_ERROR) {
|
||||||
|
switch(WSAGetLastError()) {
|
||||||
|
case WSAEINTR:
|
||||||
|
case WSAEWOULDBLOCK:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
switch(errno) {
|
switch(errno) {
|
||||||
#ifdef EAGAIN
|
#ifdef EAGAIN
|
||||||
@ -179,6 +189,7 @@ bool TcpSocket::notifyAvailableForWrite(const SharedPtr<Socket> &self,SocketMana
|
|||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
} else memmove(_outbuf,_outbuf + (unsigned int)n,_outptr -= (unsigned int)n);
|
} else memmove(_outbuf,_outbuf + (unsigned int)n,_outptr -= (unsigned int)n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user