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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:502:    *!    *! 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    *!    *! @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 ) +  PIKEFUN int(0..) 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 )    nbytes = _nbytes->u.integer;    -  +  if( _once ) +  once = _once->u.integer; +  +     if( (fd = get_storage( f, file_program )) )    {    while( 1 )    {    unsigned char *ptr = io_add_space( io, 4096, 0 );    int res;       res = fd_read( fd->box.fd, ptr, MINIMUM(4096,nbytes) );       if( res == -1 && errno == EINTR )    continue;       if( res <= 0 )    break; -  +     nbytes -= res;    io->len += res;    bread += res; -  if( res != 4096 ) +  if( res != 4096 || once)    break;    }    fd->box.revents &= ~(PIKE_BIT_FD_READ|PIKE_BIT_FD_READ_OOB);    if(!SAFE_IS_ZERO(&fd->event_cbs[PIKE_FD_READ])    && fd->box.backend)    set_fd_callback_events(&fd->box, fd->box.events|PIKE_BIT_FD_READ, 0);    }    else    {    /* some other object. Just call read */