1 /**************************************************************************/
2 /*                                                                        */
3 /*                                 OCaml                                  */
4 /*                                                                        */
5 /*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           */
6 /*                                                                        */
7 /*   Copyright 2002 Institut National de Recherche en Informatique et     */
8 /*     en Automatique.                                                    */
9 /*                                                                        */
10 /*   All rights reserved.  This file is distributed under the terms of    */
11 /*   the GNU Lesser General Public License version 2.1, with the          */
12 /*   special exception on linking described in the file LICENSE.          */
13 /*                                                                        */
14 /**************************************************************************/
15 
16 #include <caml/mlvalues.h>
17 #include <caml/signals.h>
18 #include "unixsupport.h"
19 
unix_set_nonblock(socket)20 CAMLprim value unix_set_nonblock(socket)
21      value socket;
22 {
23   u_long non_block = 1;
24 
25   if (ioctlsocket(Socket_val(socket), FIONBIO, &non_block) != 0) {
26     win32_maperr(WSAGetLastError());
27     uerror("unix_set_nonblock", Nothing);
28   }
29   Flags_fd_val(socket) = Flags_fd_val(socket) & ~FLAGS_FD_IS_BLOCKING;
30   return Val_unit;
31 }
32 
unix_clear_nonblock(socket)33 CAMLprim value unix_clear_nonblock(socket)
34      value socket;
35 {
36   u_long non_block = 0;
37 
38   if (ioctlsocket(Socket_val(socket), FIONBIO, &non_block) != 0) {
39     win32_maperr(WSAGetLastError());
40     uerror("unix_clear_nonblock", Nothing);
41   }
42   Flags_fd_val(socket) = Flags_fd_val(socket) | FLAGS_FD_IS_BLOCKING;
43   return Val_unit;
44 }
45