From 6ba6a17ebdb17e94efb2cc2be740ec16a10f7799 Mon Sep 17 00:00:00 2001 From: Asanka Herath Date: Wed, 26 Aug 2009 14:39:38 -0400 Subject: [PATCH] Do things the WinSock way --- lib/krb5/net_read.c | 4 ++-- lib/krb5/net_write.c | 36 ++++++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/lib/krb5/net_read.c b/lib/krb5/net_read.c index 59bfe71b2..5a8045988 100644 --- a/lib/krb5/net_read.c +++ b/lib/krb5/net_read.c @@ -39,7 +39,7 @@ krb5_net_read (krb5_context context, void *buf, 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); } diff --git a/lib/krb5/net_write.c b/lib/krb5/net_write.c index 9c0d4a5a4..6377957ac 100644 --- a/lib/krb5/net_write.c +++ b/lib/krb5/net_write.c @@ -39,9 +39,9 @@ krb5_net_write (krb5_context context, const void *buf, 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 @@ -51,7 +51,7 @@ krb5_net_write_block(krb5_context context, size_t len, time_t timeout) { - int fd = *((int *)p_fd); + SOCKET fd = *((SOCKET *)p_fd); int ret; struct timeval tv, *tvp; const char *cbuf = (const char *)buf; @@ -71,29 +71,45 @@ krb5_net_write_block(krb5_context context, tvp = NULL; ret = select(fd + 1, NULL, &wfds, NULL, tvp); - if (ret < 0) { - if (errno == EINTR) + if (IS_SOCKET_ERROR(ret)) { + if (SOCK_ERRNO == EINTR) continue; return -1; - } else if (ret == 0) + } + +#ifdef HAVE_WINSOCK + if (ret == 0) { + WSASetLastError( WSAETIMEDOUT ); 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)) { errno = ETIMEDOUT; return -1; } -#ifdef WIN32 - count = send (fd, cbuf, rem, 0); -#else count = write (fd, cbuf, rem); -#endif + if (count < 0) { if (errno == EINTR) continue; else return count; } + +#endif + cbuf += count; rem -= count;