SO_KEEPALIVE doesnt' work

My server program hangs if the network connection or power is lost from my
client side…
I’m trying to use this SO_KEEPALIVE option to make my server program keep
running…it doesnt seem
to make any difference…:

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on, (sizeof)(on));

I just read that default timeout for SO_KEEPALIVE is at least 2 hours… is
ther another way
to make my server program not hang??

ran zhang <rzhang@vamcointernational.com> wrote in message
news:a5dfpn$3fc$1@inn.qnx.com

My server program hangs if the network connection or power is lost from my
client side…
I’m trying to use this SO_KEEPALIVE option to make my server program keep
running…it doesnt seem
to make any difference…:

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
(sizeof)(on));
\

“ran zhang” <rzhang@vamcointernational.com> wrote in
news:a5dhqu$4t7$1@inn.qnx.com:

I just read that default timeout for SO_KEEPALIVE is at least 2
hours… is ther another way
to make my server program not hang??

You can use setsockopt() to set the time when a KEEPALIVE is sent. A word
of warning, this option is not socket dependant, but affects everyone using
the stack.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Adam:
how would i modify the code to do a timeout?

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on, (sizeof)(on));




Adam Mallory <amallory@qnx.com> wrote in message
news:Xns91C1522BEF287amalloryqnxcom@209.226.137.4

“ran zhang” <> rzhang@vamcointernational.com> > wrote in
news:a5dhqu$4t7$> 1@inn.qnx.com> :

I just read that default timeout for SO_KEEPALIVE is at least 2
hours… is ther another way
to make my server program not hang??

You can use setsockopt() to set the time when a KEEPALIVE is sent. A word
of warning, this option is not socket dependant, but affects everyone
using
the stack.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

“ran zhang” <rzhang@vamcointernational.com> wrote in
news:a5iktp$r5g$1@inn.qnx.com:

Adam:
how would i modify the code to do a timeout?

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
(sizeof)(on));

If you’re looking to do timeouts on socket connections, perhaps you should
take a look at select() or try doing a heartbeat if you access to the
server and client code bases.


\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

ran zhang <rzhang@vamcointernational.com> wrote:

Adam:
how would i modify the code to do a timeout?

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on, (sizeof)(on));

Socket option TCP_KEEPALIVE to change that 2 hour.
Check the document for “tcp”.

-xtang


Adam Mallory <> amallory@qnx.com> > wrote in message
news:Xns91C1522BEF287amalloryqnxcom@209.226.137.4
“ran zhang” <> rzhang@vamcointernational.com> > wrote in
news:a5dhqu$4t7$> 1@inn.qnx.com> :

I just read that default timeout for SO_KEEPALIVE is at least 2
hours… is ther another way
to make my server program not hang??

You can use setsockopt() to set the time when a KEEPALIVE is sent. A word
of warning, this option is not socket dependant, but affects everyone
using
the stack.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

Look at “Bible”: UNIX, Network Programming -W. Richard Stevens - > Chapter
21
Regards !
Kostadin Vadin

“ran zhang” <rzhang@vamcointernational.com> wrote in message
news:a5dfpn$3fc$1@inn.qnx.com

My server program hangs if the network connection or power is lost from my
client side…
I’m trying to use this SO_KEEPALIVE option to make my server program keep
running…it doesnt seem
to make any difference…:

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
(sizeof)(on));
\

Xiaodan Tang <xtang@qnx.com> wrote in news:a5kov9$rgn$1@nntp.qnx.com:

ran zhang <> rzhang@vamcointernational.com> > wrote:
Adam:
how would i modify the code to do a timeout?

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
(sizeof)(on));

Socket option TCP_KEEPALIVE to change that 2 hour.
Check the document for “tcp”.

I just don’t like advocating the use of this as a mechanism for timing out
sockets. It’s usually a system wide attribute - hence the use of a heart
beat using OBD (or some other mechanism you can cook up) IMHO is better. I
agree it’s not always do-able, but without context in this case, I would
err on the side of caution.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Adam Mallory <amallory@qnx.com> wrote:

Xiaodan Tang <> xtang@qnx.com> > wrote in news:a5kov9$rgn$> 1@nntp.qnx.com> :

ran zhang <> rzhang@vamcointernational.com> > wrote:
Adam:
how would i modify the code to do a timeout?

msgsock = accept (sock, 0, 0) ;
int on = 1;
setsockopt (msgsock , SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
(sizeof)(on));

Socket option TCP_KEEPALIVE to change that 2 hour.
Check the document for “tcp”.

I just don’t like advocating the use of this as a mechanism for timing out
sockets. It’s usually a system wide attribute - hence the use of a heart
beat using OBD (or some other mechanism you can cook up) IMHO is better. I
agree it’s not always do-able, but without context in this case, I would
err on the side of caution.

Adam, I don’t have source to confirm, but TCP_KEEPALIVE IS socket
based.
This is an option that implemented by QSSL.

-xtang

Xiaodan Tang <xtang@qnx.com> wrote in news:a5r2p3$mec$2@nntp.qnx.com:

Adam, I don’t have source to confirm, but TCP_KEEPALIVE IS socket
based.
This is an option that implemented by QSSL.

Opps, wrong option - sorry.

-Adam