Re: support for keep alive option

From: PG User <pguser1982(at)gmail(dot)com>
To: Barry Bell <Barry(dot)Bell(at)hartehanks(dot)com>
Cc: "pgsql-odbc(at)postgresql(dot)org" <pgsql-odbc(at)postgresql(dot)org>
Subject: Re: support for keep alive option
Date: 2013-12-31 00:29:46
Message-ID: CAB7tN8YQzb-ToQw1zNCuUZJQGLgsJLW01LXX1Z2AfNfrW5tBpA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)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(dot)Bell(at)hartehanks(dot)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(dot)Bell(at)hartehanks(dot)com
>>
>> 1525 NW 3rd ST, Deerfield Beach, FL 33442
>>
>> <https://www.facebook.com/HarteHanks>
>>
>> <https://twitter.com/HarteHanks>
>>
>> <http://www.linkedin.com/company/hartehanks>
>>
>>
>>
>>
>>
>>
>>
>> *www.hartehanks.com <http://www.hartehanks.com/>*
>>
>>
>>
>>
>>
>>
>>
>> *From:* pgsql-odbc-owner(at)postgresql(dot)org [mailto:
>> pgsql-odbc-owner(at)postgresql(dot)org] *On Behalf Of *PG User
>> *Sent:* Tuesday, December 17, 2013 4:27 PM
>> *To:* pgsql-odbc(at)postgresql(dot)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 Content-Type Size
keep_alive.diff text/plain 722 bytes

In response to

Responses

Browse pgsql-odbc by date

  From Date Subject
Next Message Pavel Raiskup 2014-01-06 09:00:41 Static analysis fix request
Previous Message Bart Klein Ikink 2013-12-24 16:08:33 Re: Database link from Postgres to Oracle using ODBC