Initial Windows port
This commit is contained in:
committed by
Love Hornquist Astrand
parent
25a2ac726b
commit
b1063ea8fc
+26
-9
@@ -33,17 +33,13 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like write but never return partial data.
|
||||
*/
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write (int fd, const void *buf, size_t nbytes)
|
||||
{
|
||||
const char *cbuf = (const char *)buf;
|
||||
@@ -51,11 +47,7 @@ net_write (int fd, const void *buf, size_t nbytes)
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
#ifdef WIN32
|
||||
count = send (fd, cbuf, rem, 0);
|
||||
#else
|
||||
count = write (fd, cbuf, rem);
|
||||
#endif
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
@@ -67,3 +59,28 @@ net_write (int fd, const void *buf, size_t nbytes)
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#ifdef SOCKET_IS_NOT_AN_FD
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write_s (SOCKET sock, const void *buf, size_t nbytes)
|
||||
{
|
||||
const char *cbuf = (const char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
count = send (sock, cbuf, rem, 0);
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user