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

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql.pike:269:   //! This function returns a string describing what host are we talking to,   //! and how (TCP/IP or UNIX sockets).   //!   //! @seealso   //! @[server_info()]   string host_info()   { return sprintf("fd:%d TCP/IP %s:%d PID %d",    _c?_c.query_fd():-1,host,port,backendpid);   }    + //! Returns true if the connection seems to be open. + //! + //! @note + //! This function only checks that there's an open connection, + //! and that the other end hasn't closed it yet. No data is + //! sent over the connection. + //! + //! For a more reliable check of whether the connection + //! is alive, please use @[ping()]. + //! + //! @seealso + //! @[ping()] + int is_open() + { return _c&&_c.query_fd()>=0; + } +  + //! @decl int ping() + //! + //! Check whether the connection is alive. + //! + //! @returns + //! Returns one of the following: + //! @int + //! @value 0 + //! Everything ok. + //! @value 1 + //! The connection reconnected automatically. + //! @value -1 + //! The server has gone away, and the connection is dead. + //! @endint + //! + //! @seealso + //! @[is_open()] + int ping() + { int oldbackendpid=backendpid; +  mixed err; +  if(_c && (err = catch +  { _c.sendflush(); +  return backendpid!=oldbackendpid; +  })) +  { PD("%O\n",err); +  if(reconnect(1)) +  return 1; +  } +  return -1; + } +    final private object getsocket(void|int nossl)   { object lcon = Stdio.File();    if(!lcon.connect(host,port))    return UNDEFINED;       object fcon;   #if constant(SSL.sslfile)    if(!nossl && (options->use_ssl || options->force_ssl))    { PD("SSLRequest\n");    { object c=.pgsql_util.PGassist();
pike.git/lib/modules/Sql.pmod/pgsql.pike:1076:    _c.close();    _c=0;    foreach(prepareds;;mapping tp)    m_delete(tp,"preparedname");    if(!options->reconnect || !(connectmtxkey = _stealmutex.trylock(2)))    return 0; // Recursive reconnect, bailing out    }    if(!(_c=getsocket()))    { string msg=sprintf("Couldn't connect to database on %s:%d",host,port);    if(force) -  { lastmessage+=({msg}); +  { if(!sizeof(lastmessage) || lastmessage[sizeof(lastmessage)-1]!=msg) +  lastmessage+=({msg});    return 0;    }    else    ERROR(msg+"\n");    }    _closesent=0;    _mstate=unauthenticated;    qstate=queryidle;    _runtimeparameter=([]);    array(string) plugbuf=({"",_c.plugint32(PG_PROTOCOL(3,0))});