54 |
|
|
55 |
#include <errno.h> |
#include <errno.h> |
56 |
|
|
57 |
void write_timeout_error(); |
static void write_timeout_error(); |
58 |
void connection_failure(); |
static void connection_failure(); |
59 |
|
|
60 |
#ifdef __MINGW32__ |
#ifdef __MINGW32__ |
61 |
/* Keep track of socket initialisations */ |
/* Keep track of socket initialisations */ |
101 |
#define BIND_LAST_ADDRESS 65534 |
#define BIND_LAST_ADDRESS 65534 |
102 |
static unsigned int iLastAddressUsed = BIND_INITIAL_ADDRESS; |
static unsigned int iLastAddressUsed = BIND_INITIAL_ADDRESS; |
103 |
|
|
104 |
DEFUN("OPEN-NAMED-SOCKET",object,fSopen_named_socket,SI,1,1,NONE,OI,OO,OO,OO, |
DEFUN_NEW("OPEN-NAMED-SOCKET",object,fSopen_named_socket,SI,1,1,NONE,OI,OO,OO,OO,(int port), |
105 |
"Open a socket on PORT and return (cons fd portname) where file \ |
"Open a socket on PORT and return (cons fd portname) where file \ |
106 |
descriptor is a small fixnum which is the write file descriptor for \ |
descriptor is a small fixnum which is the write file descriptor for \ |
107 |
the socket. If PORT is zero do automatic allocation of port") |
the socket. If PORT is zero do automatic allocation of port") |
|
(port) |
|
|
int port; |
|
108 |
{ int s, n, rc; struct |
{ int s, n, rc; struct |
109 |
sockaddr_in addr; |
sockaddr_in addr; |
110 |
|
|
178 |
return make_cons(make_fixnum(s), make_fixnum(ntohs(addr.sin_port))); |
return make_cons(make_fixnum(s), make_fixnum(ntohs(addr.sin_port))); |
179 |
} |
} |
180 |
|
|
181 |
DEFUN("CLOSE-FD",object,fSclose_fd,SI,1,1,NONE,OI,OO,OO,OO, |
DEFUN_NEW("CLOSE-FD",object,fSclose_fd,SI,1,1,NONE,OI,OO,OO,OO,(int fd), |
182 |
"Close the file descriptor FD")(fd) |
"Close the file descriptor FD") |
183 |
int fd; |
|
184 |
{RETURN1(0==close(fd) ? Ct : Cnil);} |
{RETURN1(0==close(fd) ? Ct : Cnil);} |
185 |
|
|
186 |
DEFUN("CLOSE-SD",object,fSclose_sfd,SI,1,1,NONE,OO,OO,OO,OO, |
DEFUN_NEW("CLOSE-SD",object,fSclose_sfd,SI,1,1,NONE,OO,OO,OO,OO,(object sfd), |
187 |
"Close the socket connection sfd")(sfd) |
"Close the socket connection sfd") |
188 |
object sfd; |
|
189 |
{ int res; |
{ int res; |
190 |
free(OBJ_TO_CONNECTION_STATE(sfd)->read_buffer); |
free(OBJ_TO_CONNECTION_STATE(sfd)->read_buffer); |
191 |
res = close(OBJ_TO_CONNECTION_STATE(sfd)->fd); |
res = close(OBJ_TO_CONNECTION_STATE(sfd)->fd); |
197 |
} |
} |
198 |
|
|
199 |
|
|
200 |
DEFUN("ACCEPT-SOCKET-CONNECTION",object,fSaccept_socket_connection, |
DEFUN_NEW("ACCEPT-SOCKET-CONNECTION",object,fSaccept_socket_connection, |
201 |
SI,1,1,NONE,OO,OO,OO,OO, |
SI,1,1,NONE,OO,OO,OO,OO,(object named_socket), |
202 |
"Given a NAMED_SOCKET it waits for a connection on this \ |
"Given a NAMED_SOCKET it waits for a connection on this \ |
203 |
and returns (list* named_socket fd name1) when one is established") |
and returns (list* named_socket fd name1) when one is established") |
204 |
(named_socket) |
|
|
object named_socket; |
|
205 |
{ |
{ |
206 |
int n, fd; |
int n, fd; |
207 |
struct sockaddr_in addr; |
struct sockaddr_in addr; |
224 |
); |
); |
225 |
} |
} |
226 |
|
|
227 |
object |
/* static object */ |
228 |
sock_hostname_to_hostid_list(host_name) |
/* sock_hostname_to_hostid_list(host_name) */ |
229 |
char *host_name; |
/* char *host_name; */ |
230 |
{ |
/* { */ |
231 |
struct hostent *h; |
/* struct hostent *h; */ |
232 |
object addr_list = Cnil; |
/* object addr_list = Cnil; */ |
233 |
int i; |
/* int i; */ |
234 |
|
|
235 |
h = gethostbyname(host_name); |
/* h = gethostbyname(host_name); */ |
236 |
|
|
237 |
for (i = 0; h->h_addr_list[i] != 0; i++) |
/* for (i = 0; h->h_addr_list[i] != 0; i++) */ |
238 |
{ |
/* { */ |
239 |
addr_list = make_cons(make_simple_string(inet_ntoa(*(struct in_addr *)h->h_addr_list[i])), addr_list); |
/* addr_list = make_cons(make_simple_string(inet_ntoa(*(struct in_addr *)h->h_addr_list[i])), addr_list); */ |
240 |
} |
/* } */ |
241 |
return addr_list; |
/* return addr_list; */ |
242 |
} |
/* } */ |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
DEFUN("HOSTNAME-TO-HOSTID",object,fShostname_to_hostid,SI,1,1, |
DEFUN_NEW("HOSTNAME-TO-HOSTID",object,fShostname_to_hostid,SI,1,1, |
248 |
NONE,OO,OO,OO,OO,"")(object host) |
NONE,OO,OO,OO,OO,(object host),"") |
249 |
{ |
{ |
250 |
struct hostent *h; |
struct hostent *h; |
251 |
char buf[300]; |
char buf[300]; |
259 |
else return Cnil; |
else return Cnil; |
260 |
} |
} |
261 |
|
|
262 |
DEFUN("GETHOSTNAME",object,fSgethostname,SI,0,0,NONE,OO,OO,OO,OO, |
DEFUN_NEW("GETHOSTNAME",object,fSgethostname,SI,0,0,NONE,OO,OO,OO,OO,(void), |
263 |
"Returns HOSTNAME of the local host") |
"Returns HOSTNAME of the local host") |
264 |
() |
|
265 |
{char buf[300]; |
{char buf[300]; |
266 |
if (0 == gethostname(buf,sizeof(buf))) |
if (0 == gethostname(buf,sizeof(buf))) |
267 |
return make_simple_string(buf); |
return make_simple_string(buf); |
268 |
else return Cnil; |
else return Cnil; |
269 |
} |
} |
270 |
|
|
271 |
DEFUN("HOSTID-TO-HOSTNAME",object,fShostid_to_hostname,SI, |
DEFUN_NEW("HOSTID-TO-HOSTNAME",object,fShostid_to_hostname,SI, |
272 |
1,10,NONE,OO,OO,OO,OO,"") |
1,10,NONE,OO,OO,OO,OO,(object host_id),"") |
273 |
(host_id) |
|
|
object host_id; |
|
274 |
{char *hostid; |
{char *hostid; |
275 |
struct in_addr addr; |
struct in_addr addr; |
276 |
struct hostent *h; |
struct hostent *h; |
284 |
return Cnil; |
return Cnil; |
285 |
} |
} |
286 |
|
|
287 |
object |
/* static object */ |
288 |
sock_get_name(s) |
/* sock_get_name(s) */ |
289 |
int s; |
/* int s; */ |
290 |
{ |
/* { */ |
291 |
struct sockaddr_in addr; |
/* struct sockaddr_in addr; */ |
292 |
int m = sizeof(addr); |
/* int m = sizeof(addr); */ |
293 |
getsockname(s, (struct sockaddr *)&addr, &m); |
/* getsockname(s, (struct sockaddr *)&addr, &m); */ |
294 |
return make_cons( |
/* return make_cons( */ |
295 |
make_cons( |
/* make_cons( */ |
296 |
make_fixnum(addr.sin_port) |
/* make_fixnum(addr.sin_port) */ |
297 |
, make_simple_string(inet_ntoa(addr.sin_addr)) |
/* , make_simple_string(inet_ntoa(addr.sin_addr)) */ |
298 |
) |
/* ) */ |
299 |
,make_cons(make_fixnum(addr.sin_family) |
/* ,make_cons(make_fixnum(addr.sin_family) */ |
300 |
, make_fixnum(s)) |
/* , make_fixnum(s)) */ |
301 |
); |
/* ); */ |
302 |
} |
/* } */ |
303 |
|
|
304 |
#include "comm.c" |
#include "comm.c" |
305 |
|
|
306 |
|
|
307 |
DEFUN("CONNECTION-STATE-FD",object,fSconnection_state_fd,SI,1,1,NONE,OO,OO,OO,OO,"") (sfd) |
DEFUN_NEW("CONNECTION-STATE-FD",object,fSconnection_state_fd,SI,1,1,NONE,OO,OO,OO,OO,(object sfd),"") |
|
object sfd; |
|
308 |
{ return make_fixnum(OBJ_TO_CONNECTION_STATE(sfd)->fd); |
{ return make_fixnum(OBJ_TO_CONNECTION_STATE(sfd)->fd); |
309 |
} |
} |
310 |
|
|
311 |
DEFUN("OUR-WRITE",object,fSour_write,SI,3,3,NONE,OO,OI,OO,OO,"") |
DEFUN_NEW("OUR-WRITE",object,fSour_write,SI,3,3,NONE,OO,OI,OO,OO,(object sfd,object buffer,int nbytes),"") |
312 |
(sfd,buffer,nbytes) |
|
|
object buffer; |
|
|
object sfd; |
|
|
int nbytes; |
|
313 |
{ return make_fixnum(write1(OBJ_TO_CONNECTION_STATE(sfd),buffer->ust.ust_self,nbytes)); |
{ return make_fixnum(write1(OBJ_TO_CONNECTION_STATE(sfd),buffer->ust.ust_self,nbytes)); |
314 |
} |
} |
315 |
|
|
316 |
DEFUN("OUR-READ-WITH-OFFSET",object,fSour_read_with_offset,SI,5,5,NONE, |
DEFUN_NEW("OUR-READ-WITH-OFFSET",object,fSour_read_with_offset,SI,5,5,NONE, |
317 |
OO,OI,II,OO, |
OO,OI,II,OO,(object fd,object buffer,int offset,int nbytes,int timeout), |
318 |
"Read from STATE-FD into string BUFFER putting data at OFFSET and reading NBYTES, waiting for TIMEOUT before failing") |
"Read from STATE-FD into string BUFFER putting data at OFFSET and reading NBYTES, waiting for TIMEOUT before failing") |
319 |
(fd,buffer,offset,nbytes,timeout) |
|
|
int offset,nbytes,timeout; |
|
|
object buffer,fd; |
|
320 |
{ return make_fixnum(read1(OBJ_TO_CONNECTION_STATE(fd),&((buffer)->ust.ust_self[offset]),nbytes,timeout)); |
{ return make_fixnum(read1(OBJ_TO_CONNECTION_STATE(fd),&((buffer)->ust.ust_self[offset]),nbytes,timeout)); |
321 |
} |
} |
322 |
|
|
347 |
|
|
348 |
static int needs_quoting[256]; |
static int needs_quoting[256]; |
349 |
|
|
350 |
DEFUN("PRINT-TO-STRING1",object,fSprint_to_string1,SI,3,3,NONE,OO,OO,OO,OO, |
DEFUN_NEW("PRINT-TO-STRING1",object,fSprint_to_string1,SI,3,3,NONE,OO,OO,OO,OO,(object str,object x,object the_code), |
351 |
"Print to STRING the object X according to CODE. The string must have \ |
"Print to STRING the object X according to CODE. The string must have \ |
352 |
fill pointer, and this will be advanced.") |
fill pointer, and this will be advanced.") |
353 |
(str,x,the_code) |
|
|
object str,x; |
|
|
object the_code; |
|
354 |
{ enum type t = type_of(x); |
{ enum type t = type_of(x); |
355 |
int fp = str->st.st_fillp; |
int fp = str->st.st_fillp; |
356 |
char *xx = &(str->st.st_self[fp]); |
char *xx = &(str->st.st_self[fp]); |
468 |
} |
} |
469 |
} |
} |
470 |
|
|
471 |
void |
static void |
472 |
not_defined_for_os() |
not_defined_for_os() |
473 |
{ FEerror("Function not defined for this operating system",0);} |
{ FEerror("Function not defined for this operating system",0);} |
474 |
|
|
475 |
|
|
476 |
DEFUN("SET-SIGIO-FOR-FD",object,fSset_sigio_for_fd,SI,1,1,NONE,OI,OO,OO,OO,"") |
DEFUN_NEW("SET-SIGIO-FOR-FD",object,fSset_sigio_for_fd,SI,1,1,NONE,OI,OO,OO,OO,(int fd),"") |
477 |
(fd) |
|
|
int fd; |
|
478 |
{ |
{ |
479 |
/* for the moment we will use SIGUSR1 to notify, instead of depending on SIGIO, |
/* for the moment we will use SIGUSR1 to notify, instead of depending on SIGIO, |
480 |
since LINUX does not support the latter yet... |
since LINUX does not support the latter yet... |
502 |
|
|
503 |
} |
} |
504 |
|
|
505 |
DEFUN("RESET-STRING-INPUT-STREAM",object,fSreset_string_input_stream,SI,4,4,NONE,OO,OI,IO,OO, |
DEFUN_NEW("RESET-STRING-INPUT-STREAM",object,fSreset_string_input_stream,SI,4,4,NONE,OO,OI,IO,OO,(object strm,object string,int start,int end), |
506 |
"Reuse a string output STREAM by setting its output to STRING \ |
"Reuse a string output STREAM by setting its output to STRING \ |
507 |
and positioning the ouput/input to start at START and end at END") |
and positioning the ouput/input to start at START and end at END") |
508 |
(strm,string,start,end) |
|
|
object strm,string; |
|
|
int start,end; |
|
509 |
{ strm->sm.sm_object0 = string; |
{ strm->sm.sm_object0 = string; |
510 |
strm->sm.sm_int0 = start; |
strm->sm.sm_int0 = start; |
511 |
strm->sm.sm_int1 = end; |
strm->sm.sm_int1 = end; |
512 |
return strm; |
return strm; |
513 |
} |
} |
514 |
|
|
515 |
DEFUN("CHECK-STATE-INPUT",object,fScheck_state_input,SI,2,2,NONE,OO,IO,OO,OO, |
DEFUN_NEW("CHECK-STATE-INPUT",object,fScheck_state_input,SI,2,2,NONE,OO,IO,OO,OO,(object osfd,int timeout), |
516 |
"") (osfd,timeout) |
"") |
|
object osfd; |
|
|
int timeout; |
|
517 |
{ |
{ |
518 |
return fScheck_dsfd_for_input(OBJ_TO_CONNECTION_STATE(osfd),timeout); |
return fScheck_dsfd_for_input(OBJ_TO_CONNECTION_STATE(osfd),timeout); |
519 |
|
|
520 |
} |
} |
521 |
|
|
522 |
DEFUN("CLEAR-CONNECTION-STATE",object,fSclear_connection_state, |
DEFUN_NEW("CLEAR-CONNECTION-STATE",object,fSclear_connection_state, |
523 |
SI,1,1,NONE,OO,OO,OO,OO, |
SI,1,1,NONE,OO,OO,OO,OO,(object osfd), |
524 |
"Read on FD until nothing left to read. Return number of bytes read") |
"Read on FD until nothing left to read. Return number of bytes read") |
525 |
(osfd) |
|
|
object osfd; |
|
526 |
{ |
{ |
527 |
struct connection_state *sfd = OBJ_TO_CONNECTION_STATE(osfd); |
struct connection_state *sfd = OBJ_TO_CONNECTION_STATE(osfd); |
528 |
int n=fix(fSclear_connection(sfd->fd)); |
int n=fix(fSclear_connection(sfd->fd)); |
535 |
|
|
536 |
#endif |
#endif |
537 |
|
|
538 |
void |
static void |
539 |
write_timeout_error(s) |
write_timeout_error(s) |
540 |
char *s; |
char *s; |
541 |
{FEerror("Write timeout: ~s",1,make_simple_string(s)); |
{FEerror("Write timeout: ~s",1,make_simple_string(s)); |
542 |
} |
} |
543 |
|
|
544 |
void |
static void |
545 |
connection_failure(s) |
connection_failure(s) |
546 |
char *s; |
char *s; |
547 |
{FEerror("Connect failure: ~s",1,make_simple_string(s)); |
{FEerror("Connect failure: ~s",1,make_simple_string(s)); |