Skip to content

Commit de77414

Browse files
committed
Merge pull request #1 from euanh/sync-with-djs55
Sync with djs55
2 parents d7bd058 + 50ffd63 commit de77414

File tree

13 files changed

+2493
-626
lines changed

13 files changed

+2493
-626
lines changed

.gitignore

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
*.annot
2-
*.cmo
3-
*.cma
4-
*.cmi
5-
*.a
6-
*.o
7-
*.cmx
8-
*.cmxs
9-
*.cmxa
1+
setup.bin
2+
setup.data
3+
setup.log
4+
dist
5+
_build
6+
api.docdir
7+
*.native
8+
*.byte

Makefile

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
.PHONY: all clean install build
2-
all: build doc
1+
# OASIS_START
2+
# DO NOT EDIT (digest: a3c674b4239234cbbe53afe090018954)
33

4-
NAME=fd-send-recv
5-
J=4
4+
SETUP = ocaml setup.ml
65

7-
export OCAMLRUNPARAM=b
6+
build: setup.data
7+
$(SETUP) -build $(BUILDFLAGS)
88

9-
setup.bin: setup.ml
10-
@ocamlopt.opt -o $@ $< || ocamlopt -o $@ $< || ocamlc -o $@ $<
11-
@rm -f setup.cmx setup.cmi setup.o setup.cmo
9+
doc: setup.data build
10+
$(SETUP) -doc $(DOCFLAGS)
1211

13-
setup.data: setup.bin
14-
@./setup.bin -configure
12+
test: setup.data build
13+
$(SETUP) -test $(TESTFLAGS)
1514

16-
build: setup.data setup.bin
17-
@./setup.bin -build -j $(J)
15+
all:
16+
$(SETUP) -all $(ALLFLAGS)
1817

19-
doc: setup.data setup.bin
20-
@./setup.bin -doc -j $(J)
18+
install: setup.data
19+
$(SETUP) -install $(INSTALLFLAGS)
2120

22-
install: setup.bin
23-
@./setup.bin -install
21+
uninstall: setup.data
22+
$(SETUP) -uninstall $(UNINSTALLFLAGS)
2423

25-
test: setup.bin build
26-
@./setup.bin -test
27-
28-
reinstall: setup.bin
29-
@ocamlfind remove $(NAME) || true
30-
@./setup.bin -reinstall
24+
reinstall: setup.data
25+
$(SETUP) -reinstall $(REINSTALLFLAGS)
3126

3227
clean:
33-
@ocamlbuild -clean
34-
@rm -f setup.data setup.log setup.bin
28+
$(SETUP) -clean $(CLEANFLAGS)
29+
30+
distclean:
31+
$(SETUP) -distclean $(DISTCLEANFLAGS)
32+
33+
setup.data:
34+
$(SETUP) -configure $(CONFIGUREFLAGS)
35+
36+
configure:
37+
$(SETUP) -configure $(CONFIGUREFLAGS)
38+
39+
.PHONY: build doc test all install uninstall reinstall clean distclean configure
40+
41+
# OASIS_STOP

_oasis

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,62 @@
1-
OASISFormat: 0.2
1+
OASISFormat: 0.3
22
Name: fd-send-recv
33
Version: 1.0.1
44
Synopsis: Bindings to sendmsg/recvmsg which allow fds to be sent/received
55
Authors: Jonathan Ludlam <[email protected]>
66
License: LGPL-2.1 with OCaml linking exception
7-
Plugins: META (0.2)
7+
Plugins: META (0.3), DevFiles (0.3)
88
BuildTools: ocamlbuild
99

10+
Flag tuntap
11+
Description: Enable the tuntap test (require package tuntap)
12+
Default: false
13+
1014
Library fd_send_recv
1115
CompiledObject: best
1216
Path: lib
1317
Findlibname: fd-send-recv
1418
Modules: Fd_send_recv
1519
CSources: fd_send_recv_stubs.c
1620
BuildDepends: unix
21+
22+
Document api
23+
Title: Documentation and API reference
24+
Type: ocamlbuild (0.3)
25+
BuildTools+: ocamldoc
26+
XOCamlbuildLibraries: fd-send-recv
27+
XOcamlbuildPath: doc
28+
Install: false
29+
30+
Executable test
31+
Path: test
32+
MainIs: test.ml
33+
BuildDepends: threads, fd-send-recv
34+
CompiledObject: best
35+
Install: false
36+
37+
Executable test_fork
38+
Path: test
39+
MainIs: test_fork.ml
40+
BuildDepends: fd-send-recv
41+
CompiledObject: best
42+
Install: false
43+
44+
Executable test_tuntap
45+
Build$: flag(tuntap)
46+
Install: false
47+
Path: test
48+
MainIs: test_tuntap.ml
49+
BuildDepends: fd-send-recv, tuntap
50+
CompiledObject: best
51+
52+
Test test
53+
Command: ./test.native
54+
Run: true
55+
56+
Test test_fork
57+
Command: ./test_fork.native
58+
Run: true
59+
60+
Test test_tuntap
61+
Command: ./test_tuntap.native
62+
Run$: flag(tuntap)

_tags

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 4206d3c65bf245bd4b7dd568003eb92a)
3-
# Ignore VCS directories, you can use the same kind of rule outside
4-
# OASIS_START/STOP if you want to exclude directories that contains
2+
# DO NOT EDIT (digest: 31b466dfab10d97e7109d7a6c9172be1)
3+
# Ignore VCS directories, you can use the same kind of rule outside
4+
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
6+
true: annot, bin_annot
67
<**/.svn>: -traverse
78
<**/.svn>: not_hygienic
89
".bzr": -traverse
@@ -16,6 +17,22 @@
1617
# Library fd_send_recv
1718
"lib/fd_send_recv.cmxs": use_fd_send_recv
1819
<lib/fd_send_recv.{cma,cmxa}>: use_libfd_send_recv_stubs
19-
<lib/*.ml{,i}>: pkg_unix
20+
<lib/*.ml{,i,y}>: pkg_unix
2021
"lib/fd_send_recv_stubs.c": pkg_unix
22+
# Executable test
23+
<test/test.{native,byte}>: pkg_threads
24+
<test/test.{native,byte}>: pkg_unix
25+
<test/test.{native,byte}>: use_fd_send_recv
26+
<test/*.ml{,i,y}>: pkg_threads
27+
# Executable test_fork
28+
<test/test_fork.{native,byte}>: pkg_unix
29+
<test/test_fork.{native,byte}>: use_fd_send_recv
30+
# Executable test_tuntap
31+
<test/test_tuntap.{native,byte}>: pkg_tuntap
32+
<test/test_tuntap.{native,byte}>: pkg_unix
33+
<test/test_tuntap.{native,byte}>: use_fd_send_recv
34+
<test/*.ml{,i,y}>: pkg_tuntap
35+
<test/*.ml{,i,y}>: pkg_unix
36+
<test/*.ml{,i,y}>: use_fd_send_recv
2137
# OASIS_STOP
38+
<lib>: include

configure

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
# OASIS_START
4+
# DO NOT EDIT (digest: dc86c2ad450f91ca10c931b6045d0499)
5+
set -e
6+
7+
FST=true
8+
for i in "$@"; do
9+
if $FST; then
10+
set --
11+
FST=false
12+
fi
13+
14+
case $i in
15+
--*=*)
16+
ARG=${i%%=*}
17+
VAL=${i##*=}
18+
set -- "$@" "$ARG" "$VAL"
19+
;;
20+
*)
21+
set -- "$@" "$i"
22+
;;
23+
esac
24+
done
25+
26+
ocaml setup.ml -configure "$@"
27+
# OASIS_STOP

doc/api.odocl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fd_send_recv

lib/fd_send_recv.mli

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,30 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414

15+
(** Module to send and receive file descriptors over UNIX domain sockets. *)
16+
1517
exception Unix_error of int
1618
(** Thrown by the low-level C functions *)
1719

18-
val send_fd : Unix.file_descr -> string -> int -> int -> Unix.msg_flag list -> Unix.file_descr -> int
19-
(** [send_fd channel_fd buf ofs len flags fd_to_send] sends a message over [channel_fd]
20-
containing the [buf] [ofs] [len] substring, with [flags] and file descriptor [fd_to_send] *)
20+
val send_fd : Unix.file_descr -> string -> int -> int ->
21+
Unix.msg_flag list -> Unix.file_descr -> int
22+
(** [send_fd channel_fd buf ofs len flags fd_to_send] sends a message
23+
over [channel_fd] containing the [buf] [ofs] [len] substring, with
24+
[flags] and file descriptor [fd_to_send], and returns the number
25+
of bytes sent. Note that you have to send a non-empty message
26+
(e.g. of size greater than zero) to actually have the fd
27+
passed. *)
2128

22-
val recv_fd : Unix.file_descr -> string -> int -> int -> Unix.msg_flag list -> int * Unix.sockaddr * Unix.file_descr
23-
(** [recv_fd channel_fd buf ofs len flags] receives a message into substring [buf] [ofs] [len]
24-
with [flags], returning the number of bytes read, the address of the peer and a file descriptor *)
29+
val recv_fd : Unix.file_descr -> string -> int -> int ->
30+
Unix.msg_flag list -> int * Unix.sockaddr * Unix.file_descr
31+
(** [recv_fd channel_fd buf ofs len flags] receives a message into
32+
substring [buf] [ofs] [len] with [flags], returning the number of
33+
bytes read, the address of the peer and a file descriptor. *)
2534

2635
val int_of_fd : Unix.file_descr -> int
27-
(** [int_of_fd fd] returns the underlying unix integer file descriptor associated with OCaml Unix.file_descr [fd] *)
36+
(** [int_of_fd fd] returns the underlying unix integer file descriptor
37+
associated with OCaml Unix.file_descr [fd]. *)
2838

2939
val fd_of_int : int -> Unix.file_descr
30-
(** [fd_of_int fd] returns the OCaml Unix.file_descr associated with underlying unix integer [fd] *)
40+
(** [fd_of_int fd] returns the OCaml Unix.file_descr associated with
41+
underlying unix integer [fd]. *)

lib/fd_send_recv_stubs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ CAMLprim value stub_unix_send_fd(value sock, value buff, value ofs, value len, v
9595
ret=sendmsg(Int_val(sock), &msg, cv_flags);
9696
caml_leave_blocking_section();
9797

98-
if(ret == -1)
98+
if(ret == -1) {
99+
perror("sendmsg");
99100
raise_error(errno);
101+
}
100102

101103
CAMLreturn(Val_int(ret));
102104
}
@@ -142,8 +144,10 @@ CAMLprim value stub_unix_recv_fd(value sock, value buff, value ofs, value len, v
142144
ret=recvmsg(Int_val(sock), &msg, cv_flags);
143145
caml_leave_blocking_section();
144146

145-
if(ret == -1)
147+
if(ret == -1) {
148+
perror("recvmsg");
146149
raise_error(errno);
150+
}
147151

148152
if(ret>0 && msg.msg_controllen>0) {
149153
cmsg = CMSG_FIRSTHDR(&msg);

0 commit comments

Comments
 (0)