1 /***********************************************************************/
5 /* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */
7 /* Copyright 1996 Institut National de Recherche en Informatique et */
8 /* en Automatique. All rights reserved. This file is distributed */
9 /* under the terms of the GNU Library General Public License, with */
10 /* the special exception on linking described in file ../../LICENSE. */
12 /***********************************************************************/
14 /* $Id: socket.c 4765 2002-04-30 15:00:48Z xleroy $ */
17 #include "unixsupport.h"
19 int socket_domain_table[] = {
23 int socket_type_table[] = {
24 SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET
27 CAMLprim value unix_socket(domain, type, proto)
28 value domain, type, proto;
31 int oldvalue, oldvaluelen, newvalue, retcode;
33 oldvaluelen = sizeof(oldvalue);
34 retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
35 (char *) &oldvalue, &oldvaluelen);
37 /* Set sockets to synchronous mode */
38 newvalue = SO_SYNCHRONOUS_NONALERT;
39 setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
40 (char *) &newvalue, sizeof(newvalue));
42 s = socket(socket_domain_table[Int_val(domain)],
43 socket_type_table[Int_val(type)],
46 /* Restore initial mode */
47 setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
48 (char *) &oldvalue, oldvaluelen);
50 if (s == INVALID_SOCKET) {
51 win32_maperr(WSAGetLastError());
52 uerror("socket", Nothing);
54 return win_alloc_socket(s);