Re: support for keep alive option - Mailing list pgsql-odbc

From PG User
Subject Re: support for keep alive option
Date
Msg-id CAB7tN8YQzb-ToQw1zNCuUZJQGLgsJLW01LXX1Z2AfNfrW5tBpA@mail.gmail.com
Whole thread Raw
In response to Re: support for keep alive option  (PG User <pguser1982@gmail.com>)
List pgsql-odbc
Hi Barry,
I changed the code and tested it and keep alive option is working fine for me now.
Is this patch ok to add to postgres odbc driver?

The patch is very simple as follows:

diff --git a/socket.c b/socket.c
index 2e3e1cc..ac17b4d 100644
--- a/socket.c
+++ b/socket.c
@@ -330,6 +330,19 @@ retry:
         fcntl(self->socket, F_SETFL, O_NONBLOCK);
 #endif

+       {
+               int optval;
+               socklen_t optlen;
+               optval=1;
+               optlen = sizeof(optval);
+
+               if(setsockopt(self->socket, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0)
+               {
+                       SOCK_set_error(self, SOCKET_COULD_NOT_CONNECT, "Could not set socket to SO_KEEPALIVE.");
+                       goto cleanup;
+               }
+       }
+
        if (curadr)
        {
                struct sockaddr *in = (struct sockaddr *) &(self->sadr_area);





On Tue, Dec 17, 2013 at 3:25 PM, PG User <pguser1982@gmail.com> wrote:
Hi Barry,
Thank you for reply.
I am little bit confused.

I saw the code for JDBC code and it sets true to
newStream.getSocket().setKeepAlive(requireTCPKeepAlive);
if ?tchKeepAlive=true is given.


But, in socket.c of odbc driver, in  
char
SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname, long timeout)

Can we just do the same thing?:
setsockopt(self->socket, IPPROTO_TCP, TCP_KEEPALIVE, (char *) &i, len);

as did in the same function:

if (setsockopt(self->socket, IPPROTO_TCP, TCP_NODELAY, (char *) &i, len) < 0) { SOCK_set_error(self, SOCKET_COULD_NOT_CONNECT, "Could not set socket to NODELAY."); closesocket(self->socket); self->socket = (SOCKETFD) -1; return 0; }

- Nachiket


On Tue, Dec 17, 2013 at 1:29 PM, Barry Bell <Barry.Bell@hartehanks.com> wrote:

The “keep alive” option is set inside the client, not the driver,

What ever programing language you are using may have a keep alive ( and timeout settings) for the OBDC driver.

 

Barry Bell

Senior Developer/Analyst, Harte Hanks Logsitics

Harte Hanks, Inc.

 

Office: 954-429-3771 Ext 267 Barry.Bell@hartehanks.com

1525 NW 3rd ST, Deerfield Beach, FL 33442

 

 

 

www.hartehanks.com

 

 

 

From: pgsql-odbc-owner@postgresql.org [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of PG User
Sent: Tuesday, December 17, 2013 4:27 PM
To: pgsql-odbc@postgresql.org
Subject: [ODBC] support for keep alive option

 

Hi,

I looking at code and found that there is an option for tpch keep alive in jdbc driver but there is no such support in odbc driver.

Is there any plan to support that in near future?

 

Thanking you.

 

- pguser



Attachment

pgsql-odbc by date:

Previous
From: Bart Klein Ikink
Date:
Subject: Re: Database link from Postgres to Oracle using ODBC
Next
From: Pavel Raiskup
Date:
Subject: Static analysis fix request