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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:110:    if(mode>realbuffer->stashflushmode)    realbuffer->stashflushmode=mode;    return realbuffer->stashflushmode;   }      private inline mixed callout(function(mixed ...:void) f,    float|int delay,mixed ... args) {    return local_backend->call_out(f,delay,@args);   }    + private void nop() { } +    // Some pgsql utility functions      class bufcon {    inherit Stdio.Buffer;       private conxion realbuffer;       protected void create(conxion _realbuffer) {    realbuffer=_realbuffer;    }
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:148:    lock=0;    this->clear();    if(lock=realbuffer->nostash->trylock(1)) {    realbuffer->started=lock; lock=0;    realbuffer->sendcmd(SENDOUT);    }    }      }    - class conxion { + class conxiin {    inherit Stdio.Buffer:i; -  +  +  final Thread.Condition fillread; +  final Thread.Mutex fillreadmux; +  final function(:void) gottimeout; +  final int timeout; +  +  protected bool range_error(int howmuch) { + #ifdef PG_DEBUG +  if(howmuch<=0) +  error("Out of range %d\n",howmuch); + #endif +  if(fillread) { +  array cid=callout(gottimeout,timeout); +  Thread.MutexKey lock=fillreadmux->lock(); +  fillread.wait(lock); +  lock=0; +  local_backend->remove_call_out(cid); +  } else +  throw(MAGICTERMINATE); +  return true; +  } +  +  final int read_cb(mixed id,mixed b) { +  Thread.MutexKey lock=fillreadmux->lock(); +  if(fillread) +  fillread.signal(); +  lock=0; +  return 0; +  } +  +  protected void create() { +  i::create(); +  gottimeout=nop; // Preset it with a NOP +  timeout=128; // Just a reasonable amount +  fillreadmux=Thread.Mutex(); +  fillread=Thread.Condition(); +  } + } +  + class conxion {    inherit Stdio.Buffer:o; -  +  final conxiin i;    -  private Thread.Condition fillread; -  private Thread.Mutex fillreadmux; +     private Thread.Queue qportals;    final Thread.Mutex shortmux;    final Stdio.File socket;    private object pgsqlsess;    private int towrite;    -  final function(:void) gottimeout; -  final int timeout; +     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;   #ifdef PG_DEBUG    final int queueoutidx;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:198:    add(stash); stash->clear();    foreach(stashqueue->try_read_array();;sql_result portal)    queueup(portal);    lock=0;    return this;    }    stashcount++;    return bufcon(this);    }    -  protected bool range_error(int howmuch) { -  if(!howmuch) -  return false; - #ifdef PG_DEBUG -  if(howmuch<0) -  error("Out of range %d\n",howmuch); - #endif -  if(fillread) { -  array cid=callout(gottimeout,timeout); -  Thread.MutexKey lock=fillreadmux->lock(); -  fillread.wait(lock); -  lock=0; -  local_backend->remove_call_out(cid); -  } else -  throw(MAGICTERMINATE); -  return true; -  } -  -  private int read_cb(mixed id,mixed b) { -  Thread.MutexKey lock=fillreadmux->lock(); -  if(fillread) -  fillread.signal(); -  lock=0; -  return 0; -  } -  +     private int write_cb() {    Thread.MutexKey lock=shortmux->lock();    towrite-=output_to(socket,towrite);    lock=0; -  if(!fillread && !sizeof(this)) { +  if(!i->fillread && !sizeof(this)) {    PD("%d>Close socket delayed\n",socket->query_fd());    socket->close();    }    return 0;    }    -  final inline int consume(int w) { return i::consume(w); } -  final inline int unread(int w) { return i::unread(w); } -  final inline string read(int w) { return i::read(w); } -  final inline object read_buffer(int w) { return i::read_buffer(w); } -  final inline int read_sint(int w) { return i::read_sint(w); } -  final inline int read_int8() { return i::read_int8(); } -  final inline int read_int16() { return i::read_int16(); } -  final inline int read_int32() { return i::read_int32(); } -  final inline string read_cstring() { return i::read_cstring(); } -  +     final void sendcmd(void|int mode,void|sql_result portal) {    if(portal)    queueup(portal);   nosync:    do {    switch(mode) {    default:    break nosync;    case SYNCSEND:    PD("%d>Sync %d %d Queue\n",
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:304:    } while(0);    lock=started=0;    return;    };    lock=0;    if(pgsqlsess)    pgsqlsess->_connectfail();    }       final void sendterminate() { -  Thread.MutexKey lock=fillreadmux->lock(); -  fillread.signal(); -  fillread=0; // Delayed close() after flushing the output buffer +  Thread.MutexKey lock=i->fillreadmux->lock(); +  i->fillread.signal(); +  i->fillread=0; // Delayed close() after flushing the output buffer    lock=0;    }       final int close() {    destruct(nostash);    PD("%d>Close socket\n",socket->query_fd());    return socket->close();    }       protected void destroy() {
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:359:    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); -  socket->set_nonblocking(read_cb,write_cb,0); +  socket->set_buffer_mode(i,0); +  socket->set_nonblocking(i->read_cb,write_cb,0);    Thread.Thread(pgsqlsess->_processloop,this);    return;    };    if(pgsqlsess)    pgsqlsess->_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::this),i::_size_object(), +  sizeof(i),i->_size_object(),    qportals->size(),sizeof(this),_size_object());    break;    }    return res;    }       protected void create(object _pgsqlsess,Thread.Queue _qportals,int nossl) { -  i::create(); o::create(); +  o::create();    qportals = _qportals;    synctransact = 1; -  gottimeout=sendcmd; // Preset it with a NOP -  timeout=128; // Just a reasonable amount +     socket=Stdio.File(); -  fillreadmux=Thread.Mutex(); +  i=conxiin();    shortmux=Thread.Mutex();    nostash=Thread.Mutex(); -  fillread=Thread.Condition(); +     stashavail=Thread.Condition();    stashqueue=Thread.Queue();    stash=Stdio.Buffer();    pgsqlsess=_pgsqlsess;    Thread.Thread(connectloop,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 {       private object pgsqlsess;    private int eoffound;    private conxion c; -  +  private conxiin cr;    final mixed _delayederror;    final int _state;    final int _fetchlimit;    private int alltext;    final int _forcetext;       final string _portalname;       private int rowsreceived;    private int inflight;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:459:    _portalname,datarowdesc&&sizeof(datarowdesc),    statuscmdcomplete||(_unnamedstatementkey?"*parsing*":""));    break;    }    return res;    }       protected void create(object _pgsqlsess,conxion _c,string query,    int _portalbuffersize,int alltyped,array params,int forcetext) {    pgsqlsess = _pgsqlsess; -  c = _c; +  cr = (c = _c)->i;    _query = query;    datarows = Thread.Queue();    _ddescribe=Thread.Condition();    _ddescribemux=Thread.Mutex();    closemux=Thread.Mutex();    prepbufferready=Thread.Condition();    prepbuffermux=Thread.Mutex();    portalbuffersize=_portalbuffersize;    alltext = !alltyped;    _params = params;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:562: Inside #if defined(PG_DEBUG)
     #ifdef PG_DEBUG    final int   #else    final void   #endif    _decodedata(int msglen,string cenc) {    _storetiming();    string serror;    bytesreceived+=msglen; -  int cols=c->read_int16(); +  int cols=cr->read_int16();    array a=allocate(cols,!alltext&&Val.null);   #ifdef PG_DEBUG    msglen-=2+4*cols;   #endif    foreach(datarowdesc;int i;mapping m) { -  int collen=c->read_sint(4); +  int collen=cr->read_sint(4);    if(collen>0) {   #ifdef PG_DEBUG    msglen-=collen;   #endif    mixed value;    switch(int typ=m.type) {    case FLOAT4OID:   #if SIZEOF_FLOAT>=8    case FLOAT8OID:   #endif    if(!alltext) { -  value=(float)c->read(collen); +  value=(float)cr->read(collen);    break;    } -  default:value=c->read(collen); +  default:value=cr->read(collen);    break;    case CHAROID: -  value=alltext?c->read(1):c->read_int8(); +  value=alltext?cr->read(1):cr->read_int8();    break; -  case BOOLOID:value=c->read_int8(); +  case BOOLOID:value=cr->read_int8();    switch(value) {    case 'f':value=0;    break;    case 't':value=1;    }    if(alltext)    value=value?"t":"f";    break;    case TEXTOID:    case BPCHAROID:    case VARCHAROID: -  value=c->read(collen); +  value=cr->read(collen);    if(cenc==UTF8CHARSET && catch(value=utf8_to_string(value))    && !serror)    serror=SERROR("%O contains non-%s characters\n",    value,UTF8CHARSET);    break;    case INT8OID:case INT2OID:    case OIDOID:case INT4OID:    if(_forcetext) { -  value=c->read(collen); +  value=cr->read(collen);    if(!alltext)    value=(int)value;    } else {    switch(typ) { -  case INT8OID:value=c->read_sint(8); +  case INT8OID:value=cr->read_sint(8);    break; -  case INT2OID:value=c->read_sint(2); +  case INT2OID:value=cr->read_sint(2);    break;    case OIDOID: -  case INT4OID:value=c->read_sint(4); +  case INT4OID:value=cr->read_sint(4);    }    if(alltext)    value=(string)value;    }    }    a[i]=value;    } else if(!collen)    a[i]="";    }    _processdataready(a);