LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-18-2013, 03:13 AM   #1
niteen
Member
 
Registered: Mar 2013
Location: India
Distribution: Fedora
Posts: 61

Rep: Reputation: Disabled
setsockopt timeout problem


i gotta decrease timeout value for connect socket..
i am using likewise putting setsockopt twice
Code:
	struct timeval tv;
        tv.tv_sec = 0;
	int y;

	setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&y, sizeof(y));
	setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));
it's still taking time..
any assistance please!!
 
Old 03-18-2013, 07:48 AM   #2
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,535

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Initialize the variable 'y' to 1 (one) before calling the first setsockopt() call.

As for setting the timeout on the socket, use SO_SNDTIMEO, not SO_RCVTIMEO, so that the connect() call returns sooner should there be a failure to connect to the server. You also should set some non-zero timeout period.

For example:
Code:
struct timeval tv = { 0, 100 };    // 0 seconds, 100 microseconds
int y = 1;

setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&y, sizeof(y));
setsockopt( sockfd, SOL_SOCKET, SO_SNDTIMEO,(struct timeval *)&tv, sizeof(struct timeval));
 
Old 03-20-2013, 05:33 AM   #3
niteen
Member
 
Registered: Mar 2013
Location: India
Distribution: Fedora
Posts: 61

Original Poster
Rep: Reputation: Disabled
yup! thats working well..

thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setsockopt: SO_RCVTIMEO Ephracis Programming 2 03-18-2013 03:43 AM
problem with setsockopt errornumbers GeriN Programming 2 03-18-2013 03:37 AM
setsockopt for SCTP_PEER_ADDR_PARAMS oxyjohn Programming 5 05-07-2007 12:29 PM
setsockopt() in kernel? hegdeshashi Linux - Networking 0 01-12-2006 01:17 AM
setsockopt Mercurius Programming 6 12-24-2005 08:16 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration