int
BIO_sock_init(void)
{
-#ifdef OPENSSL_SYS_WINDOWS
- static struct WSAData wsa_state;
-
- if (!wsa_init_done) {
- int err;
-
- wsa_init_done = 1;
- memset(&wsa_state, 0, sizeof(wsa_state));
- /* Not making wsa_state available to the rest of the
- * code is formally wrong. But the structures we use
- * are [beleived to be] invariable among Winsock DLLs,
- * while API availability is [expected to be] probed
- * at run-time with DSO_global_lookup. */
- if (WSAStartup(0x0202, &wsa_state) != 0) {
- err = WSAGetLastError();
- SYSerr(SYS_F_WSASTARTUP, err);
- BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
- return (-1);
- }
- }
-#endif /* OPENSSL_SYS_WINDOWS */
#ifdef WATT32
extern int _watt_do_exit;
_watt_do_exit = 0;
void
BIO_sock_cleanup(void)
{
-#ifdef OPENSSL_SYS_WINDOWS
- if (wsa_init_done) {
- wsa_init_done = 0;
-#if 0 /* this call is claimed to be non-present in Winsock2 */
- WSACancelBlockingCall();
-#endif
- WSACleanup();
- }
-#elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
+#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
if (wsa_init_done) {
wsa_init_done = 0;
WSACleanup();
#ifdef SO_REUSEADDR
err_num = errno;
if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
-#ifdef OPENSSL_SYS_WINDOWS
- /* Some versions of Windows define EADDRINUSE to
- * a dummy value.
- */
- (err_num == WSAEADDRINUSE))
-#else
(err_num == EADDRINUSE))
-#endif
{
client = server;
if (h == NULL || strcmp(h, "*") == 0) {
struct timeval timenow, timeleft;
/* Read current socket timeout */
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0) {
- perror("getsockopt");
- } else {
- data->socket_timeout.tv_sec = timeout / 1000;
- data->socket_timeout.tv_usec = (timeout % 1000) * 1000;
- }
-#else
sz.i = sizeof(data->socket_timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
&(data->socket_timeout), (void *)&sz) < 0) {
perror("getsockopt");
} else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0)
OPENSSL_assert(sz.s <= sizeof(data->socket_timeout));
-#endif
/* Get current time */
get_current_time(&timenow);
(data->socket_timeout.tv_sec > timeleft.tv_sec) ||
(data->socket_timeout.tv_sec == timeleft.tv_sec &&
data->socket_timeout.tv_usec >= timeleft.tv_usec)) {
-#ifdef OPENSSL_SYS_WINDOWS
- timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
&timeleft, sizeof(struct timeval)) < 0) {
perror("setsockopt");
}
-#endif
}
}
#endif
/* Is a timer active? */
if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout = data->socket_timeout.tv_sec * 1000 +
- data->socket_timeout.tv_usec / 1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
&(data->socket_timeout), sizeof(struct timeval)) < 0) {
perror("setsockopt");
}
-#endif
}
#endif
}
break;
#if defined(SO_RCVTIMEO)
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
-#ifdef OPENSSL_SYS_WINDOWS
- {
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
sizeof(struct timeval)) < 0) {
perror("setsockopt");
ret = -1;
}
-#endif
break;
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
{
size_t s;
int i;
} sz = {0};
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0) {
- perror("getsockopt");
- ret = -1;
- } else {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
- }
-#else
sz.i = sizeof(struct timeval);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
ptr, (void *)&sz) < 0) {
ret = (int)sz.s;
} else
ret = sz.i;
-#endif
}
break;
#endif
#if defined(SO_SNDTIMEO)
case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT:
-#ifdef OPENSSL_SYS_WINDOWS
- {
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
sizeof(struct timeval)) < 0) {
perror("setsockopt");
ret = -1;
}
-#endif
break;
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
{
size_t s;
int i;
} sz = {0};
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, &sz.i) < 0) {
- perror("getsockopt");
- ret = -1;
- } else {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
- }
-#else
sz.i = sizeof(struct timeval);
if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
ptr, (void *)&sz) < 0) {
ret = (int)sz.s;
} else
ret = sz.i;
-#endif
}
break;
#endif
case BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP:
/* fall-through */
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
-#ifdef OPENSSL_SYS_WINDOWS
- if (data->_errno == WSAETIMEDOUT)
-#else
- if (data->_errno == EAGAIN)
-#endif
- {
+ if (data->_errno == EAGAIN) {
ret = 1;
data->_errno = 0;
} else
if ((i == 0) || (i == -1)) {
err = errno;
-
-#if defined(OPENSSL_SYS_WINDOWS)
- /* If the socket return value (i) is -1
- * and err is unexpectedly 0 at this point,
- * the error code was overwritten by
- * another system call before this error
- * handling is called.
- */
-#endif
-
return (BIO_dgram_non_fatal_error(err));
}
return (0);
BIO_dgram_non_fatal_error(int err)
{
switch (err) {
-#if defined(OPENSSL_SYS_WINDOWS)
-# if defined(WSAEWOULDBLOCK)
- case WSAEWOULDBLOCK:
-# endif
-
-# if 0 /* This appears to always be an error */
-# if defined(WSAENOTCONN)
- case WSAENOTCONN:
-# endif
-# endif
-#endif
#ifdef EWOULDBLOCK
# ifdef WSAEWOULDBLOCK
if ((i == 0) || (i == -1)) {
err = errno;
-
-#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
- if ((i == -1) && (err == 0))
- return (1);
-#endif
-
return (BIO_fd_non_fatal_error(err));
}
return (0);
else
#endif
{
-#if defined(OPENSSL_SYS_WINDOWS)
- int fd = _fileno((FILE*)ptr);
- if (num & BIO_FP_TEXT)
- _setmode(fd, _O_TEXT);
- else
- _setmode(fd, _O_BINARY);
-#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
+#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
int fd = fileno((FILE*)ptr);
/* Under CLib there are differences in file modes */
if (num & BIO_FP_TEXT)
if ((i == 0) || (i == -1)) {
err = errno;
-
-#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
- if ((i == -1) && (err == 0))
- return (1);
-#endif
-
return (BIO_sock_non_fatal_error(err));
}
return (0);
int
BIO_sock_init(void)
{
-#ifdef OPENSSL_SYS_WINDOWS
- static struct WSAData wsa_state;
-
- if (!wsa_init_done) {
- int err;
-
- wsa_init_done = 1;
- memset(&wsa_state, 0, sizeof(wsa_state));
- /* Not making wsa_state available to the rest of the
- * code is formally wrong. But the structures we use
- * are [beleived to be] invariable among Winsock DLLs,
- * while API availability is [expected to be] probed
- * at run-time with DSO_global_lookup. */
- if (WSAStartup(0x0202, &wsa_state) != 0) {
- err = WSAGetLastError();
- SYSerr(SYS_F_WSASTARTUP, err);
- BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP);
- return (-1);
- }
- }
-#endif /* OPENSSL_SYS_WINDOWS */
#ifdef WATT32
extern int _watt_do_exit;
_watt_do_exit = 0;
void
BIO_sock_cleanup(void)
{
-#ifdef OPENSSL_SYS_WINDOWS
- if (wsa_init_done) {
- wsa_init_done = 0;
-#if 0 /* this call is claimed to be non-present in Winsock2 */
- WSACancelBlockingCall();
-#endif
- WSACleanup();
- }
-#elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
+#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
if (wsa_init_done) {
wsa_init_done = 0;
WSACleanup();
#ifdef SO_REUSEADDR
err_num = errno;
if ((bind_mode == BIO_BIND_REUSEADDR_IF_UNUSED) &&
-#ifdef OPENSSL_SYS_WINDOWS
- /* Some versions of Windows define EADDRINUSE to
- * a dummy value.
- */
- (err_num == WSAEADDRINUSE))
-#else
(err_num == EADDRINUSE))
-#endif
{
client = server;
if (h == NULL || strcmp(h, "*") == 0) {
struct timeval timenow, timeleft;
/* Read current socket timeout */
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0) {
- perror("getsockopt");
- } else {
- data->socket_timeout.tv_sec = timeout / 1000;
- data->socket_timeout.tv_usec = (timeout % 1000) * 1000;
- }
-#else
sz.i = sizeof(data->socket_timeout);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
&(data->socket_timeout), (void *)&sz) < 0) {
perror("getsockopt");
} else if (sizeof(sz.s) != sizeof(sz.i) && sz.i == 0)
OPENSSL_assert(sz.s <= sizeof(data->socket_timeout));
-#endif
/* Get current time */
get_current_time(&timenow);
(data->socket_timeout.tv_sec > timeleft.tv_sec) ||
(data->socket_timeout.tv_sec == timeleft.tv_sec &&
data->socket_timeout.tv_usec >= timeleft.tv_usec)) {
-#ifdef OPENSSL_SYS_WINDOWS
- timeout = timeleft.tv_sec * 1000 + timeleft.tv_usec / 1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
&timeleft, sizeof(struct timeval)) < 0) {
perror("setsockopt");
}
-#endif
}
}
#endif
/* Is a timer active? */
if (data->next_timeout.tv_sec > 0 || data->next_timeout.tv_usec > 0) {
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout = data->socket_timeout.tv_sec * 1000 +
- data->socket_timeout.tv_usec / 1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
&(data->socket_timeout), sizeof(struct timeval)) < 0) {
perror("setsockopt");
}
-#endif
}
#endif
}
break;
#if defined(SO_RCVTIMEO)
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
-#ifdef OPENSSL_SYS_WINDOWS
- {
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
sizeof(struct timeval)) < 0) {
perror("setsockopt");
ret = -1;
}
-#endif
break;
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
{
size_t s;
int i;
} sz = {0};
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
- (void*)&timeout, &sz.i) < 0) {
- perror("getsockopt");
- ret = -1;
- } else {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
- }
-#else
sz.i = sizeof(struct timeval);
if (getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
ptr, (void *)&sz) < 0) {
ret = (int)sz.s;
} else
ret = sz.i;
-#endif
}
break;
#endif
#if defined(SO_SNDTIMEO)
case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT:
-#ifdef OPENSSL_SYS_WINDOWS
- {
- struct timeval *tv = (struct timeval *)ptr;
- int timeout = tv->tv_sec * 1000 + tv->tv_usec/1000;
- if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, sizeof(timeout)) < 0) {
- perror("setsockopt");
- ret = -1;
- }
- }
-#else
if (setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
sizeof(struct timeval)) < 0) {
perror("setsockopt");
ret = -1;
}
-#endif
break;
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
{
size_t s;
int i;
} sz = {0};
-#ifdef OPENSSL_SYS_WINDOWS
- int timeout;
- struct timeval *tv = (struct timeval *)ptr;
-
- sz.i = sizeof(timeout);
- if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
- (void*)&timeout, &sz.i) < 0) {
- perror("getsockopt");
- ret = -1;
- } else {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
- ret = sizeof(*tv);
- }
-#else
sz.i = sizeof(struct timeval);
if (getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
ptr, (void *)&sz) < 0) {
ret = (int)sz.s;
} else
ret = sz.i;
-#endif
}
break;
#endif
case BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP:
/* fall-through */
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
-#ifdef OPENSSL_SYS_WINDOWS
- if (data->_errno == WSAETIMEDOUT)
-#else
- if (data->_errno == EAGAIN)
-#endif
- {
+ if (data->_errno == EAGAIN) {
ret = 1;
data->_errno = 0;
} else
if ((i == 0) || (i == -1)) {
err = errno;
-
-#if defined(OPENSSL_SYS_WINDOWS)
- /* If the socket return value (i) is -1
- * and err is unexpectedly 0 at this point,
- * the error code was overwritten by
- * another system call before this error
- * handling is called.
- */
-#endif
-
return (BIO_dgram_non_fatal_error(err));
}
return (0);
BIO_dgram_non_fatal_error(int err)
{
switch (err) {
-#if defined(OPENSSL_SYS_WINDOWS)
-# if defined(WSAEWOULDBLOCK)
- case WSAEWOULDBLOCK:
-# endif
-
-# if 0 /* This appears to always be an error */
-# if defined(WSAENOTCONN)
- case WSAENOTCONN:
-# endif
-# endif
-#endif
#ifdef EWOULDBLOCK
# ifdef WSAEWOULDBLOCK
if ((i == 0) || (i == -1)) {
err = errno;
-
-#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
- if ((i == -1) && (err == 0))
- return (1);
-#endif
-
return (BIO_fd_non_fatal_error(err));
}
return (0);
else
#endif
{
-#if defined(OPENSSL_SYS_WINDOWS)
- int fd = _fileno((FILE*)ptr);
- if (num & BIO_FP_TEXT)
- _setmode(fd, _O_TEXT);
- else
- _setmode(fd, _O_BINARY);
-#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
+#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
int fd = fileno((FILE*)ptr);
/* Under CLib there are differences in file modes */
if (num & BIO_FP_TEXT)
if ((i == 0) || (i == -1)) {
err = errno;
-
-#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
- if ((i == -1) && (err == 0))
- return (1);
-#endif
-
return (BIO_sock_non_fatal_error(err));
}
return (0);