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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:1802:    {    Pike_sp--;    push_int64( io_rewind( THIS, bytes ) );    }       /*! @decl string(8bit) read( int n )    *!    *! Read @[bytes] bytes of data from the buffer.    *!    *! If there is not enough data available this returns 0. +  *! +  *! @seealso +  *! @[try_read()]    */    PIKEFUN string(0..255) read( int bytes )    {    struct pike_string *s;    Pike_sp--;    s = io_read_string(THIS, bytes );    if( s )    push_string( s );    else    push_undefined();    }       /*! @decl string(8bit) read( )    *!    *! Read all data from the buffer.    *!    *! If there is not enough data available this returns 0.    *!    *! This is basically equivalent to (string)buffer, but it also    *! removes the data from the buffer. -  +  *! +  *! @seealso +  *! @[try_read()]    */    PIKEFUN string(0..255) read()    {    struct pike_string * s = io_read_string(THIS, io_len(THIS));    if( s )    push_string( s );    else -  push_undefined(); +  push_undefined(); /* FIXME: Is this ever reached? */    }    -  +  /*! @decl string(8bit) try_read(int len) +  *! +  *! Attempt to read some data from the buffer. +  *! +  *! @param len +  *! Read at most @[len] bytes from the buffer. +  *! +  *! @returns +  *! If the buffer contains less than @[len] bytes +  *! of data, the entire buffer contents are returned. +  *! Otherwise the first @[len] bytes are returned. +  *! +  *! @seealso +  *! @[read()] +  */ +  PIKEFUN string(0..255) try_read( int bytes ) +  { +  struct pike_string *s; +  Pike_sp--; +  +  if (bytes > io_len(THIS)) +  bytes = io_len(THIS); +  s = io_read_string(THIS, bytes ); +  if( s ) +  push_string( s ); +  else +  push_undefined(); /* FIXME: Is this ever reached? */ +  } +     /*! @decl int(8bit) read_int8()    */    PIKEFUN int(8bit) read_int8( )    {    IOBuffer *io = THIS;    if( LIKELY(io_avail( io, 1 )) )    push_int( io_read_byte_uc(io) );    else    push_int(-1);    }