Do things the WinSock way
This commit is contained in:

committed by
Love Hornquist Astrand

parent
d6adaa775f
commit
6ba6a17ebd
@@ -39,7 +39,7 @@ krb5_net_read (krb5_context context,
|
|||||||
void *buf,
|
void *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
int fd = *((int *)p_fd);
|
SOCKET fd = *((SOCKET *)p_fd);
|
||||||
|
|
||||||
return net_read (fd, buf, len);
|
return net_read_s (fd, buf, len);
|
||||||
}
|
}
|
||||||
|
@@ -39,9 +39,9 @@ krb5_net_write (krb5_context context,
|
|||||||
const void *buf,
|
const void *buf,
|
||||||
size_t len)
|
size_t len)
|
||||||
{
|
{
|
||||||
int fd = *((int *)p_fd);
|
SOCKET fd = *((SOCKET *)p_fd);
|
||||||
|
|
||||||
return net_write (fd, buf, len);
|
return net_write_s (fd, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
|
KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
|
||||||
@@ -51,7 +51,7 @@ krb5_net_write_block(krb5_context context,
|
|||||||
size_t len,
|
size_t len,
|
||||||
time_t timeout)
|
time_t timeout)
|
||||||
{
|
{
|
||||||
int fd = *((int *)p_fd);
|
SOCKET fd = *((SOCKET *)p_fd);
|
||||||
int ret;
|
int ret;
|
||||||
struct timeval tv, *tvp;
|
struct timeval tv, *tvp;
|
||||||
const char *cbuf = (const char *)buf;
|
const char *cbuf = (const char *)buf;
|
||||||
@@ -71,29 +71,45 @@ krb5_net_write_block(krb5_context context,
|
|||||||
tvp = NULL;
|
tvp = NULL;
|
||||||
|
|
||||||
ret = select(fd + 1, NULL, &wfds, NULL, tvp);
|
ret = select(fd + 1, NULL, &wfds, NULL, tvp);
|
||||||
if (ret < 0) {
|
if (IS_SOCKET_ERROR(ret)) {
|
||||||
if (errno == EINTR)
|
if (SOCK_ERRNO == EINTR)
|
||||||
continue;
|
continue;
|
||||||
return -1;
|
return -1;
|
||||||
} else if (ret == 0)
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_WINSOCK
|
||||||
|
if (ret == 0) {
|
||||||
|
WSASetLastError( WSAETIMEDOUT );
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = send (fd, cbuf, rem, 0);
|
||||||
|
|
||||||
|
if (IS_SOCKET_ERROR(count)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
if (ret == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!FD_ISSET(fd, &wfds)) {
|
if (!FD_ISSET(fd, &wfds)) {
|
||||||
errno = ETIMEDOUT;
|
errno = ETIMEDOUT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
count = send (fd, cbuf, rem, 0);
|
|
||||||
#else
|
|
||||||
count = write (fd, cbuf, rem);
|
count = write (fd, cbuf, rem);
|
||||||
#endif
|
|
||||||
if (count < 0) {
|
if (count < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
cbuf += count;
|
cbuf += count;
|
||||||
rem -= count;
|
rem -= count;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user