diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2004-07-13 12:25:21 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2004-07-13 12:25:21 +0000 |
commit | 63c1789b5edb177db6f5c0ae351815c584562cab (patch) | |
tree | 7fede3c61f74a6a228cffb11499ae6b222b0b67d /otherlibs/win32unix/write.c | |
parent | 237006931a8e0e1aa292b93c14a1ab60d4138d53 (diff) |
Fusion des modifs faites sur la branche release jusqu'a la release 3.08.0
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@6553 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/write.c')
-rw-r--r-- | otherlibs/win32unix/write.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/otherlibs/win32unix/write.c b/otherlibs/win32unix/write.c index 8571ff679..862e50791 100644 --- a/otherlibs/win32unix/write.c +++ b/otherlibs/win32unix/write.c @@ -62,3 +62,44 @@ CAMLprim value unix_write(value fd, value buf, value vofs, value vlen) End_roots(); return Val_long(written); } + +CAMLprim value unix_single_write(value fd, value buf, value vofs, value vlen) +{ + long ofs, len, written; + DWORD numbytes, numwritten; + char iobuf[UNIX_BUFFER_SIZE]; + + Begin_root (buf); + ofs = Long_val(vofs); + len = Long_val(vlen); + written = 0; + if (len > 0) { + numbytes = len > UNIX_BUFFER_SIZE ? UNIX_BUFFER_SIZE : len; + memmove (iobuf, &Byte(buf, ofs), numbytes); + if (Descr_kind_val(fd) == KIND_SOCKET) { + int ret; + SOCKET s = Socket_val(fd); + enter_blocking_section(); + ret = send(s, iobuf, numbytes, 0); + leave_blocking_section(); + if (ret == SOCKET_ERROR) { + win32_maperr(WSAGetLastError()); + uerror("single_write", Nothing); + } + numwritten = ret; + } else { + BOOL ret; + HANDLE h = Handle_val(fd); + enter_blocking_section(); + ret = WriteFile(h, iobuf, numbytes, &numwritten, NULL); + leave_blocking_section(); + if (! ret) { + win32_maperr(GetLastError()); + uerror("single_write", Nothing); + } + } + written = numwritten; + } + End_roots(); + return Val_long(written); +} |