Add copyright notices and new function String.chomp
[ocaml.git] / otherlibs / unix / accept.c
blobd2cb598e55928702cf13388beb5b27b7d54878a1
1 /***********************************************************************/
2 /* */
3 /* Objective Caml */
4 /* */
5 /* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
6 /* */
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. */
11 /* */
12 /***********************************************************************/
14 /* $Id$ */
16 #include <mlvalues.h>
17 #include <alloc.h>
18 #include <fail.h>
19 #include <memory.h>
20 #include <signals.h>
21 #include "unixsupport.h"
23 #ifdef HAS_SOCKETS
25 #include "socketaddr.h"
27 CAMLprim value unix_accept(value sock)
29 int retcode;
30 value res;
31 value a;
32 union sock_addr_union addr;
33 socklen_param_type addr_len;
35 addr_len = sizeof(addr);
36 enter_blocking_section();
37 retcode = accept(Int_val(sock), &addr.s_gen, &addr_len);
38 leave_blocking_section();
39 if (retcode == -1) uerror("accept", Nothing);
40 a = alloc_sockaddr(&addr, addr_len, retcode);
41 Begin_root (a);
42 res = alloc_small(2, 0);
43 Field(res, 0) = Val_int(retcode);
44 Field(res, 1) = a;
45 End_roots();
46 return res;
49 #else
51 CAMLprim value unix_accept(value sock)
52 { invalid_argument("accept not implemented"); }
54 #endif