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
|
#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);
}
|