pike.git / src / modules / Pipe / pipe.c

version» Context lines:

pike.git/src/modules/Pipe/pipe.c:15: Inside #if defined(HAVE_MMAP)
  #ifdef HAVE_MMAP   /* sys/mman.h is _probably_ there anyway. */   #include <sys/mman.h>   #endif   #endif   #endif      #include <fcntl.h>      #include "global.h" - RCSID("$Id: pipe.c,v 1.18 1998/04/03 20:55:47 grubba Exp $"); + RCSID("$Id: pipe.c,v 1.19 1998/04/03 21:35:34 grubba Exp $");      #include "threads.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "object.h"   #include "constants.h"   #include "interpret.h"   #include "svalue.h"   #include "error.h"   #include "builtin_functions.h"
pike.git/src/modules/Pipe/pipe.c:322:    o->mode=O_RUN; /* Hubbe */    }    }    next=o->next;    free_object(obj);    }       free_object(THISOBJ);   }    + /* Read some data from the blocking object. +  * +  */ + static int read_some_data(void) + { +  struct pipe *this = THIS; +  struct input * i = this->firstinput; +  +  if (!i || i->type != I_BLOCKING_OBJ) { +  fatal("PIPE: read_some_data(): Bad input type!\n"); +  return; +  } +  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) && (sp[-1].u.string->len > 0)) { +  append_buffer(sp[-1].u.string); +  pop_stack(); +  THIS->sleeping = 1; +  return(1); /* Success */ +  } +  +  /* FIXME: Should we check the return value here? */ +  pop_stack(); +  /* EOF */ +  return(0); /* EOF */ + } +    /* Let's guess what this function does....    *    */   static INLINE void input_finish(void)   {    struct input *i;       while(1)    {    /* Get the next input from the queue */
pike.git/src/modules/Pipe/pipe.c:350:    case I_OBJ:    THIS->sleeping=0;    push_callback(offset_input_read_callback);    push_int(0);    push_callback(offset_input_close_callback);    apply_low(i->u.obj,i->set_nonblocking_offset,3);    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; +  if (read_some_data())    return; -  } else { -  /* FIXME: Should we check the return value here? */ -  pop_stack(); -  /* EOF */ +     continue; -  } +        case I_MMAP:    if (THIS->fd==-1) return;    continue;       case I_STRING:    append_buffer(i->u.str);       case I_NONE: break;    }
pike.git/src/modules/Pipe/pipe.c:440:    free((char *)b);       /* Wake up first input if it was sleeping and we    * have room for more in the buffer.    */    if (this->sleeping &&    this->firstinput &&    this->bytes_in_buffer<MAX_BYTES_IN_BUFFER)    {    if (this->firstinput->type == I_BLOCKING_OBJ) { -  push_int(8192); -  push_int(1); /* We don't care if we don't get all 8192 bytes. */ -  apply(i->firstinput->u.obj, "read", 2); -  if (sp[-1].type == T_STRING) { -  append_buffer(sp[-1].u.string); -  } else { -  /* FIXME: Should probably check the return value. */ -  /* EOF */ +  if (!read_some_data()) {    this->sleeping = 0;    input_finish();    } -  pop_stack(); +     } else {    this->sleeping=0;    push_callback(offset_input_read_callback);    push_int(0);    push_callback(offset_input_close_callback);    apply(this->firstinput->u.obj, "set_nonblocking", 3);    pop_stack();    }    }    }
pike.git/src/modules/Pipe/pipe.c:721:    i->u.obj=NULL;    i->type=I_NONE;       nobjects--;    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; +  if (i==THIS->firstinput) { +  read_some_data(); +  }    return;    }    }       if (i==THIS->firstinput)    {    push_callback(offset_input_read_callback);    push_int(0);    push_callback(offset_input_close_callback);    apply_low(i->u.obj,i->set_nonblocking_offset,3);