1996-09-04 07:17:43 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, 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>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
2002-06-07 02:49:45 -07:00
|
|
|
#include <signals.h>
|
1996-09-04 07:17:43 -07:00
|
|
|
#include "unixsupport.h"
|
|
|
|
#include "socketaddr.h"
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_accept(sock)
|
1999-02-24 08:35:33 -08:00
|
|
|
value sock;
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
2002-04-30 08:00:48 -07:00
|
|
|
SOCKET sconn = Socket_val(sock);
|
1997-09-03 07:38:02 -07:00
|
|
|
SOCKET snew;
|
|
|
|
value fd = Val_unit, adr = Val_unit, res;
|
1999-02-24 08:01:16 -08:00
|
|
|
int oldvalue, oldvaluelen, newvalue, retcode;
|
2000-03-16 05:35:20 -08:00
|
|
|
union sock_addr_union addr;
|
|
|
|
socklen_param_type addr_len;
|
2003-01-06 08:44:21 -08:00
|
|
|
int errcode = 0;
|
1997-05-26 10:16:31 -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));
|
|
|
|
}
|
2000-03-16 05:35:20 -08:00
|
|
|
addr_len = sizeof(sock_addr);
|
1997-09-03 07:38:02 -07:00
|
|
|
enter_blocking_section();
|
2000-03-16 05:35:20 -08:00
|
|
|
snew = accept(sconn, &addr.s_gen, &addr_len);
|
1997-09-03 07:38:02 -07:00
|
|
|
leave_blocking_section();
|
2003-01-06 08:44:21 -08:00
|
|
|
if( snew == INVALID_SOCKET )
|
|
|
|
errcode = WSAGetLastError ();
|
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 (snew == INVALID_SOCKET) {
|
2003-01-06 08:44:21 -08:00
|
|
|
win32_maperr(errcode);
|
2001-12-03 02:33:39 -08:00
|
|
|
uerror("accept", Nothing);
|
|
|
|
}
|
1997-09-03 07:38:02 -07:00
|
|
|
Begin_roots2 (fd, adr)
|
2002-04-30 08:00:48 -07:00
|
|
|
fd = win_alloc_socket(snew);
|
2000-03-16 05:35:20 -08:00
|
|
|
adr = alloc_sockaddr(&addr, addr_len);
|
1998-10-26 11:19:32 -08:00
|
|
|
res = alloc_small(2, 0);
|
1997-09-03 07:38:02 -07:00
|
|
|
Field(res, 0) = fd;
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(res, 1) = adr;
|
|
|
|
End_roots();
|
1996-09-04 07:17:43 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|