2004-08-12 17:36:36 -04:00
|
|
|
#include "factor.h"
|
|
|
|
|
|
|
|
PORT* untag_port(CELL tagged)
|
|
|
|
{
|
|
|
|
PORT* p;
|
|
|
|
type_check(PORT_TYPE,tagged);
|
|
|
|
p = (PORT*)UNTAG(tagged);
|
|
|
|
/* after image load & save, ports are no longer valid */
|
|
|
|
if(p->fd == -1)
|
|
|
|
general_error(ERROR_PORT_EXPIRED,tagged);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2004-08-16 19:29:07 -04:00
|
|
|
PORT* port(PORT_MODE type, CELL fd)
|
2004-08-12 17:36:36 -04:00
|
|
|
{
|
|
|
|
PORT* port = allot_object(PORT_TYPE,sizeof(PORT));
|
2004-08-16 19:29:07 -04:00
|
|
|
port->type = type;
|
2004-08-12 17:36:36 -04:00
|
|
|
port->fd = fd;
|
2004-08-12 23:40:28 -04:00
|
|
|
port->buffer = NULL;
|
2004-08-15 21:50:44 -04:00
|
|
|
port->line = F;
|
2004-08-15 22:45:08 -04:00
|
|
|
port->client_host = F;
|
|
|
|
port->client_port = F;
|
|
|
|
port->client_socket = F;
|
2004-08-16 19:29:07 -04:00
|
|
|
port->line = F;
|
2004-08-16 20:42:30 -04:00
|
|
|
port->line_ready = false;
|
2004-08-12 17:36:36 -04:00
|
|
|
port->buf_fill = 0;
|
|
|
|
port->buf_pos = 0;
|
2004-08-15 21:50:44 -04:00
|
|
|
|
2004-08-16 19:29:07 -04:00
|
|
|
if(type == PORT_SPECIAL)
|
|
|
|
port->buffer = NULL;
|
|
|
|
else
|
|
|
|
port->buffer = string(BUF_SIZE,'\0');
|
|
|
|
|
2004-08-15 21:50:44 -04:00
|
|
|
if(fcntl(port->fd,F_SETFL,O_NONBLOCK,1) == -1)
|
2004-08-18 15:23:42 -04:00
|
|
|
io_error(__FUNCTION__);
|
2004-08-15 21:50:44 -04:00
|
|
|
|
|
|
|
return port;
|
2004-08-12 17:36:36 -04:00
|
|
|
}
|
|
|
|
|
2004-08-20 01:49:14 -04:00
|
|
|
void init_line_buffer(PORT* port, FIXNUM count)
|
|
|
|
{
|
|
|
|
if(port->line == F)
|
|
|
|
port->line = tag_object(sbuf(LINE_SIZE));
|
|
|
|
else
|
|
|
|
untag_sbuf(port->line)->top = 0;
|
|
|
|
}
|
|
|
|
|
2004-08-12 17:36:36 -04:00
|
|
|
void primitive_portp(void)
|
|
|
|
{
|
|
|
|
drepl(tag_boolean(typep(PORT_TYPE,dpeek())));
|
|
|
|
}
|
|
|
|
|
|
|
|
void fixup_port(PORT* port)
|
|
|
|
{
|
|
|
|
port->fd = -1;
|
|
|
|
if(port->buffer != 0)
|
2004-08-12 23:40:28 -04:00
|
|
|
port->buffer = fixup_untagged_string(port->buffer);
|
2004-08-15 21:50:44 -04:00
|
|
|
fixup(&port->line);
|
2004-08-15 22:45:08 -04:00
|
|
|
fixup(&port->client_host);
|
|
|
|
fixup(&port->client_port);
|
2004-08-12 17:36:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void collect_port(PORT* port)
|
|
|
|
{
|
|
|
|
if(port->buffer != 0)
|
2004-08-12 23:40:28 -04:00
|
|
|
port->buffer = copy_untagged_string(port->buffer);
|
2004-08-15 21:50:44 -04:00
|
|
|
copy_object(&port->line);
|
2004-08-15 22:45:08 -04:00
|
|
|
copy_object(&port->client_host);
|
|
|
|
copy_object(&port->client_port);
|
2004-08-12 17:36:36 -04:00
|
|
|
}
|