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.14 1997/10/10 18:59:47 grubba Exp $"); + RCSID("$Id: pipe.c,v 1.15 1998/04/03 20:23:00 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:69:    * multiple socket output without regular file output illegal    */      static struct program *pipe_program, *output_program;      #define THIS ((struct pipe *)(fp->current_storage))   #define THISOBJ (fp->current_object)      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;    struct pike_string *str;    char *mmap;    } u;    unsigned long len; /* current input: string or mmap len */    int set_blocking_offset, set_nonblocking_offset;    struct input *next;   };
pike.git/src/modules/Pipe/pipe.c:178:    return i;   }      /* Free an input struct and all that it stands for */   static INLINE void free_input(struct input *i)   {    ninputs--;    switch (i->type)    {    case I_OBJ: +  case I_BLOCKING_OBJ:    if (!i->u.obj) break;    if (i->u.obj->prog)    {   #ifdef BLOCKING_CLOSE    apply_low(i->u.obj,i->set_blocking_offset,0);    pop_stack();   #endif    apply(i->u.obj,"close",0);    pop_stack();    destruct(i->u.obj);
pike.git/src/modules/Pipe/pipe.c:327:      /* 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 */    i=THIS->firstinput->next;    free_input(THIS->firstinput);    THIS->firstinput=i;       if(!i) break;       switch(i->type)    {    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(); +  THIS->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;       case I_STRING:    append_buffer(i->u.str);       case I_NONE: break;    }    }
pike.git/src/modules/Pipe/pipe.c:418:    free_string(b->s);    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(this->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 */ +  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();    }    } -  +  }       while (!this->firstbuffer)    {    if (this->firstinput)    {   #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)    if (this->firstinput->type==I_MMAP)    {    char *src;    struct pike_string *tmp;
pike.git/src/modules/Pipe/pipe.c:457: Inside #if defined(HAVE_MMAP) && defined(HAVE_MUNMAP)
  /* This thread_allow/deny is at the cost of one extra memory copy */    THREADS_ALLOW();    MEMCPY(tmp->str, src, len);    THREADS_DISALLOW();    return end_shared_string(tmp);    }    else   #endif    if (this->firstinput->type!=I_OBJ)    { +  /* FIXME: What about I_BLOCKING_OBJ? */    input_finish(); /* shouldn't be anything else ... maybe a finished object */    }    }    return NULL; /* no data */    }       if (pos==this->pos)    {    this->firstbuffer->s->refs++;    return this->firstbuffer->s;
pike.git/src/modules/Pipe/pipe.c:671:    i->u.obj=obj;    nobjects++;    i->type=I_OBJ;    i->u.obj->refs++;    i->set_nonblocking_offset=find_identifier("set_nonblocking",i->u.obj->prog);    i->set_blocking_offset=find_identifier("set_blocking",i->u.obj->prog);       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;       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; +  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);    pop_stack();    }    else