pike.git / lib / modules / Sql.pmod / pgsql_util.pmod

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:178:    }    }      };      class conxiin {    inherit Stdio.Buffer:i;       final Thread.Condition fillread;    final Thread.Mutex fillreadmux; +  final int procmsg;    private int didreadcb;       protected bool range_error(int howmuch) {   #ifdef PG_DEBUG    if(howmuch<=0)    error("Out of range %d\n",howmuch);   #endif    if(fillread) {    Thread.MutexKey lock=fillreadmux->lock();    if(!didreadcb)    fillread.wait(lock);    didreadcb=0;    lock=0;    } else    throw(MAGICTERMINATE);    return true;    }       final int read_cb(mixed id,mixed b) { -  +  PD("Read callback %O\n",(string)b);    Thread.MutexKey lock=fillreadmux->lock(); -  if(fillread) +  if(procmsg) +  procmsg=0,lock=0,Thread.Thread(id); +  else if(fillread)    didreadcb=1, fillread.signal();    lock=0;    return 0;    }       protected void create() {    i::create();    fillreadmux=Thread.Mutex();    fillread=Thread.Condition();    }   };      class conxion {    inherit Stdio.Buffer:o;    final conxiin i;       private Thread.Queue qportals;    final Thread.Mutex shortmux;    final Stdio.File socket; -  private object pgsqlsess; +  private function(void|mixed:void) connectfail;    private int towrite;       final Thread.Mutex nostash;    final Thread.MutexKey started;    final Thread.Queue stashqueue;    final Thread.Condition stashavail;    final Stdio.Buffer stash;    final int stashflushmode;    final int stashcount;    final int synctransact;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:320:    lock=shortmux->lock();    if(towrite=sizeof(this)) {    PD("%d>Sendcmd %O\n",socket->query_fd(),((string)this)[..towrite-1]);    towrite-=output_to(socket,towrite);    }    } while(0);    lock=started=0;    return;    };    lock=0; -  if(pgsqlsess) -  pgsqlsess->_connectfail(); +  catch(connectfail());    }       final void sendterminate() {    Thread.MutexKey lock=i->fillreadmux->lock();    if(i->fillread) // Delayed close() after flushing the output buffer    i->fillread.signal(), i->fillread=0;    lock=0;    }       final int close() {    int ret;    destruct(nostash);    PD("%d>Close socket\n",socket->query_fd());    ret=socket->close();    sendterminate();    return ret;    }       protected void destroy() {    catch(close()); // Exceptions don't work inside destructors -  pgsqlsess=0; +  connectfail=0;    }    -  final void connectloop(int nossl) { +  final void connectloop(object pgsqlsess, int nossl) {    mixed err=catch {    for(;;clear()) {    socket->connect(pgsqlsess._host,pgsqlsess._port);   #if constant(SSL.File)    if(!nossl && !pgsqlsess->nossl    && (pgsqlsess._options.use_ssl || pgsqlsess._options.force_ssl)) {    PD("SSLRequest\n");    start()->add_int32(8)->add_int32(PG_PROTOCOL(1234,5679))    ->sendcmd(SENDOUT);    switch(read_int8()) {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:385:    " cannot establish connection to %s:%d\n",    pgsqlsess.host,pgsqlsess.port);   #endif    break;    }    if(!socket->is_open())    error(strerror(socket->errno())+".\n");    socket->set_backend(local_backend);    socket->set_buffer_mode(i,0);    socket->set_nonblocking(i->read_cb,write_cb,close); +  connectfail=pgsqlsess->_connectfail;    Thread.Thread(pgsqlsess->_processloop,this);    return;    }; -  if(pgsqlsess) -  pgsqlsess->_connectfail(err); +  catch(connectfail(err));    }       private string _sprintf(int type, void|mapping flags) {    string res=UNDEFINED;    switch(type) {    case 'O':    res=predef::sprintf("conxion fd: %d input queue: %d/%d "    "queued portals: %d output queue: %d/%d\n",    socket&&socket->query_fd(),    sizeof(i),i->_size_object(),    qportals->size(),sizeof(this),_size_object());    break;    }    return res;    }    -  protected void create(object _pgsqlsess,Thread.Queue _qportals,int nossl) { +  protected void create(object pgsqlsess,Thread.Queue _qportals,int nossl) {    o::create();    qportals = _qportals;    synctransact = 1;    socket=Stdio.File();    i=conxiin();    shortmux=Thread.Mutex();    nostash=Thread.Mutex();    stashavail=Thread.Condition();    stashqueue=Thread.Queue();    stash=Stdio.Buffer(); -  pgsqlsess=_pgsqlsess; -  Thread.Thread(connectloop,nossl); +  Thread.Thread(connectloop,pgsqlsess,nossl);    }   };      //! The result object returned by @[Sql.pgsql()->big_query()], except for   //! the noted differences it behaves the same as @[Sql.sql_result].   //!   //! @seealso   //! @[Sql.sql_result], @[Sql.pgsql], @[Sql.Sql], @[Sql.pgsql()->big_query()]   class sql_result {