/* Drop any SSL state */
pqsecure_close(conn);
/* Close the socket itself */
- if (conn->sock >= 0)
+ if (conn->sock != PGINVALID_SOCKET)
closesocket(conn->sock);
- conn->sock = -1;
+ conn->sock = PGINVALID_SOCKET;
/* Discard any unread/unsent data */
conn->inStart = conn->inCursor = conn->inEnd = 0;
conn->outCount = 0;
addr_cur->ai_addrlen);
conn->raddr.salen = addr_cur->ai_addrlen;
- /* Open a socket */
- {
- /*
- * While we use 'pgsocket' as the socket type in the
- * backend, we use 'int' for libpq socket values.
- * This requires us to map PGINVALID_SOCKET to -1
- * on Windows.
- * See http://msdn.microsoft.com/en-us/library/windows/desktop/ms740516%28v=vs.85%29.aspx
- */
- pgsocket sock = socket(addr_cur->ai_family, SOCK_STREAM, 0);
-#ifdef WIN32
- if (sock == PGINVALID_SOCKET)
- conn->sock = -1;
- else
-#endif
- conn->sock = sock;
- }
- if (conn->sock == -1)
+ conn->sock = socket(addr_cur->ai_family, SOCK_STREAM, 0);
+ if (conn->sock == PGINVALID_SOCKET)
{
/*
* ignore socket() failure if we have more addresses
conn->client_encoding = PG_SQL_ASCII;
conn->std_strings = false; /* unless server says differently */
conn->verbosity = PQERRORS_DEFAULT;
- conn->sock = -1;
+ conn->sock = PGINVALID_SOCKET;
conn->auth_req_received = false;
conn->password_needed = false;
conn->dot_pgpass_used = false;
* Note that the protocol doesn't allow us to send Terminate messages
* during the startup phase.
*/
- if (conn->sock >= 0 && conn->status == CONNECTION_OK)
+ if (conn->sock != PGINVALID_SOCKET && conn->status == CONNECTION_OK)
{
/*
* Try to send "close connection" message to backend. Ignore any
if (!conn)
return NULL;
- if (conn->sock < 0)
+ if (conn->sock == PGINVALID_SOCKET)
return NULL;
cancel = malloc(sizeof(PGcancel));
if (!conn)
return FALSE;
- if (conn->sock < 0)
+ if (conn->sock == PGINVALID_SOCKET)
{
strlcpy(conn->errorMessage.data,
"PQrequestCancel() -- connection is not open\n",
{
if (!conn)
return -1;
- return conn->sock;
+ return (conn->sock != PGINVALID_SOCKET) ? conn->sock : -1;
}
int
int someread = 0;
int nread;
- if (conn->sock < 0)
+ if (conn->sock == PGINVALID_SOCKET)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("connection not open\n"));
int remaining = conn->outCount;
int result = 0;
- if (conn->sock < 0)
+ if (conn->sock == PGINVALID_SOCKET)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("connection not open\n"));
if (!conn)
return -1;
- if (conn->sock < 0)
+ if (conn->sock == PGINVALID_SOCKET)
{
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("socket not open\n"));
/* Connection data */
/* See PQconnectPoll() for how we use 'int' and not 'pgsocket'. */
- int sock; /* Unix FD for socket, -1 if not connected */
+ pgsocket sock; /* FD for socket, PGINVALID_SOCKET if unconnected */
SockAddr laddr; /* Local address */
SockAddr raddr; /* Remote address */
ProtocolVersion pversion; /* FE/BE protocol version in use */