pike.git / lib / modules / Stdio.pmod

version» Context lines:

pike.git/lib/modules/Stdio.pmod:1: - // $Id: Stdio.pmod,v 1.36 1998/10/22 02:13:18 grubba Exp $ + // $Id: Stdio.pmod,v 1.37 1999/01/30 01:35:08 grubba Exp $      #include <string.h>      inherit files;      class File   {    inherit Fd_ref;       mixed ___read_callback;
pike.git/lib/modules/Stdio.pmod:67:       int connect(string host, int port)    {    if(!_fd) _fd=Fd();   #ifdef __STDIO_DEBUG    __closed_backtrace=0;   #endif    return ::connect(host,port);    }    +  static private function(int, mixed ...:void) _async_cb; +  static private array(mixed) _async_args; +  static private void _async_connected(mixed|void ignored) +  { +  // Copy the args to avoid races. +  function(int, mixed ...:void) cb = _async_cb; +  array(mixed) args = _async_args; +  _async_cb = 0; +  _async_args = 0; +  set_nonblocking(0,0,0); +  cb(1, @args); +  } +  static private void _async_failed(mixed|void ignored) +  { +  // Copy the args to avoid races. +  function(int, mixed ...:void) cb = _async_cb; +  array(mixed) args = _async_args; +  _async_cb = 0; +  _async_args = 0; +  set_nonblocking(0,0,0); +  cb(0, @args); +  } +  // NOTE: Zaps nonblocking-state. +  int async_connect(string host, int port, +  function(int, mixed ...:void) callback, +  mixed ... args) +  { +  if (!_fd && !open_socket()) { +  // Out of sockets? +  return 0; +  } +  _async_cb = callback; +  _async_args = args; +  set_nonblocking(0, _async_connected, _async_failed); +  mixed err; +  if (err = catch(connect(host, port))) { +  // Illegal format. -- Bad hostname? +  set_nonblocking(0,0,0); +  throw(err); +  } +  return(1); // OK so far. +  } +     object(File) pipe(void|int how)    {    _fd=Fd();   #ifdef __STDIO_DEBUG    __closed_backtrace=0;   #endif    if(query_num_arg()==0)    how=PROP_NONBLOCK | PROP_BIDIRECTIONAL;    if(object(Fd) fd=::pipe(how))    {