pike.git / src / modules / _Stdio / buffer.cmod

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:850:    }    }    }      #undef THIS   #define THIS (&(((struct IOBuffer_struct *)Pike_fp->current_storage)->b))          /* pike functions */    -  /*! @decl int(0..) input_from( Stdio.Stream f, int|void nbytes ) +  /*! @decl int(-1..) input_from( Stdio.Stream f, int|void nbytes )    *!    *! Read data from @[f] into this buffer. If @[nbytes] is not    *! specified, read until there is no more data to read (currently).    *! -  *! Returns the amount of data that was read +  *! Returns the amount of data that was read, or @expr{-1@} on +  *! read error.    *!    *! @note    *! Please note that this funcition will read all data from the    *! filedescriptor unless it's set to be non-blocking.    */ -  PIKEFUN int(0..) input_from( object f, int|void _nbytes, int|void _once ) +  PIKEFUN int(-1..) input_from( object f, int|void _nbytes, int|void _once )    {    IOBuffer *io = THIS;    size_t sz = io_len( io );    size_t bread = 0, nbytes = (size_t)-1;    struct my_file *fd;    int once = 0;    -  if( _nbytes ) +  if( _nbytes ) {    nbytes = _nbytes->u.integer; -  +  if (!nbytes) RETURN 0; +  }       if( _once )    once = _once->u.integer;          if( (fd = get_storage( f, file_program )) )    {    while( 1 )    {    unsigned char *ptr = io_add_space( io, 4096, 0 );
pike.git/src/modules/_Stdio/buffer.cmod:894:       if( res == -1 && errno == EINTR )    continue;       if( res <= 0 )    break;       nbytes -= res;    io->len += res;    bread += res; -  if( res != 4096 || once) +  if( res != 4096 || once || !nbytes )    break;    }    io_set_events( io, fd, PIKE_BIT_FD_READ_OOB, PIKE_FD_READ );    }    else    {    /* some other object. Just call read */    while( nbytes )    {    push_int( MINIMUM(4096,nbytes) );    safe_apply( f, "read", 1 );    if( TYPEOF(Pike_sp[-1]) != PIKE_T_STRING || Pike_sp[-1].u.string->len == 0 )    break;    if( Pike_sp[-1].u.string->size_shift )    Pike_error("Can not handle non-8bit data\n");    io_append( io, Pike_sp[-1].u.string->str, Pike_sp[-1].u.string->len );    nbytes -= Pike_sp[-1].u.string->len;    pop_stack();    }    } -  +  +  if (!bread) RETURN -1; +     RETURN bread;    }       /*! @decl int __fd_set_output( object f )    *!    *! This tells the buffer to trigger the write callback for the    *! specified filedescriptor when data is added to the buffer.    *!    *! This is used internally by Stdio.File to handle nonblocking    *! buffered mode, and is not really intended to be used directly.