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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:580:    lock=0;    PD("%d Wait for auth ready released.\n",c?->socket&&c->socket->query_fd());    }   }      private inline mixed callout(function(mixed ...:void) f,    float|int delay,mixed ... args) {    return .pgsql_util.local_backend->call_out(f,delay,@args);   }    + private int|.pgsql_util.sql_result portal; // state information procmessage + #ifdef PG_DEBUG + private string datarowdebug; + private int datarowdebugcount; + #endif +    final void _processloop(.pgsql_util.conxion ci) { -  int terminating=0; -  .pgsql_util.conxiin cr=ci->i; -  int|.pgsql_util.sql_result portal; -  mixed err; +  (c=ci)->socket->set_id(procmessage); +  cancelsecret=0; +  portal=0;    {    Stdio.Buffer plugbuffer=Stdio.Buffer()->add_int32(PG_PROTOCOL(3,0));    if(user)    plugbuffer->add("user\0",user,0);    if(database)    plugbuffer->add("database\0",database,0);    _options.reconnect=undefinedp(_options.reconnect) || _options.reconnect;    foreach(_options-.pgsql_util.censoroptions; string name; mixed value)    plugbuffer->add(name,0,(string)value,0);    plugbuffer->add_int8(0);    PD("%O\n",(string)plugbuffer);    if(catch(ci->start()->add_hstring(plugbuffer,4,4)->sendcmd(SENDOUT))) {   #ifdef PG_DEBUG    if(!_options)    PD("_options is zero, %O\n",this);   #endif    if(_options && _options.reconnect) // FIXME why can _options be 0?    _connectfail();    else    destruct(waitforauthready); -  return; +  } else // Do not flush at this point, PostgreSQL 9.4 disapproves +  procmessage();    } -  } // Do not flush at this point, PostgreSQL 9.4 disapproves -  cancelsecret=0; + } +  + private void procmessage() { +  int terminating=0; +  .pgsql_util.conxion ci=c; // cache value FIXME sensible? +  .pgsql_util.conxiin cr=ci->i; // cache value FIXME sensible? +  mixed err;   #ifdef PG_DEBUG    PD("Processloop\n"); -  string datarowdebug; -  int datarowdebugcount; +        void showportal(int msgtype) {    if(objectp(portal))    PD("%d<%O %d %c switch portal\n",    ci->socket->query_fd(),portal._portalname,++ci->queueinidx,msgtype);    else if(portal>0)    PD("%d<Sync %d %d %c portal\n",    ci->socket->query_fd(),++ci->queueinidx,portal,msgtype);    };   #endif    for(;;) {    err=catch {   #ifdef PG_DEBUG    if(!portal && datarowdebug) {    PD("%s rows %d\n",datarowdebug,datarowdebugcount);    datarowdebug=0; datarowdebugcount=0;    }   #endif -  +  if(!sizeof(cr)) { // Preliminary check, fast path +  Thread.MutexKey lock=cr->fillreadmux->lock(); +  if(!sizeof(cr)) { // Check for real +  cr->procmsg=1; +  lock=0; +  return; // Terminate thread, wait for callback +  } +  lock=0; +  }    int msgtype=cr->read_int8();    if(!portal) {    portal=qportals->try_read();   #ifdef PG_DEBUG    showportal(msgtype);   #endif    }    int msglen=cr->read_int32();    _msgsreceived++;    _bytesreceived+=1+msglen;