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

version» Context lines:

pike.git/src/modules/Pipe/pipe.c:19: Inside #if defined(HAVE_MMAP)
  #else   #ifdef HAVE_MMAP   /* sys/mman.h is _probably_ there anyway. */   #include <sys/mman.h>   #endif   #endif   #endif      #include <fcntl.h>    - RCSID("$Id: pipe.c,v 1.30 1999/02/10 21:50:35 hubbe Exp $"); + RCSID("$Id: pipe.c,v 1.31 1999/03/05 01:49:27 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:321:   /* Wake up the sleepers */   static void low_start(void)   {    struct object *obj, *next;    struct output *o;          add_ref(THISOBJ); /* dont kill yourself now */    for(obj=THIS->firstoutput;obj;obj=next)    { -  add_ref(obj); /* Hang on PLEASE!! /hubbe */ +  /* add_ref(obj); /* Hang on PLEASE!! /hubbe */    o=(struct output *)(obj->storage); -  +  next=o->next;    if (o->obj && o->mode==O_SLEEP)    {    if (!o->obj->prog)    {    output_finish(obj);    }    else    { - #if 0 +     push_int(0);    push_callback(offset_output_write_callback);    push_callback(offset_output_close_callback);    apply_low(o->obj,o->set_nonblocking_offset,3); - #endif -  output_try_write_some(obj); -  o->mode=O_RUN; /* Hubbe */ +  /* output_try_write_some(obj); */ +  /* o->mode=O_RUN; /* Hubbe */    }    } -  next=o->next; -  free_object(obj); +  /* next=o->next; */ +  /* free_object(obj); */    }       free_object(THISOBJ);   }      /* Read some data from the blocking object.    *    */   static int read_some_data(void)   {
pike.git/src/modules/Pipe/pipe.c:557:   }         /*    * close and free the contents of a struct output    * Note that the output struct is not freed or unlinked here,    * that is taken care of later.    */   static INLINE void output_finish(struct object *obj)   { -  struct output *o; +  struct output *o, *oi; +  struct object *obji;       o=(struct output *)(obj->storage);       if (o->obj)    { -  +  if(obj==THIS->firstoutput){ +  THIS->firstoutput=o->next; +  } else +  for(obji=THIS->firstoutput;obji;obji=oi->next) +  { +  oi=(struct output *)(obji->storage); +  if(oi->next==obj) +  { +  oi->next=o->next; +  } +  }    if(o->obj->prog)    {   #ifdef BLOCKING_CLOSE    apply_low(o->obj,o->set_blocking_offset,0);    pop_stack();   #endif    push_int(0);    apply(o->obj,"set_id",1);    pop_stack();   
pike.git/src/modules/Pipe/pipe.c:587:    destruct(o->obj);    }    free_object(o->obj);    noutputs--;    o->obj=NULL;       THIS->living_outputs--;       finished_p(); /* Moved by per, one line down.. :) */    -  free_object(THISOBJ); /* What? /Hubbe */ +  /* free_object(THISOBJ); /* What? /Hubbe */    }   }      /*    * Try to write some data to our precious output    */   static INLINE void output_try_write_some(struct object *obj)   {    struct output *out;    struct pike_string *s;
pike.git/src/modules/Pipe/pipe.c:618:    s=gimme_some_data(out->pos);    if (!s) /* out of data */    {    /* out of data, goto sleep */    if (!THIS->firstinput || !out->obj->prog) /* end of life */    {    output_finish(obj);    }    else    { - #if 0 +     apply_low(out->obj, out->set_blocking_offset, 0);    pop_stack(); /* from apply */ - #endif +     out->mode=O_SLEEP;    }    return;    }    len=s->len;    push_string(s);    apply_low(out->obj,out->write_offset,1);    out->mode=O_RUN;       ret=-1;
pike.git/src/modules/Pipe/pipe.c:829:    int fd;    struct stat s;    struct buffer *b;       if (args<1 ||    sp[-args].type != T_OBJECT ||    !sp[-args].u.object ||    !sp[-args].u.object->prog)    error("Bad/missing argument 1 to pipe->output().\n");    +  if (args==2 && +  sp[1-args].type != T_INT) +  error("Bad argument 2 to pipe->output().\n"); +     if (THIS->fd==-1) /* no buffer */    {    /* test if usable as buffer */    apply(sp[-args].u.object,"query_fd",0);       if ((sp[-1].type==T_INT)    && (fd=sp[-1].u.integer)>=0    && (fstat(fd,&s)==0)    && S_ISREG(s.st_mode)    && (THIS->fd=dup(fd))!=-1 )
pike.git/src/modules/Pipe/pipe.c:877:    THIS->pos=0; */    push_int(0);    apply(sp[-args-2].u.object,"set_id", 1);    pop_n_elems(args+2); /* ... and from apply x 2 */    return;    }    pop_stack(); /* from apply */    }       THIS->living_outputs++; -  add_ref(THISOBJ); /* Weird */ +  /* add_ref(THISOBJ); /* Weird */       /* Allocate a new struct output */    obj=clone_object(output_program,0);    o=(struct output *)(obj->storage);    o->next=THIS->firstoutput;    THIS->firstoutput=obj;    noutputs++;    o->obj=NULL;       add_ref(o->obj=sp[-args].u.object);
pike.git/src/modules/Pipe/pipe.c:906:    free_object(o->obj);    error("illegal file object%s%s%s\n",    ((o->write_offset<0)?"; no write":""),    ((o->set_nonblocking_offset<0)?"; no set_nonblocking":""),    ((o->set_blocking_offset<0)?"; no set_blocking":""));    }       o->mode=O_RUN;    /* keep the file pointer of the duped fd    o->pos=0; */ +  /* allow start position as 2nd argument for additional outputs +  o->pos=THIS->pos; */ +  +  if(args>=2) +  o->pos=sp[1-args].u.integer; +  else    o->pos=THIS->pos;       ref_push_object(obj);    apply(o->obj,"set_id",1);    pop_stack();       push_int(0);    push_callback(offset_output_write_callback);    push_callback(offset_output_close_callback);    apply_low(o->obj,o->set_nonblocking_offset,3);
pike.git/src/modules/Pipe/pipe.c:947:       free_svalue(&THIS->done_callback);    assign_svalue_no_free(&(THIS->done_callback),sp-args);    pop_n_elems(args-1);   }      static void pipe_set_output_closed_callback(INT32 args)   {    if (args==0)    { -  free_svalue(&THIS->done_callback); +  free_svalue(&THIS->output_closed_callback);    THIS->output_closed_callback.type=T_INT;    return;    }    if (args<1 || (sp[-args].type!=T_FUNCTION && sp[-args].type!=T_ARRAY))    error("Illegal argument to set_output_closed_callback()\n");       if (args>1)    {    free_svalue(&THIS->id);    assign_svalue_no_free(&(THIS->id),sp-args+1);
pike.git/src/modules/Pipe/pipe.c:1098:      /********** init/exit *******************************************************/      void close_and_free_everything(struct object *thisobj,struct pipe *p)   {    struct buffer *b;    struct input *i;    struct output *o;    struct object *obj;    +  if(p->done){ +  return; +  }    p->done=1;       if (thisobj)    add_ref(thisobj); /* don't kill object during this */       while (p->firstbuffer)    {    b=p->firstbuffer;    p->firstbuffer=b->next;    sbuffers-=b->s->len;
pike.git/src/modules/Pipe/pipe.c:1151:    free_object(thisobj);       free_svalue(& p->done_callback);    free_svalue(& p->output_closed_callback);    free_svalue(& p->id);       p->done_callback.type=T_INT;    p->output_closed_callback.type=T_INT;    p->id.type=T_INT;    -  p->done=0; +  /* p->done=0; */   }      static void init_pipe_struct(struct object *o)   {    THIS->firstbuffer=THIS->lastbuffer=NULL;    THIS->firstinput=THIS->lastinput=NULL;    THIS->firstoutput=NULL;    THIS->bytes_in_buffer=0;    THIS->pos=0;    THIS->sleeping=0;
pike.git/src/modules/Pipe/pipe.c:1203:       apply(o->obj,"close",0);    pop_stack();       if(!THISOBJ->prog)    error("Pipe done callback destructed pipe.\n");    }    free_object(o->obj);    noutputs--;    o->obj=0; +  o->fd=-1;    }   }      static void init_output_struct(struct object *ob)   {    struct output *o;    o=(struct output *)(fp->current_storage);    o->obj=0;   }   
pike.git/src/modules/Pipe/pipe.c:1240:      void pike_module_init(void)   {    start_new_program();    ADD_STORAGE(struct pipe);      /* function(:array) */    ADD_EFUN("_pipe_debug", f__pipe_debug,tFunc(,tArray), 0);    /* function(object:void) */    ADD_FUNCTION("input",pipe_input,tFunc(tObj,tVoid),0); -  /* function(object:void) */ -  ADD_FUNCTION("output",pipe_output,tFunc(tObj,tVoid),0); +  /* function(object,void|int:void) */ +  ADD_FUNCTION("output",pipe_output,tFunc(tObj tOr(tVoid|tInt),tVoid),0);    /* function(string:void) */    ADD_FUNCTION("write",pipe_write,tFunc(tStr,tVoid),0);       /* function(:void) */    ADD_FUNCTION("start",pipe_start,tFunc(,tVoid),0);    /* function(:void) */    ADD_FUNCTION("finish",pipe_finish,tFunc(,tVoid),0);       /* function(void|function(mixed,object:mixed),void|mixed:void) */    ADD_FUNCTION("set_output_closed_callback",pipe_set_output_closed_callback,tFunc(tOr(tVoid,tFunc(tMix tObj,tMix)) tOr(tVoid,tMix),tVoid),0);