85 |
#include <elf_abi.h> |
#include <elf_abi.h> |
86 |
#endif |
#endif |
87 |
|
|
88 |
|
#ifndef __MINGW32__ |
89 |
|
# include <sys/socket.h> |
90 |
|
# include <netinet/in.h> |
91 |
|
# include <arpa/inet.h> |
92 |
|
#else |
93 |
|
# include <windows.h> |
94 |
|
# include <winsock2.h> |
95 |
|
#endif |
96 |
|
#include <errno.h> |
97 |
|
|
98 |
extern void tcpCloseSocket (int fd); |
extern void tcpCloseSocket (int fd); |
99 |
|
|
100 |
object terminal_io; |
object terminal_io; |
1216 |
switch (strm->sm.sm_mode) { |
switch (strm->sm.sm_mode) { |
1217 |
#ifdef HAVE_NSOCKET |
#ifdef HAVE_NSOCKET |
1218 |
case smm_socket: |
case smm_socket: |
1219 |
{ int ch = getCharGclSocket(strm,Cnil); |
{ |
1220 |
if (ch == EOF) return FALSE; |
fd_set fds; |
1221 |
else unreadc_stream(ch,strm); |
struct timeval tv; |
1222 |
return TRUE; |
FD_ZERO(&fds); |
1223 |
} |
FD_SET(SOCKET_STREAM_FD(strm),&fds); |
1224 |
|
memset(&tv,0,sizeof(tv)); |
1225 |
|
return select(SOCKET_STREAM_FD(strm)+1,&fds,NULL,NULL,&tv)>0 ? TRUE : FALSE; |
1226 |
|
} |
1227 |
|
/* { int ch = getCharGclSocket(strm,Cnil); */ |
1228 |
|
/* if (ch == EOF) return FALSE; */ |
1229 |
|
/* else unreadc_stream(ch,strm); */ |
1230 |
|
/* return TRUE; */ |
1231 |
|
/* } */ |
1232 |
#endif |
#endif |
1233 |
|
|
1234 |
case smm_input: |
case smm_input: |
2337 |
DEF_ORDINARY("SOCKET",sSsocket,SI,""); |
DEF_ORDINARY("SOCKET",sSsocket,SI,""); |
2338 |
|
|
2339 |
|
|
2340 |
|
@(static defun accept (x) |
2341 |
|
int fd,n; |
2342 |
|
struct sockaddr_in addr; |
2343 |
|
object server,host,port; |
2344 |
|
@ |
2345 |
|
if (type_of(x) != t_stream) |
2346 |
|
FEerror("~S is not a steam~%",1,x); |
2347 |
|
if (x->sm.sm_mode!=smm_two_way) |
2348 |
|
FEerror("~S is not a two-way steam~%",1,x); |
2349 |
|
fd=accept(SOCKET_STREAM_FD(STREAM_INPUT_STREAM(x)),(struct sockaddr *)&addr, &n); |
2350 |
|
if (fd <0) { |
2351 |
|
FEerror("Error ~S on accepting connection to ~S~%",1,make_simple_string(strerror(errno)),x); |
2352 |
|
x=Cnil; |
2353 |
|
} else { |
2354 |
|
server=STREAM_INPUT_STREAM(x)->sm.sm_object0->c.c_car; |
2355 |
|
host=STREAM_INPUT_STREAM(x)->sm.sm_object0->c.c_cdr->c.c_car; |
2356 |
|
port=STREAM_INPUT_STREAM(x)->sm.sm_object0->c.c_cdr->c.c_cdr->c.c_car; |
2357 |
|
x = make_two_way_stream |
2358 |
|
(make_socket_stream(fd,gcl_sm_input,server,host,port,Cnil), |
2359 |
|
make_socket_stream(fd,gcl_sm_output,server,host,port,Cnil)); |
2360 |
|
} |
2361 |
|
@(return `x`); |
2362 |
|
|
2363 |
|
|
2364 |
|
@) |
2365 |
|
|
|
|
|
2366 |
#endif /* HAVE_NSOCKET */ |
#endif /* HAVE_NSOCKET */ |
2367 |
|
|
2368 |
object standard_io; |
object standard_io; |
2491 |
make_si_function("FREAD",Lfread); |
make_si_function("FREAD",Lfread); |
2492 |
#ifdef HAVE_NSOCKET |
#ifdef HAVE_NSOCKET |
2493 |
make_si_function("SOCKET",Lsocket); |
make_si_function("SOCKET",Lsocket); |
2494 |
|
make_si_function("ACCEPT",Laccept); |
2495 |
#endif |
#endif |
2496 |
make_function("STREAMP", Lstreamp); |
make_function("STREAMP", Lstreamp); |
2497 |
make_function("INPUT-STREAM-P", Linput_stream_p); |
make_function("INPUT-STREAM-P", Linput_stream_p); |