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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:1229:    if(!waitforauthready)    waitforauthready=Thread.Condition();    lock=0;    PD("Schedule reconnect in %ds\n",tdelay);    _delayederror=0;    callout(reconnect,tdelay,1);    } else if(err)    _delayederror=err;   }    - private int reconnect(void|int force) { + private int reconnect() { +  int recon=0;    PD("(Re)connect\n"); -  if(!force) { +  {    Thread.MutexKey lock=_shortmux->lock();    if(waitforauthready) {    lock=0;    return 1; // Connect still in progress in other thread    }    waitforauthready=Thread.Condition();    lock=0;    }    if(c) {    PD("Close old connection\n"); -  reconnected++; +  reconnected++;recon=1;   #ifdef PG_STATS    prepstmtused=0;   #endif -  if(!force) +     c->sendterminate(); -  else -  c->close(); +     c=0;    PD("Flushing old cache\n");    foreach(_prepareds;;mapping tp)    m_delete(tp,"preparedname"); -  if(!_options.reconnect) { -  string msg=sprintf("Lost connection to database %s:%d",_host,_port); -  if(force) { -  lastmessage+=({msg}); -  return 0; -  } else -  ERROR(msg+"\n"); +  if(!_options.reconnect) +  ERROR("Lost connection to database %s:%d\n",_host,_port);    } -  } +     PD("Actually start to connect\n");    qportals=Thread.Queue();    _readyforcommit=Thread.Condition();    _readyforquerycount=1;    _waittocommit=0;    qportals->write(1); -  if(!(c=getsocket())) { -  string msg=sprintf("Couldn't connect to database on %s:%d",_host,_port); -  if(force) { -  if(!sizeof(lastmessage) || lastmessage[sizeof(lastmessage)-1]!=msg) -  lastmessage+=({msg}); -  return 0; -  } else -  ERROR(msg+"\n"); -  } +  if(!(c=getsocket())) +  ERROR("Couldn't connect to database on %s:%d\n",_host,_port);    _runtimeparameter=([]);    _unnamedportalmux=Thread.Mutex();    unnamedstatement=Thread.Mutex(); -  readyforquery_cb=force?reconnect_cb:connect_cb; +  readyforquery_cb=recon?reconnect_cb:connect_cb;    _portalsinflight=0;    return 1;   }      //! For PostgreSQL this function performs the same function as @[resync()].   //!   //! @seealso   //! @[resync()], @[cancelquery()]   /*semi*/final void reload() {    resync();