1996-09-04 07:17:43 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
|
|
|
/* Objective Caml */
|
|
|
|
/* */
|
|
|
|
/* Xavier Leroy and Pascal Cuoq, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../../LICENSE. */
|
1996-09-04 07:17:43 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <mlvalues.h>
|
|
|
|
#include <alloc.h>
|
|
|
|
#include <memory.h>
|
2002-06-07 02:49:45 -07:00
|
|
|
#include <signals.h>
|
1996-09-05 06:32:25 -07:00
|
|
|
#include "unixsupport.h"
|
1996-09-04 07:17:43 -07:00
|
|
|
#include "socketaddr.h"
|
|
|
|
|
|
|
|
static int msg_flag_table[] = {
|
|
|
|
MSG_OOB, MSG_DONTROUTE, MSG_PEEK
|
|
|
|
};
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_recv(value sock, value buff, value ofs, value len, value flags)
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
|
|
|
int ret;
|
1997-09-02 09:01:39 -07:00
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
|
|
|
|
|
|
|
Begin_root (buff);
|
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
|
|
|
enter_blocking_section();
|
2002-04-30 08:00:48 -07:00
|
|
|
ret = recv(Socket_val(sock), iobuf, (int) numbytes,
|
1999-11-29 11:04:56 -08:00
|
|
|
convert_flag_list(flags, msg_flag_table));
|
1997-09-02 09:01:39 -07:00
|
|
|
leave_blocking_section();
|
2001-12-03 02:33:39 -08:00
|
|
|
if (ret == -1) {
|
|
|
|
win32_maperr(WSAGetLastError());
|
|
|
|
uerror("recv", Nothing);
|
|
|
|
}
|
2000-11-23 05:45:03 -08:00
|
|
|
memmove (&Byte(buff, Long_val(ofs)), iobuf, ret);
|
1997-09-02 09:01:39 -07:00
|
|
|
End_roots();
|
1996-09-04 07:17:43 -07:00
|
|
|
return Val_int(ret);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_recvfrom(value sock, value buff, value ofs, value len, value flags)
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
1997-09-02 09:01:39 -07:00
|
|
|
int ret;
|
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
1996-09-04 07:17:43 -07:00
|
|
|
value res;
|
1997-05-26 10:16:31 -07:00
|
|
|
value adr = Val_unit;
|
2000-03-16 05:35:20 -08:00
|
|
|
union sock_addr_union addr;
|
|
|
|
socklen_param_type addr_len;
|
1996-09-04 07:17:43 -07:00
|
|
|
|
1997-09-02 09:01:39 -07:00
|
|
|
Begin_roots2 (buff, adr);
|
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
2000-03-16 05:35:20 -08:00
|
|
|
addr_len = sizeof(sock_addr);
|
1997-05-26 10:16:31 -07:00
|
|
|
enter_blocking_section();
|
2002-04-30 08:00:48 -07:00
|
|
|
ret = recvfrom(Socket_val(sock),
|
1999-11-29 11:04:56 -08:00
|
|
|
iobuf, (int) numbytes,
|
|
|
|
convert_flag_list(flags, msg_flag_table),
|
2000-03-16 05:35:20 -08:00
|
|
|
&addr.s_gen, &addr_len);
|
1997-05-26 10:16:31 -07:00
|
|
|
leave_blocking_section();
|
2001-12-03 02:33:39 -08:00
|
|
|
if (ret == -1) {
|
|
|
|
win32_maperr(WSAGetLastError());
|
|
|
|
uerror("recvfrom", Nothing);
|
|
|
|
}
|
2000-11-23 05:45:03 -08:00
|
|
|
memmove (&Byte(buff, Long_val(ofs)), iobuf, ret);
|
2000-03-16 05:35:20 -08:00
|
|
|
adr = alloc_sockaddr(&addr, addr_len);
|
1998-10-26 11:19:32 -08:00
|
|
|
res = alloc_small(2, 0);
|
1997-09-02 09:01:39 -07:00
|
|
|
Field(res, 0) = Val_int(ret);
|
1997-05-26 10:16:31 -07:00
|
|
|
Field(res, 1) = adr;
|
|
|
|
End_roots();
|
1996-09-04 07:17:43 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_send(value sock, value buff, value ofs, value len, value flags)
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
|
|
|
int ret;
|
1997-09-02 09:01:39 -07:00
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
|
|
|
|
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
2000-11-23 05:45:03 -08:00
|
|
|
memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes);
|
1996-09-04 07:17:43 -07:00
|
|
|
enter_blocking_section();
|
2002-04-30 08:00:48 -07:00
|
|
|
ret = send(Socket_val(sock), iobuf, (int) numbytes,
|
1996-09-04 07:17:43 -07:00
|
|
|
convert_flag_list(flags, msg_flag_table));
|
|
|
|
leave_blocking_section();
|
2001-12-03 02:33:39 -08:00
|
|
|
if (ret == -1) {
|
|
|
|
win32_maperr(WSAGetLastError());
|
|
|
|
uerror("send", Nothing);
|
|
|
|
}
|
1996-09-04 07:17:43 -07:00
|
|
|
return Val_int(ret);
|
|
|
|
}
|
|
|
|
|
1997-09-02 09:01:39 -07:00
|
|
|
value unix_sendto_native(value sock, value buff, value ofs, value len, value flags, value dest)
|
1996-09-04 07:17:43 -07:00
|
|
|
{
|
|
|
|
int ret;
|
1997-09-02 09:01:39 -07:00
|
|
|
long numbytes;
|
|
|
|
char iobuf[UNIX_BUFFER_SIZE];
|
2000-03-16 05:35:20 -08:00
|
|
|
union sock_addr_union addr;
|
|
|
|
socklen_param_type addr_len;
|
1997-09-02 09:01:39 -07:00
|
|
|
|
2000-03-16 05:35:20 -08:00
|
|
|
get_sockaddr(dest, &addr, &addr_len);
|
1997-09-02 09:01:39 -07:00
|
|
|
numbytes = Long_val(len);
|
|
|
|
if (numbytes > UNIX_BUFFER_SIZE) numbytes = UNIX_BUFFER_SIZE;
|
2000-11-23 05:45:03 -08:00
|
|
|
memmove (iobuf, &Byte(buff, Long_val(ofs)), numbytes);
|
1996-09-04 07:17:43 -07:00
|
|
|
enter_blocking_section();
|
2002-04-30 08:00:48 -07:00
|
|
|
ret = sendto(Socket_val(sock),
|
1999-11-29 11:04:56 -08:00
|
|
|
iobuf, (int) numbytes,
|
1997-09-02 09:01:39 -07:00
|
|
|
convert_flag_list(flags, msg_flag_table),
|
2000-03-16 05:35:20 -08:00
|
|
|
&addr.s_gen, addr_len);
|
1996-09-04 07:17:43 -07:00
|
|
|
leave_blocking_section();
|
2001-12-03 02:33:39 -08:00
|
|
|
if (ret == -1) {
|
|
|
|
win32_maperr(WSAGetLastError());
|
|
|
|
uerror("sendto", Nothing);
|
|
|
|
}
|
1996-09-04 07:17:43 -07:00
|
|
|
return Val_int(ret);
|
|
|
|
}
|
|
|
|
|
2001-08-28 07:47:48 -07:00
|
|
|
CAMLprim value unix_sendto(argv, argc)
|
1996-09-04 07:17:43 -07:00
|
|
|
value * argv;
|
|
|
|
int argc;
|
|
|
|
{
|
|
|
|
return unix_sendto_native
|
|
|
|
(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
|
|
|
|
}
|