File: aux_stubs.c

package info (click to toggle)
syslog-ocaml 1.4-6
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 260 kB
  • ctags: 173
  • sloc: ml: 414; makefile: 36; ansic: 26
file content (31 lines) | stat: -rw-r--r-- 917 bytes parent folder | download | duplicates (3)
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);
}