1996-09-04 07:17:43 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
1996-09-05 06:32:25 -07:00
|
|
|
#include "unixsupport.h"
|
1996-09-04 07:17:43 -07:00
|
|
|
|
|
|
|
int socket_domain_table[] = {
|
|
|
|
PF_UNIX, PF_INET
|
|
|
|
};
|
|
|
|
|
|
|
|
int socket_type_table[] = {
|
|
|
|
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET
|
|
|
|
};
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_socket(domain, type, proto)
|
1996-09-04 07:17:43 -07:00
|
|
|
value domain, type, proto;
|
|
|
|
{
|
|
|
|
SOCKET s;
|
1999-02-24 08:01:16 -08:00
|
|
|
int oldvalue, oldvaluelen, newvalue, retcode;
|
1996-09-04 07:17:43 -07:00
|
|
|
|
1999-02-24 08:01:16 -08:00
|
|
|
oldvaluelen = sizeof(oldvalue);
|
1999-02-24 06:28:23 -08:00
|
|
|
retcode = getsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
|
1999-02-24 08:01:16 -08:00
|
|
|
(char *) &oldvalue, &oldvaluelen);
|
1999-02-24 06:28:23 -08:00
|
|
|
if (retcode == 0) {
|
1999-02-24 08:35:33 -08:00
|
|
|
/* Set sockets to synchronous mode */
|
|
|
|
newvalue = SO_SYNCHRONOUS_NONALERT;
|
1999-02-24 06:28:23 -08:00
|
|
|
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
|
|
|
|
(char *) &newvalue, sizeof(newvalue));
|
|
|
|
}
|
1996-09-04 07:17:43 -07:00
|
|
|
s = socket(socket_domain_table[Int_val(domain)],
|
|
|
|
socket_type_table[Int_val(type)],
|
|
|
|
Int_val(proto));
|
1999-02-24 06:28:23 -08:00
|
|
|
if (retcode == 0) {
|
|
|
|
/* Restore initial mode */
|
|
|
|
setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
|
1999-02-24 08:01:16 -08:00
|
|
|
(char *) &oldvalue, oldvaluelen);
|
1999-02-24 06:28:23 -08:00
|
|
|
}
|
2001-12-03 02:33:39 -08:00
|
|
|
if (s == INVALID_SOCKET) {
|
|
|
|
win32_maperr(WSAGetLastError());
|
|
|
|
uerror("socket", Nothing);
|
|
|
|
}
|
2002-04-30 08:00:48 -07:00
|
|
|
return win_alloc_socket(s);
|
1996-09-04 07:17:43 -07:00
|
|
|
}
|