From 514e97eaabc71fb78fabe1b17c052e5106ff648c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net> Date: Mon, 2 Mar 1998 03:20:07 -0800 Subject: [PATCH] Stdio.File->proxy() fixed Rev: src/modules/files/file.c:1.77 --- src/modules/files/file.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/modules/files/file.c b/src/modules/files/file.c index a7f4970a6b..ed3cc510c7 100644 --- a/src/modules/files/file.c +++ b/src/modules/files/file.c @@ -6,7 +6,7 @@ #define READ_BUFFER 8192 #include "global.h" -RCSID("$Id: file.c,v 1.76 1998/02/20 01:08:58 hubbe Exp $"); +RCSID("$Id: file.c,v 1.77 1998/03/02 11:20:07 hubbe Exp $"); #include "fdlib.h" #include "interpret.h" #include "svalue.h" @@ -1617,9 +1617,7 @@ static void file_create(INT32 args) struct new_thread_data { - struct object *from; - struct object *to; - INT32 fromfd, tofd; + INT32 from, to; }; static void *proxy_thread(void * data) @@ -1627,13 +1625,10 @@ static void *proxy_thread(void * data) char buffer[READ_BUFFER]; struct new_thread_data *p=(struct new_thread_data *)data; -/* fprintf(stderr,"new proxy thread, from %d to %d.\n",p->fromfd,p->tofd); */ -/* fprintf(stderr,"Thread started %p.\n",p); */ while(1) { long len, w; -/* fprintf(stderr,"reading from %d.\n",p->fromfd); */ - len=fd_read(p->fromfd, buffer, READ_BUFFER); + len=fd_read(p->from, buffer, READ_BUFFER); if(len==0) break; if(len<0) { @@ -1642,10 +1637,9 @@ static void *proxy_thread(void * data) } w=0; -/* fprintf(stderr,"writing to %d.\n",p->tofd); */ while(w<len) { - long wl=fd_write(p->tofd, buffer+w, len-w); + long wl=fd_write(p->to, buffer+w, len-w); if(wl<0) { if(errno==EINTR) continue; @@ -1655,10 +1649,9 @@ static void *proxy_thread(void * data) } } -/* fprintf(stderr,"Proxy thread (%d - %d) done.\n",p->fromfd,p->tofd); */ mt_lock(&interpreter_lock); - free_object(p->from); - free_object(p->to); + do_close(p->to, FILE_READ | FILE_WRITE); + do_close(p->from, FILE_READ | FILE_WRITE); num_threads--; mt_unlock(&interpreter_lock); free((char *)p); @@ -1676,12 +1669,8 @@ void file_proxy(INT32 args) error("Bad argument 1 to Stdio.File->proxy, not a Stdio.File object.\n"); p=ALLOC_STRUCT(new_thread_data); - p->to=fp->current_object; - p->tofd=FD; - p->from=sp[-args].u.object; - p->fromfd=f->fd; - p->to->refs++; - p->from->refs++; + files[p->from=f->fd].refs++; + files[p->to=FD].refs++; num_threads++; if(th_create_small(&id,proxy_thread,p)) { -- GitLab