Branch: Tag:

1998-04-03

1998-04-03 19:58:15 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Added support for blocking inputs.

Rev: src/modules/Pipe/pipe.c:1.16

22:   #include <fcntl.h>      #include "global.h" - RCSID("$Id: pipe.c,v 1.15 1998/01/13 23:00:35 hubbe Exp $"); + RCSID("$Id: pipe.c,v 1.16 1998/04/03 19:58:15 grubba Exp $");      #include "threads.h"   #include "stralloc.h"
79:      struct input   { -  enum { I_NONE,I_OBJ,I_STRING,I_MMAP } type; +  enum { I_NONE,I_OBJ,I_BLOCKING_OBJ,I_STRING,I_MMAP } type;    union    {    struct object *obj;
188:    switch (i->type)    {    case I_OBJ: +  case I_BLOCKING_OBJ:    if (!i->u.obj) break;    if (i->u.obj->prog)    {
337:       while(1)    { +  /* Get the next input from the queue */    i=THIS->firstinput->next;    free_input(THIS->firstinput);    THIS->firstinput=i;
354:    pop_stack();    return;    +  case I_BLOCKING_OBJ: +  push_int(8192); +  push_int(1); /* We don't care if we don't get all 8192 bytes. */ +  apply(i->u.obj, "read", 2); +  if (sp[-1].type == T_STRING) { +  append_buffer(sp[-1].u.string); +  pop_stack(); +  i->sleeping = 1; +  return; +  } else { +  /* FIXME: Should we check the return value here? */ +  pop_stack(); +  /* EOF */ +  continue; +  } +     case I_MMAP:    if (THIS->fd==-1) return;    continue;
428:    this->firstinput &&    this->bytes_in_buffer<MAX_BYTES_IN_BUFFER)    { +  if (this->type == I_BLOCKING_OBJ) { +  push_int(8192); +  push_int(1); /* We don't care if we don't get all 8192 bytes. */ +  apply(i->u.obj, "read", 2); +  if (sp[-1].type == T_STRING) { +  append_buffer(sp[-1].u.string); +  } else { +  this->sleeping = 0; +  /* We're not sleeping -- we're dead... */ +  } +  pop_stack(); +  } else {    this->sleeping=0;    push_callback(offset_input_read_callback);    push_int(0);
436:    pop_stack();    }    } +  }       while (!this->firstbuffer)    {
467:   #endif    if (this->firstinput->type!=I_OBJ)    { +  /* FIXME: What about I_BLOCKING_OBJ? */    input_finish(); /* shouldn't be anything else ... maybe a finished object */    }    }
681:    if (i->set_nonblocking_offset<0 ||    i->set_blocking_offset<0)    { +  if (find_identifier("read", i->u.obj->prog) < 0) { +  /* Not even a read function */    free_object(i->u.obj);    i->u.obj=NULL;    i->type=I_NONE;
689:    error("illegal file object%s%s\n",    ((i->set_nonblocking_offset<0)?"; no set_nonblocking":""),    ((i->set_blocking_offset<0)?"; no set_blocking":"")); +  } else { +  /* Try blocking mode */ +  i->type = I_BLOCKING_OBJ; +  return;    } -  +  }       if (i==THIS->firstinput)    {