• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

comunication question

I have a server sending data on request to several hundreds of clients.

server and client are written in c++, communication is a class I've written and uses non-blocking sockets with winsock 2.

my question is:
What is the effect on my users if I use SO_LINGER with a timeout of 0, instead of SO_DONTLINGER ?

how will it affect reconnection to the server ?

1 Solution
LINGER structure is used by an application to set the linger socket option and specify the length of time to wait for unsent data before a socket is closed.

The LINGER stucture as U know has 2 members.
Following steps should be performed to enable or disable linger option.

A) To enable SO_LINGER, the application should set l_onoff to a nonzero value, set l_linger to zero or the desired timeout (in seconds), and call setsockopt.

B) To enable SO_DONTLINGER (that is, disable SO_LINGER) l_onoff should be set to zero and setsockopt should be called

Hence, giving value of timeout of 0 is not equivalent to

Enabling SO_LINGER with a nonzero timeout on a nonblocking socket is not good.
guyssAuthor Commented:
I wanted to know what the effect would be, I know how to do it...
if you do SO_LINGER with 0 time out it'll forcefully shut the connection off meaning it'll just terminate connection without giving the queued up packets a chance to be sent out. If you set SO_DONTLINGER then although it'll return immediately without blocking, te packets will get a chacne to be sent out
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

guyssAuthor Commented:
I use closesocket when I detect a disctonnection from the server, I use my own keep-alive/tiemout mechanism.

will the other side of the socket get any different response than when using SO_DONTLINGER ?

will I have any problems when the user attempts to reconnect, (i.e - open another socket for the same port and ip address) ?

well, when you have SO_DONTLINGER you won't be able to bind again to the same port/ip until the timer on the underlying layer has expired.
guyssAuthor Commented:
how would this be detected ? a failure in opening the socket again ? I never saw this happen.
I've not tried this under Windows. When I was doing development under Sun, I experience that bind will fail if I try to bind immediately after closing.
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to accept "dbusychild" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please do not accept this comment as an answer!
Per recommendation comment force/accepted by

Community Support Moderator
Experts Exchange

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now