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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:15:   #require constant(Thread.Thread)      #include "pgsql.h"      //! The instance of the pgsql dedicated backend.   final Pike.Backend local_backend = Pike.SmallBackend();      private Thread.Mutex backendmux = Thread.Mutex();   private int clientsregistered;    - multiset cachealways=(<"BEGIN","begin","END","end","COMMIT","commit">); - Regexp createprefix + final multiset cachealways=(<"BEGIN","begin","END","end","COMMIT","commit">); + final Regexp createprefix    =Regexp("^[ \t\f\r\n]*[Cc][Rr][Ee][Aa][Tt][Ee][ \t\f\r\n]");   private Regexp dontcacheprefix    =Regexp("^[ \t\f\r\n]*([Ff][Ee][Tt][Cc][Hh]|[Cc][Oo][Pp][Yy])[ \t\f\r\n]"); -  + private Regexp commitprefix=Regexp( +  "^[ \t\f\r\n]*([Cc][Oo][Mm][Mm][Ii][Tt]|[Ee][Nn][Dd])([ \t\f\r\n;]|$)");   private Regexp execfetchlimit    =Regexp("^[ \t\f\r\n]*(([Uu][Pp][Dd][Aa]|[Dd][Ee][Ll][Ee])[Tt][Ee]|\   [Ii][Nn][Ss][Ee][Rr][Tt])[ \t\f\r\n]|\   [ \t\f\r\n][Ll][Ii][Mm][Ii][Tt][ \t\f\r\n]+[12][; \t\f\r\n]*$");      final void closestatement(PGplugbuffer|PGassist plugbuffer,string oldprep) {    if(oldprep) {    PD("Close statement %s\n",oldprep);    plugbuffer->add_int8('C')->add_hstring(({'S',oldprep,0}),4,4);    }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:305:    catch(close()); // Exceptions don't work inside destructors    pgsqlsess=0;    }       final void connectloop(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)) { +  && (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()) {    case 'S':    object fcon=SSL.File(socket,SSL.Context());    if(fcon->connect()) {    socket=fcon;    break;    }    default:socket->close();    pgsqlsess.nossl=1;    continue;    case 'N': -  if(pgsqlsess.options.force_ssl) +  if(pgsqlsess._options.force_ssl)    error("Encryption not supported on connection to %s:%d\n",    pgsqlsess.host,pgsqlsess.port);    }    }   #else -  if(pgsqlsess.options.force_ssl) +  if(pgsqlsess._options.force_ssl)    error("Encryption library missing,"    " cannot establish connection to %s:%d\n",    pgsqlsess.host,pgsqlsess.port);   #endif    break;    }    if(!socket->is_open())    error(strerror(socket->errno()));    socket->set_backend(local_backend);    socket->set_buffer_mode(i::this,0);
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:680:    Thread.MutexKey lock=prepbuffermux->lock();    prepbufferready->wait(lock);    lock=0;    if(_state==closed)    return;    prepbuffermux=0;    }    Stdio.Buffer plugbuffer=prepbuffer;    prepbuffer=0;    plugbuffer->add_int16(sizeof(_datarowdesc)); +  if(sizeof(_datarowdesc))    foreach(_datarowdesc;;mapping col)    plugbuffer->add_int16(oidformat(col.type)); -  +  else if(commitprefix->match(_query)) { +  Thread.MutexKey lock=pgsqlsess->_commitmux->lock(); +  if(pgsqlsess->_portalsinflight) { +  pgsqlsess->_waittocommit++; +  PD("Commit waiting for portals to finish\n"); +  pgsqlsess->_readyforcommit->wait(lock); +  pgsqlsess->_waittocommit--; +  } +  lock=0; +  }    PD("Bind portal %O statement %O\n",_portalname,_preparedname);    _fetchlimit=pgsqlsess->_fetchlimit;    _openportal();    PGassist bindbuffer=c->start(1);    _unnamedstatementkey=0;    bindbuffer->add_int8('B')->add_hstring(plugbuffer,4,4);    if(!_tprepared)    closestatement(bindbuffer,_preparedname);    _sendexecute(pgsqlsess->_fetchlimit    && !(cachealways[_query]
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:744:    plugbuffer->add("c\0\0\0\4");    case bound:    _state=closed;    lock=0;    PD("Close portal %O\n",_portalname);    if(sizeof(_portalname)) {    plugbuffer->add_int8('C')->add_hstring(({'P',_portalname,0}),4,4);    retval=flushsend;    } else    _unnamedportalkey=0; -  if(!--pgsqlsess->_portalsinflight && !alreadyfilled) { -  pgsqlsess->_readyforquerycount++; +  Thread.MutexKey lockc=pgsqlsess->_commitmux->lock(); +  if(!--pgsqlsess->_portalsinflight) { +  if(pgsqlsess->_waittocommit) { +  PD("Signal no portals in flight\n"); +  pgsqlsess->_readyforcommit->signal(); +  lockc=0; +  } else if(!alreadyfilled) +  pgsqlsess->_readyforquerycount++, retval=syncsend;    pgsqlsess->_pportalcount=0; -  retval=syncsend; +     } -  +  lockc=0;    }    lock=0;    return retval;    }       final void _processdataready() {    _rowsreceived++;    if(_rowsreceived==1)    PD("<%O _fetchlimit %d=min(%d||1,%d), _inflight %d\n",_portalname,    _fetchlimit,(_portalbuffersize>>1)*_rowsreceived/_bytesreceived,