io.c merged

cvs
Slava Pestov 2004-12-11 03:21:08 +00:00
parent e78228ded5
commit c88fb98ef8
4 changed files with 76 additions and 4 deletions

View File

@ -8,8 +8,6 @@ F_PORT* untag_port(CELL tagged)
/* after image load & save, ports are no longer valid */ /* after image load & save, ports are no longer valid */
if(p->fd == -1) if(p->fd == -1)
general_error(ERROR_EXPIRED,tagged); general_error(ERROR_EXPIRED,tagged);
/* if(p->closed)
general_error(ERROR_CLOSED,tagged); */
return p; return p;
} }
@ -47,7 +45,7 @@ void init_line_buffer(F_PORT* port, F_FIXNUM count)
void fixup_port(F_PORT* port) void fixup_port(F_PORT* port)
{ {
port->fd = -1; port->fd = (F_FIXNUM)INVALID_HANDLE_VALUE;
fixup(&port->buffer); fixup(&port->buffer);
fixup(&port->line); fixup(&port->line);
fixup(&port->client_host); fixup(&port->client_host);
@ -64,6 +62,29 @@ void collect_port(F_PORT* port)
copy_object(&port->io_error); copy_object(&port->io_error);
} }
#ifdef WIN32
CELL make_io_error(const char* func)
{
char *buffer;
F_STRING *function = from_c_string(func);
F_STRING *error;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &buffer,
0, NULL);
error = from_c_string(buffer);
LocalFree(buffer);
return cons(tag_object(function),cons(tag_object(error),F));
}
#else
CELL make_io_error(const char* func) CELL make_io_error(const char* func)
{ {
F_STRING* function = from_c_string(func); F_STRING* function = from_c_string(func);
@ -71,6 +92,7 @@ CELL make_io_error(const char* func)
return cons(tag_object(function),cons(tag_object(error),F)); return cons(tag_object(function),cons(tag_object(error),F));
} }
#endif
void postpone_io_error(F_PORT* port, const char* func) void postpone_io_error(F_PORT* port, const char* func)
{ {

View File

@ -1,5 +1,9 @@
#define BUF_SIZE (8 * 1024) #define BUF_SIZE (8 * 1024)
#ifndef WIN32
#define INVALID_HANDLE_VALUE -1
#endif
typedef enum { typedef enum {
PORT_READ, PORT_READ,
PORT_RECV, PORT_RECV,

View File

@ -1,4 +1,4 @@
#include "factor.h" #include "../factor.h"
void init_io_tasks(fd_set* fdset, IO_TASK* io_tasks) void init_io_tasks(fd_set* fdset, IO_TASK* io_tasks)
{ {

46
native/win32/io.c Normal file
View File

@ -0,0 +1,46 @@
#include "../factor.h"
HANDLE completion_port = INVALID_HANDLE_VALUE;
CELL callback_list = F;
void init_io (void)
{
completion_port = CreateIoCompletionPort(
INVALID_HANDLE_VALUE, NULL, 0, 1);
if (completion_port == INVALID_HANDLE_VALUE)
io_error(__FUNCTION__);
userenv[STDIN_ENV] = tag_object(port(PORT_READ, (CELL)GetStdHandle(STD_INPUT_HANDLE)));
userenv[STDOUT_ENV] = tag_object(port(PORT_WRITE, (CELL)GetStdHandle(STD_OUTPUT_HANDLE)));
}
void primitive_add_copy_io_task (void)
{
io_error(__FUNCTION__);
}
void primitive_close (void)
{
PORT *port = untag_port(dpop());
CloseHandle((HANDLE)port->fd);
port->closed = true;
}
void primitive_next_io_task (void)
{
if (callback_list != F)
{
CONS *cons = untag_cons(callback_list);
CELL car = cons->car;
callback_list = cons->cdr;
dpush(car);
}
else
dpush(F);
}
void collect_io_tasks (void)
{
copy_object(&callback_list);
}