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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:453:    return -1;    }    if( bytes > l )    io_rewind( io, bytes-l );    }    return l;    }    return -1;    }    -  static void io_actually_trigger_output( Buffer *io ) +  static ptrdiff_t io_actually_trigger_output( Buffer *io )    ATTRIBUTE((noclone,noinline));    -  static void io_actually_trigger_output( Buffer *io ) +  static ptrdiff_t io_actually_trigger_output( Buffer *io )    {    struct program *prog;    struct reference *ref;    struct inherit *inh;       if (UNLIKELY(!(prog = io->output.u.object->prog))) {    /* Destructed object. */    free_svalue(&io->output);    SET_SVAL(io->output, PIKE_T_INT, NUMBER_NUMBER, integer, 0); -  return; +  return 0;    }    ref = PTR_FROM_INT(prog, SUBTYPEOF(io->output));    inh = INHERIT_FROM_PTR(prog, ref);    if ((inh->prog == file_program) &&    (ref->identifier_offset == fd_write_identifier_offset)) {    /* Stdio.Fd::write */    struct my_file *fd =    get_inherit_storage( io->output.u.object, ref->inherit_offset );    io_set_events( io, fd, PIKE_BIT_FD_WRITE_OOB, PIKE_FD_WRITE );    io->output_triggered = 1; -  +  return 0;    }    else -  io_call_write( io, &io->output, MINIMUM( io_len(io), 100 ) ); +  return io_call_write( io, &io->output, MINIMUM( io_len(io), 100 ) );    }    -  static void io_trigger_output( Buffer *io ) +  static ptrdiff_t io_trigger_output( Buffer *io )    {    if( UNLIKELY(io->output.u.object) && UNLIKELY(!io->output_triggered) ) -  io_actually_trigger_output(io); +  return io_actually_trigger_output(io); +  return 0;    }       static int io_range_error( Buffer *io, ptrdiff_t howmuch )    ATTRIBUTE((noclone,noinline));       static int io_range_error( Buffer *io, ptrdiff_t howmuch )    {    int res;    struct svalue *osp = Pike_sp;   
pike.git/src/modules/_Stdio/buffer.cmod:1095:    if (!written) written = -1;    break;    }    written += wr;    if( wr < 4096 )    break;    }    RETURN written;    }    +  /*! @decl int(-1..) try_output() +  *! +  *! Try to write some data from the buffer to the file +  *! registered with @[__fd_set_output()]. +  *! +  *! This is typically called from backend callbacks when it +  *! seems that it is possible to write some data to the file. +  *! +  *! @returns +  *! Returns @expr{-1@} on write error, and otherwise +  *! the number of bytes written to the file. +  *! +  *! @seealso +  *! @[__fd_set_output()] +  */ +  PIKEFUN int(-1..) try_output() +  { +  Buffer *io = THIS; +  if (LIKELY(io->output.u.object) && LIKELY(!io->output_triggered)) +  RETURN io_actually_trigger_output(io); +  RETURN 0; +  } +     /*! @decl int read_sint( int size )    *!    *! Read a network byte order two:s complement signed number of size n*8 bits, then    *! return it.    *!    *! Will return UNDEFINED if there is not enough buffer space    *! available unless error mode is set to throw errors.    */    PIKEFUN int read_sint( int nbytes )    {