@ -391,9 +391,13 @@ pgthreadlock_t pg_g_threadlock = default_threadlock;
* Close any physical connection to the server , and reset associated
* Close any physical connection to the server , and reset associated
* state inside the connection object . We don ' t release state that
* state inside the connection object . We don ' t release state that
* would be needed to reconnect , though .
* would be needed to reconnect , though .
*
* We can always flush the output buffer , since there ' s no longer any hope
* of sending that data . However , unprocessed input data might still be
* valuable , so the caller must tell us whether to flush that or not .
*/
*/
void
void
pqDropConnection ( PGconn * conn )
pqDropConnection ( PGconn * conn , bool flushInput )
{
{
/* Drop any SSL state */
/* Drop any SSL state */
pqsecure_close ( conn ) ;
pqsecure_close ( conn ) ;
@ -401,8 +405,10 @@ pqDropConnection(PGconn *conn)
if ( conn - > sock ! = PGINVALID_SOCKET )
if ( conn - > sock ! = PGINVALID_SOCKET )
closesocket ( conn - > sock ) ;
closesocket ( conn - > sock ) ;
conn - > sock = PGINVALID_SOCKET ;
conn - > sock = PGINVALID_SOCKET ;
/* Discard any unread/unsent data */
/* Optionally discard any unread data */
if ( flushInput )
conn - > inStart = conn - > inCursor = conn - > inEnd = 0 ;
conn - > inStart = conn - > inCursor = conn - > inEnd = 0 ;
/* Always discard any unsent data */
conn - > outCount = 0 ;
conn - > outCount = 0 ;
}
}
@ -1510,7 +1516,7 @@ connectDBStart(PGconn *conn)
return 1 ;
return 1 ;
connect_errReturn :
connect_errReturn :
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_BAD ;
conn - > status = CONNECTION_BAD ;
return 0 ;
return 0 ;
}
}
@ -1732,7 +1738,7 @@ keep_going: /* We will come back to here until there is
{
{
if ( ! connectNoDelay ( conn ) )
if ( ! connectNoDelay ( conn ) )
{
{
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > addr_cur = addr_cur - > ai_next ;
conn - > addr_cur = addr_cur - > ai_next ;
continue ;
continue ;
}
}
@ -1742,7 +1748,7 @@ keep_going: /* We will come back to here until there is
appendPQExpBuffer ( & conn - > errorMessage ,
appendPQExpBuffer ( & conn - > errorMessage ,
libpq_gettext ( " could not set socket to nonblocking mode: %s \n " ) ,
libpq_gettext ( " could not set socket to nonblocking mode: %s \n " ) ,
SOCK_STRERROR ( SOCK_ERRNO , sebuf , sizeof ( sebuf ) ) ) ;
SOCK_STRERROR ( SOCK_ERRNO , sebuf , sizeof ( sebuf ) ) ) ;
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > addr_cur = addr_cur - > ai_next ;
conn - > addr_cur = addr_cur - > ai_next ;
continue ;
continue ;
}
}
@ -1753,7 +1759,7 @@ keep_going: /* We will come back to here until there is
appendPQExpBuffer ( & conn - > errorMessage ,
appendPQExpBuffer ( & conn - > errorMessage ,
libpq_gettext ( " could not set socket to close-on-exec mode: %s \n " ) ,
libpq_gettext ( " could not set socket to close-on-exec mode: %s \n " ) ,
SOCK_STRERROR ( SOCK_ERRNO , sebuf , sizeof ( sebuf ) ) ) ;
SOCK_STRERROR ( SOCK_ERRNO , sebuf , sizeof ( sebuf ) ) ) ;
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > addr_cur = addr_cur - > ai_next ;
conn - > addr_cur = addr_cur - > ai_next ;
continue ;
continue ;
}
}
@ -1800,7 +1806,7 @@ keep_going: /* We will come back to here until there is
if ( err )
if ( err )
{
{
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > addr_cur = addr_cur - > ai_next ;
conn - > addr_cur = addr_cur - > ai_next ;
continue ;
continue ;
}
}
@ -1887,7 +1893,7 @@ keep_going: /* We will come back to here until there is
* failure and keep going if there are more addresses .
* failure and keep going if there are more addresses .
*/
*/
connectFailureMessage ( conn , SOCK_ERRNO ) ;
connectFailureMessage ( conn , SOCK_ERRNO ) ;
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
/*
/*
* Try the next address , if any .
* Try the next address , if any .
@ -1932,7 +1938,7 @@ keep_going: /* We will come back to here until there is
* error message .
* error message .
*/
*/
connectFailureMessage ( conn , optval ) ;
connectFailureMessage ( conn , optval ) ;
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
/*
/*
* If more addresses remain , keep trying , just as in the
* If more addresses remain , keep trying , just as in the
@ -2220,7 +2226,7 @@ keep_going: /* We will come back to here until there is
/* only retry once */
/* only retry once */
conn - > allow_ssl_try = false ;
conn - > allow_ssl_try = false ;
/* Must drop the old connection */
/* Must drop the old connection */
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_NEEDED ;
conn - > status = CONNECTION_NEEDED ;
goto keep_going ;
goto keep_going ;
}
}
@ -2331,7 +2337,7 @@ keep_going: /* We will come back to here until there is
{
{
conn - > pversion = PG_PROTOCOL ( 2 , 0 ) ;
conn - > pversion = PG_PROTOCOL ( 2 , 0 ) ;
/* Must drop the old connection */
/* Must drop the old connection */
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_NEEDED ;
conn - > status = CONNECTION_NEEDED ;
goto keep_going ;
goto keep_going ;
}
}
@ -2397,7 +2403,7 @@ keep_going: /* We will come back to here until there is
/* only retry once */
/* only retry once */
conn - > wait_ssl_try = false ;
conn - > wait_ssl_try = false ;
/* Must drop the old connection */
/* Must drop the old connection */
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_NEEDED ;
conn - > status = CONNECTION_NEEDED ;
goto keep_going ;
goto keep_going ;
}
}
@ -2413,7 +2419,7 @@ keep_going: /* We will come back to here until there is
/* only retry once */
/* only retry once */
conn - > allow_ssl_try = false ;
conn - > allow_ssl_try = false ;
/* Must drop the old connection */
/* Must drop the old connection */
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_NEEDED ;
conn - > status = CONNECTION_NEEDED ;
goto keep_going ;
goto keep_going ;
}
}
@ -2574,7 +2580,7 @@ keep_going: /* We will come back to here until there is
PQclear ( res ) ;
PQclear ( res ) ;
conn - > send_appname = false ;
conn - > send_appname = false ;
/* Must drop the old connection */
/* Must drop the old connection */
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_NEEDED ;
conn - > status = CONNECTION_NEEDED ;
goto keep_going ;
goto keep_going ;
}
}
@ -2971,7 +2977,7 @@ closePGconn(PGconn *conn)
/*
/*
* Close the connection , reset all transient state , flush I / O buffers .
* Close the connection , reset all transient state , flush I / O buffers .
*/
*/
pqDropConnection ( conn ) ;
pqDropConnection ( conn , true ) ;
conn - > status = CONNECTION_BAD ; /* Well, not really _bad_ - just
conn - > status = CONNECTION_BAD ; /* Well, not really _bad_ - just
* absent */
* absent */
conn - > asyncStatus = PGASYNC_IDLE ;
conn - > asyncStatus = PGASYNC_IDLE ;