|
|
@ -478,10 +478,6 @@ Socket_connectAsync(Socket self, const char* address, int port)
|
|
|
|
if (!prepareAddress(address, port, &serverAddress))
|
|
|
|
if (!prepareAddress(address, port, &serverAddress))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
fd_set fdSet;
|
|
|
|
|
|
|
|
FD_ZERO(&fdSet);
|
|
|
|
|
|
|
|
FD_SET(self->fd, &fdSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activateTcpNoDelay(self);
|
|
|
|
activateTcpNoDelay(self);
|
|
|
|
|
|
|
|
|
|
|
|
fcntl(self->fd, F_SETFL, O_NONBLOCK);
|
|
|
|
fcntl(self->fd, F_SETFL, O_NONBLOCK);
|
|
|
@ -505,17 +501,14 @@ Socket_connectAsync(Socket self, const char* address, int port)
|
|
|
|
SocketState
|
|
|
|
SocketState
|
|
|
|
Socket_checkAsyncConnectState(Socket self)
|
|
|
|
Socket_checkAsyncConnectState(Socket self)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct timeval timeout;
|
|
|
|
struct pollfd fds[1];
|
|
|
|
timeout.tv_sec = 0;
|
|
|
|
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fd_set fdSet;
|
|
|
|
fds[0].fd = self->fd;
|
|
|
|
FD_ZERO(&fdSet);
|
|
|
|
fds[0].events = POLLOUT;
|
|
|
|
FD_SET(self->fd, &fdSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int selectVal = select(self->fd + 1, NULL, &fdSet , NULL, &timeout);
|
|
|
|
int result = poll(fds, 1, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (selectVal == 1) {
|
|
|
|
if (result == 1) {
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if connection is established */
|
|
|
|
/* Check if connection is established */
|
|
|
|
|
|
|
|
|
|
|
@ -530,7 +523,7 @@ Socket_checkAsyncConnectState(Socket self)
|
|
|
|
|
|
|
|
|
|
|
|
return SOCKET_STATE_FAILED;
|
|
|
|
return SOCKET_STATE_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (selectVal == 0) {
|
|
|
|
else if (result == 0) {
|
|
|
|
return SOCKET_STATE_CONNECTING;
|
|
|
|
return SOCKET_STATE_CONNECTING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
@ -544,15 +537,14 @@ Socket_connect(Socket self, const char* address, int port)
|
|
|
|
if (Socket_connectAsync(self, address, port) == false)
|
|
|
|
if (Socket_connectAsync(self, address, port) == false)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
struct timeval timeout;
|
|
|
|
struct pollfd fds[1];
|
|
|
|
timeout.tv_sec = self->connectTimeout / 1000;
|
|
|
|
|
|
|
|
timeout.tv_usec = (self->connectTimeout % 1000) * 1000;
|
|
|
|
fds[0].fd = self->fd;
|
|
|
|
|
|
|
|
fds[0].events = POLLOUT;
|
|
|
|
|
|
|
|
|
|
|
|
fd_set fdSet;
|
|
|
|
int result = poll(fds, 1, self->connectTimeout);
|
|
|
|
FD_ZERO(&fdSet);
|
|
|
|
|
|
|
|
FD_SET(self->fd, &fdSet);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (select(self->fd + 1, NULL, &fdSet , NULL, &timeout) == 1) {
|
|
|
|
if (result == 1) {
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if connection is established */
|
|
|
|
/* Check if connection is established */
|
|
|
|
|
|
|
|
|
|
|
|