-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathordma_socket.c
52 lines (45 loc) · 1.76 KB
/
ordma_socket.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/***********************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. All rights reserved. This file is distributed */
/* under the terms of the GNU Library General Public License, with */
/* the special exception on linking described in file ../../LICENSE. */
/* */
/***********************************************************************/
#include <caml/fail.h>
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <rdma/rsocket.h>
#include <fcntl.h>
int ordma_socket_domain_table[] = {
PF_UNIX, PF_INET,
PF_INET6
};
int ordma_socket_type_table[] = {
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET
};
CAMLprim value ordma_rsocket(value domain, value type, value proto)
{
int retcode;
retcode = rsocket(ordma_socket_domain_table[Int_val(domain)],
ordma_socket_type_table[Int_val(type)],
Int_val(proto));
if (retcode == -1) uerror("socket", Nothing);
return Val_int(retcode);
}
CAMLprim value ordma_set_nonblock(value fd)
{
int retcode;
retcode = rfcntl(Int_val(fd), F_GETFL, 0);
if (retcode == -1 ||
rfcntl(Int_val(fd), F_SETFL, retcode | O_NONBLOCK) == -1){
uerror("set_nonblock", Nothing);
}
return Val_unit;
}