]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/otherlibs/unix/accept.c
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / otherlibs / unix / accept.c
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 /***********************************************************************/
13
14 /* $Id: accept.c 6824 2005-03-24 17:20:54Z doligez $ */
15
16 #include <mlvalues.h>
17 #include <alloc.h>
18 #include <fail.h>
19 #include <memory.h>
20 #include <signals.h>
21 #include "unixsupport.h"
22
23 #ifdef HAS_SOCKETS
24
25 #include "socketaddr.h"
26
27 CAMLprim value unix_accept(value sock)
28 {
29   int retcode;
30   value res;
31   value a;
32   union sock_addr_union addr;
33   socklen_param_type addr_len;
34
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;
47 }
48
49 #else
50
51 CAMLprim value unix_accept(value sock)
52 { invalid_argument("accept not implemented"); }
53   
54 #endif