1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* Automatique. Distributed only by permission. */
|
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1997-06-13 08:52:43 -07:00
|
|
|
#include <string.h>
|
1995-05-08 08:18:32 -07:00
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
1997-05-13 08:46:49 -07:00
|
|
|
#include <signals.h>
|
1996-09-04 07:15:31 -07:00
|
|
|
#include "unixsupport.h"
|
1995-05-08 08:18:32 -07:00
|
|
|
|
|
|
|
#ifdef HAS_SOCKETS
|
|
|
|
#include "socketaddr.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAS_SOCKETS) && defined(MSG_OOB) && defined(MSG_DONTROUTE) && defined(MSG_PEEK)
|
|
|
|
|
|
|
|
static int msg_flag_table[] = {
|
|
|
|
MSG_OOB, MSG_DONTROUTE, MSG_PEEK
|
|
|
|
};
|
|
|
|
|
|
|
|
value unix_recv(sock, buff, ofs, len, flags) /* ML */
|
|
|
|
value sock, buff, ofs, len, flags;
|
|
|
|
{
|
|
|
|
int ret;
|
1997-05-13 08:46:49 -07:00
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
|
|
|
|
1997-05-26 10:16:31 -07:00
|
|
|
Begin_root (buff);
|
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
|
|
|
enter_blocking_section();
|
|
|
|
ret = recv(Int_val(sock), iobuf, (int) numbytes,
|
|
|
|
convert_flag_list(flags, msg_flag_table));
|
|
|
|
leave_blocking_section();
|
|
|
|
if (ret == -1) uerror("recv", Nothing);
|
|
|
|
bcopy(iobuf, &Byte(buff, Long_val(ofs)), ret);
|
|
|
|
End_roots();
|
1995-05-08 08:18:32 -07:00
|
|
|
return Val_int(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
value unix_recvfrom(sock, buff, ofs, len, flags) /* ML */
|
|
|
|
value sock, buff, ofs, len, flags;
|
|
|
|
{
|
1997-05-13 08:46:49 -07:00
|
|
|
int ret;
|
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
1995-05-08 08:18:32 -07:00
|
|
|
value res;
|
1997-05-26 10:16:31 -07:00
|
|
|
value adr = Val_unit;
|
1995-05-08 08:18:32 -07:00
|
|
|
|
1997-05-26 10:16:31 -07:00
|
|
|
Begin_roots2 (buff, adr);
|
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
|
|
|
sock_addr_len = sizeof(sock_addr);
|
|
|
|
enter_blocking_section();
|
|
|
|
ret = recvfrom(Int_val(sock), iobuf, (int) numbytes,
|
|
|
|
convert_flag_list(flags, msg_flag_table),
|
|
|
|
&sock_addr.s_gen, &sock_addr_len);
|
|
|
|
leave_blocking_section();
|
|
|
|
if (ret == -1) uerror("recvfrom", Nothing);
|
|
|
|
bcopy(iobuf, &Byte(buff, Long_val(ofs)), ret);
|
|
|
|
adr = alloc_sockaddr();
|
|
|
|
res = alloc_tuple(2);
|
|
|
|
Field(res, 0) = Val_int(ret);
|
|
|
|
Field(res, 1) = adr;
|
|
|
|
End_roots();
|
1995-05-08 08:18:32 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
value unix_send(sock, buff, ofs, len, flags) /* ML */
|
|
|
|
value sock, buff, ofs, len, flags;
|
|
|
|
{
|
|
|
|
int ret;
|
1997-05-13 08:46:49 -07:00
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
|
|
|
|
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
|
|
|
bcopy(&Byte(buff, Long_val(ofs)), iobuf, numbytes);
|
1995-05-08 08:18:32 -07:00
|
|
|
enter_blocking_section();
|
1997-05-13 08:46:49 -07:00
|
|
|
ret = send(Int_val(sock), iobuf, (int) numbytes,
|
1995-05-08 08:18:32 -07:00
|
|
|
convert_flag_list(flags, msg_flag_table));
|
|
|
|
leave_blocking_section();
|
|
|
|
if (ret == -1) uerror("send", Nothing);
|
|
|
|
return Val_int(ret);
|
|
|
|
}
|
|
|
|
|
1995-10-23 09:58:06 -07:00
|
|
|
value unix_sendto_native(sock, buff, ofs, len, flags, dest)
|
|
|
|
value sock, buff, ofs, len, flags, dest;
|
1995-05-08 08:18:32 -07:00
|
|
|
{
|
|
|
|
int ret;
|
1997-05-13 08:46:49 -07:00
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
|
|
|
|
1995-10-23 09:58:06 -07:00
|
|
|
get_sockaddr(dest);
|
1997-05-13 08:46:49 -07:00
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
|
|
|
bcopy(&Byte(buff, Long_val(ofs)), iobuf, numbytes);
|
1995-05-08 08:18:32 -07:00
|
|
|
enter_blocking_section();
|
1997-05-13 08:46:49 -07:00
|
|
|
ret = sendto(Int_val(sock), iobuf, (int) numbytes,
|
|
|
|
convert_flag_list(flags, msg_flag_table),
|
1995-05-08 08:18:32 -07:00
|
|
|
&sock_addr.s_gen, sock_addr_len);
|
|
|
|
leave_blocking_section();
|
|
|
|
if (ret == -1) uerror("sendto", Nothing);
|
|
|
|
return Val_int(ret);
|
|
|
|
}
|
|
|
|
|
1995-10-23 09:58:06 -07:00
|
|
|
value unix_sendto(argv, argc) /* ML */
|
|
|
|
value * argv;
|
|
|
|
int argc;
|
|
|
|
{
|
|
|
|
return unix_sendto_native
|
|
|
|
(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
|
|
|
|
}
|
|
|
|
|
1995-05-08 08:18:32 -07:00
|
|
|
#else
|
|
|
|
|
|
|
|
value unix_recv() { invalid_argument("recv not implemented"); }
|
|
|
|
|
|
|
|
value unix_recvfrom() { invalid_argument("recvfrom not implemented"); }
|
|
|
|
|
|
|
|
value unix_send() { invalid_argument("send not implemented"); }
|
|
|
|
|
1995-10-23 09:58:06 -07:00
|
|
|
value unix_sendto_native() { invalid_argument("sendto not implemented"); }
|
|
|
|
|
1995-05-08 08:18:32 -07:00
|
|
|
value unix_sendto() { invalid_argument("sendto not implemented"); }
|
|
|
|
|
|
|
|
#endif
|