if (ioctlsocket (handle, FIONBIO, &one) == SOCKET_ERROR)
{
- dbus_set_error (error, _dbus_error_from_errno (WSAGetLastError ()),
+ DBUS_SOCKET_SET_ERRNO ();
+ dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to set socket %d:%d to nonblocking: %s", handle,
- _dbus_strerror (WSAGetLastError ()));
+ _dbus_strerror_from_errno ());
return FALSE;
}
NULL,
NULL);
- if (rc < 0)
+ if (rc == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
_dbus_verbose ("WSASend: failed: %s\n", _dbus_strerror_from_errno ());
saddr.sin_port = 0;
saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
- if (bind (temp, (struct sockaddr *)&saddr, sizeof (saddr)))
+ if (bind (temp, (struct sockaddr *)&saddr, sizeof (saddr)) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
goto out0;
}
len = sizeof (saddr);
- if (getsockname (temp, (struct sockaddr *)&saddr, &len))
+ if (getsockname (temp, (struct sockaddr *)&saddr, &len) == SOCKET_ERROR)
{
DBUS_SOCKET_SET_ERRNO ();
goto out0;
_dbus_win_startup_winsock ();
- fd = socket (AF_INET, SOCK_STREAM, 0);
-
- if (DBUS_SOCKET_IS_INVALID (fd))
- {
- DBUS_SOCKET_SET_ERRNO ();
- dbus_set_error (error,
- _dbus_error_from_errno (errno),
- "Failed to create socket: %s",
- _dbus_strerror_from_errno ());
-
- return -1;
- }
-
- _DBUS_ASSERT_ERROR_IS_CLEAR(error);
-
_DBUS_ZERO (hints);
if (!family)
else
{
dbus_set_error (error,
- _dbus_error_from_errno (errno),
+ DBUS_ERROR_INVALID_ARGS,
"Unknown address family %s", family);
- closesocket (fd);
return -1;
}
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = 0;
#endif
- if ((res = getaddrinfo(host, port, &hints, &ai)) != 0)
+ if ((res = getaddrinfo(host, port, &hints, &ai)) != 0 || !ai)
{
dbus_set_error (error,
- _dbus_error_from_errno (errno),
+ _dbus_error_from_errno (res),
"Failed to lookup host/port: \"%s:%s\": %s (%d)",
- host, port, gai_strerror(res), res);
- closesocket (fd);
+ host, port, _dbus_strerror(res), res);
return -1;
}
- closesocket (fd);
- fd = -1;
-
tmp = ai;
while (tmp)
{
- if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) < 0)
+ if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
+ DBUS_SOCKET_SET_ERRNO ();
+ dbus_set_error (error,
+ _dbus_error_from_errno (errno),
+ "Failed to open socket: %s",
+ _dbus_strerror_from_errno ());
freeaddrinfo(ai);
- dbus_set_error (error,
- _dbus_error_from_errno (errno),
- "Failed to open socket: %s",
- _dbus_strerror_from_errno ());
return -1;
}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
- if (connect (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) != 0)
+ if (connect (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
{
+ DBUS_SOCKET_SET_ERRNO ();
closesocket(fd);
- fd = -1;
+ fd = -1;
tmp = tmp->ai_next;
continue;
}
dbus_set_error (error,
_dbus_error_from_errno (errno),
"Failed to connect to socket \"%s:%s\" %s",
- host, port, _dbus_strerror(errno));
+ host, port, _dbus_strerror_from_errno ());
return -1;
}
- if ( noncefile != NULL )
+ if (noncefile != NULL)
{
DBusString noncefileStr;
dbus_bool_t ret;
closesocket (fd);
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
return -1;
- }
+ }
ret = _dbus_send_nonce (fd, &noncefileStr, error);
_dbus_string_free (&noncefileStr);
if (!ret)
- {
- closesocket (fd);
+ {
+ closesocket (fd);
return -1;
}
}
- if (!_dbus_set_fd_nonblocking (fd, error) )
+ if (!_dbus_set_fd_nonblocking (fd, error))
{
closesocket (fd);
return -1;
else
{
dbus_set_error (error,
- _dbus_error_from_errno (errno),
+ DBUS_ERROR_INVALID_ARGS,
"Unknown address family %s", family);
return -1;
}
if ((res = getaddrinfo(host, port, &hints, &ai)) != 0 || !ai)
{
dbus_set_error (error,
- _dbus_error_from_errno (errno),
+ _dbus_error_from_errno (res),
"Failed to lookup host/port: \"%s:%s\": %s (%d)",
- host ? host : "*", port, gai_strerror(res), res);
+ host ? host : "*", port, _dbus_strerror(res), res);
return -1;
}
while (tmp)
{
int fd = -1, *newlisten_fd;
- if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) < 0)
+ if ((fd = socket (tmp->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET)
{
+ DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error,
_dbus_error_from_errno (errno),
"Failed to open socket: %s",
if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) == SOCKET_ERROR)
{
- closesocket (fd);
+ DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to bind socket \"%s:%s\": %s",
host ? host : "*", port, _dbus_strerror_from_errno ());
+ closesocket (fd);
goto failed;
}
if (listen (fd, 30 /* backlog */) == SOCKET_ERROR)
{
- closesocket (fd);
+ DBUS_SOCKET_SET_ERRNO ();
dbus_set_error (error, _dbus_error_from_errno (errno),
"Failed to listen on socket \"%s:%s\": %s",
host ? host : "*", port, _dbus_strerror_from_errno ());
+ closesocket (fd);
goto failed;
}
newlisten_fd = dbus_realloc(listen_fd, sizeof(int)*(nlisten_fd+1));
if (!newlisten_fd)
- {
+ {
closesocket (fd);
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to allocate file handle array: %s",
- _dbus_strerror_from_errno ());
+ dbus_set_error (error, DBUS_ERROR_NO_MEMORY,
+ "Failed to allocate file handle array");
goto failed;
- }
+ }
listen_fd = newlisten_fd;
listen_fd[nlisten_fd] = fd;
nlisten_fd++;
socklen_t addrlen = sizeof(addr);
char portbuf[10];
- if ((res = getsockname(fd, &addr.Address, &addrlen)) != 0)
- {
- dbus_set_error (error, _dbus_error_from_errno (errno),
- "Failed to resolve port \"%s:%s\": %s (%d)",
- host ? host : "*", port, gai_strerror(res), res);
+ if (getsockname(fd, &addr.Address, &addrlen) == SOCKET_ERROR)
+ {
+ DBUS_SOCKET_SET_ERRNO ();
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Failed to resolve port \"%s:%s\": %s",
+ host ? host : "*", port, _dbus_strerror_from_errno());
goto failed;
}
snprintf( portbuf, sizeof( portbuf ) - 1, "%d", addr.AddressIn.sin_port );
{
dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
goto failed;
- }
+ }
/* Release current address list & redo lookup */
port = _dbus_string_get_const_data(retport);