[Pkg-ocaml-maint-commits] [SCM] syslog-ocaml packaging branch, master, updated. debian/1.4-1-5-g3ddb4f4
Eric Cooper
ecc at cmu.edu
Mon Mar 2 01:26:29 UTC 2009
The following commit has been merged in the master branch:
commit 6d5c5dd981da984263e29f2e58c3553f3ea3c655
Author: Eric Cooper <ecc at cmu.edu>
Date: Sun Mar 1 20:05:54 2009 -0500
add wrapper for send(2) with MSG_NOSIGNAL option
diff --git a/Makefile b/Makefile
index 61245a8..62053e6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
-include Makefile.conf
-SOURCES=syslog.mli syslog.ml
+SOURCES=aux.mli aux.ml aux_stubs.c syslog.mli syslog.ml
RESULT=syslog
PACKS=unix
diff --git a/aux.ml b/aux.ml
new file mode 100644
index 0000000..6aa8b95
--- /dev/null
+++ b/aux.ml
@@ -0,0 +1,10 @@
+type msg_flag = MSG_OOB | MSG_DONTROUTE | MSG_PEEK | MSG_NOSIGNAL
+
+external unsafe_send :
+ Unix.file_descr -> string -> int -> int -> msg_flag list -> int
+ = "aux_send"
+
+let send fd buf ofs len flags =
+ if ofs < 0 || len < 0 || ofs > String.length buf - len
+ then invalid_arg "Unix.send"
+ else unsafe_send fd buf ofs len flags
diff --git a/aux.mli b/aux.mli
new file mode 100644
index 0000000..d36bcbf
--- /dev/null
+++ b/aux.mli
@@ -0,0 +1,3 @@
+type msg_flag = MSG_OOB | MSG_DONTROUTE | MSG_PEEK | MSG_NOSIGNAL
+
+val send : Unix.file_descr -> string -> int -> int -> msg_flag list -> int
diff --git a/aux_stubs.c b/aux_stubs.c
new file mode 100644
index 0000000..118ce22
--- /dev/null
+++ b/aux_stubs.c
@@ -0,0 +1,31 @@
+#include <string.h>
+#include <sys/socket.h>
+#include <caml/mlvalues.h>
+#include <caml/alloc.h>
+#include <caml/signals.h>
+
+// These are from .../otherlibs/unix/unixsupport.h
+#define UNIX_BUFFER_SIZE 16384
+extern void uerror (char * cmdname, value arg) Noreturn;
+
+static int msg_flag_table[] = {
+ MSG_OOB, MSG_DONTROUTE, MSG_PEEK, MSG_NOSIGNAL
+};
+
+CAMLprim value aux_send(value sock, value buff, value ofs, value len,
+ value flags)
+{
+ int ret, cv_flags;
+ long numbytes;
+ char iobuf[UNIX_BUFFER_SIZE];
+
+ cv_flags = convert_flag_list(flags, msg_flag_table);
+ numbytes = Long_val(len);
+ if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
+ memmove(iobuf, &Byte(buff, Long_val(ofs)), numbytes);
+ enter_blocking_section();
+ ret = send(Int_val(sock), iobuf, (int) numbytes, cv_flags);
+ leave_blocking_section();
+ if (ret == -1) uerror("send", (value) 0);
+ return Val_int(ret);
+}
diff --git a/syslog.ml b/syslog.ml
index c6c66f4..80e179c 100644
--- a/syslog.ml
+++ b/syslog.ml
@@ -191,14 +191,11 @@ let protected_write loginfo str =
(try open_connection loginfo with _ -> ());
if List.mem `LOG_CONS loginfo.flags then log_console str
in
- let prev = Sys.signal Sys.sigpipe (Sys.Signal_handle fallback) in
try
- ignore (write loginfo.fd str 0 (String.length str));
- Sys.set_signal Sys.sigpipe prev
+ ignore (Aux.send loginfo.fd str 0 (String.length str) [Aux.MSG_NOSIGNAL])
with Unix_error (_, _, _) ->
(* on error, attempt to reconnect *)
- fallback ();
- Sys.set_signal Sys.sigpipe prev
+ fallback ()
let syslog ?fac loginfo lev str =
let msg = Buffer.create 64 in
--
syslog-ocaml packaging
More information about the Pkg-ocaml-maint-commits
mailing list