summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib/roken/net_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/heimdal/lib/roken/net_read.c')
-rw-r--r--source4/heimdal/lib/roken/net_read.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/source4/heimdal/lib/roken/net_read.c b/source4/heimdal/lib/roken/net_read.c
index 9d055d0068..b57dda3dda 100644
--- a/source4/heimdal/lib/roken/net_read.c
+++ b/source4/heimdal/lib/roken/net_read.c
@@ -33,29 +33,23 @@
#include <config.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-
#include "roken.h"
/*
* Like read but never return partial data.
*/
-ssize_t ROKEN_LIB_FUNCTION
-net_read (int fd, void *buf, size_t nbytes)
+#ifndef _WIN32
+
+ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
+net_read (rk_socket_t fd, void *buf, size_t nbytes)
{
char *cbuf = (char *)buf;
ssize_t count;
size_t rem = nbytes;
while (rem > 0) {
-#ifdef WIN32
- count = recv (fd, cbuf, rem, 0);
-#else
count = read (fd, cbuf, rem);
-#endif
if (count < 0) {
if (errno == EINTR)
continue;
@@ -69,3 +63,36 @@ net_read (int fd, void *buf, size_t nbytes)
}
return nbytes;
}
+
+#else
+
+ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
+net_read(rk_socket_t sock, void *buf, size_t nbytes)
+{
+ char *cbuf = (char *)buf;
+ ssize_t count;
+ size_t rem = nbytes;
+
+ while (rem > 0) {
+ count = recv (sock, cbuf, rem, 0);
+ if (count < 0) {
+
+ /* With WinSock, the error EINTR (WSAEINTR), is used to
+ indicate that a blocking call was cancelled using
+ WSACancelBlockingCall(). */
+
+#ifndef HAVE_WINSOCK
+ if (rk_SOCK_ERRNO == EINTR)
+ continue;
+#endif
+ return count;
+ } else if (count == 0) {
+ return count;
+ }
+ cbuf += count;
+ rem -= count;
+ }
+ return nbytes;
+}
+
+#endif