From 63c1789b5edb177db6f5c0ae351815c584562cab Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Tue, 13 Jul 2004 12:25:21 +0000 Subject: 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 --- otherlibs/win32unix/write.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'otherlibs/win32unix/write.c') 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); +} -- cgit v1.2.3-70-g09d2