-
August 16th, 2005, 03:03 PM
#1
example of SO_RCVTIMEO using setsockopt()
Hi,
I want to implement a timeout using SO_RCVTIMEO using setsockopt().
Does anyone have some example on this in C/VC?.
I want to do this for the recv() command.
The receive timeout is 20 secs.
Thanks
-
August 16th, 2005, 04:44 PM
#2
Re: example of SO_RCVTIMEO using setsockopt()
Code:
struct timeval tv;
tv.tv_sec = 30; /* 30 Secs Timeout */
setsockopt(sockid, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));
Thanks,
-
November 12th, 2007, 02:20 PM
#3
Re: example of SO_RCVTIMEO using setsockopt()
This works, except "recv" returns after 500ms regardless of the value on my system...
Axl
-
November 12th, 2007, 11:16 PM
#4
Re: example of SO_RCVTIMEO using setsockopt()
Maybe you have actually received data.
Mike
PS: Start a new thread. This one's more than two years old
-
May 20th, 2009, 01:24 PM
#5
Re: example of SO_RCVTIMEO using setsockopt()
Originally Posted by nkhambal
Code:
struct timeval tv;
tv.tv_sec = 30; /* 30 Secs Timeout */
setsockopt(sockid, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));
Thanks,
doesn't work, says can't converth 4th parameter from 'timeval *' to 'const char'
-
April 13th, 2010, 08:55 PM
#6
Re: example of SO_RCVTIMEO using setsockopt()
Originally Posted by Owyn
doesn't work, says can't converth 4th parameter from 'timeval *' to 'const char'
Change to:
setsockopt(sockid, SOL_SOCKET, SO_RCVTIMEO,(char *)&tv,sizeof(struct timeval));
-
April 14th, 2010, 10:15 AM
#7
Re: example of SO_RCVTIMEO using setsockopt()
Heh. Initial post was 2005. Then nothing, until 2007. Then nothing, until 2009. Then nothing until yesterday. Well, at least the responses are getting "quicker"!
Viggy
-
July 12th, 2010, 08:31 PM
#8
Re: example of SO_RCVTIMEO using setsockopt()
first... THANX...
It works for me, but 'tv.tv_sec' seams to be in miliseconds not in seconds. If i put 5000 i got a 5 sec. timeout.
-
March 18th, 2011, 01:16 PM
#9
Re: example of SO_RCVTIMEO using setsockopt()
Are you sure the struct timeval should be used as a parameter?
I suppose timeout should be rather passed as int (or unsigned int), in milliseconds:
int nTimeout = 30000; // 30 seconds
setsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&nTimeout, sizeof(int));
Unfortunately, this is not specified in setsockopt's documentation.
-
March 18th, 2011, 03:47 PM
#10
Re: example of SO_RCVTIMEO using setsockopt()
The timing of posts to this thread is hysterical.
-
April 4th, 2011, 05:52 AM
#11
Re: example of SO_RCVTIMEO using setsockopt()
WINDOWS:
Timeout value is a DWORD in milliseconds, address passed to setsockopt() is const char *
LINUX:
Timeout value is a struct timeval, address passed to setsockopt() is const void *
-
February 25th, 2015, 12:26 PM
#12
Re: example of SO_RCVTIMEO using setsockopt()
Originally Posted by grant.s
WINDOWS:
Timeout value is a DWORD in milliseconds, address passed to setsockopt() is const char *
LINUX:
Timeout value is a struct timeval, address passed to setsockopt() is const void *
Thank you!
I need to find a good cheat-sheet reference for all the diffs between BSD and winsock.
-Ed
-
November 18th, 2016, 04:34 AM
#13
Re: example of SO_RCVTIMEO using setsockopt()
vcdeveloper, I think we are close to finding a solution to your issue.
Is it acceptable for a 21 second timeout instead of the 20 seconds you requested?
-
December 13th, 2016, 10:13 AM
#14
Re: example of SO_RCVTIMEO using setsockopt()
By various reasons I would like to implement timeout on reading and writing to socket in a server but fail to get it running and therefore kindly ask for some insight into wherein the problem may reside.
In order to set the timeout on the read and write to the socket I'm trying to use of the functions setsocketopt() and getsocketopt(). However I must be doing something wrong as the return value indicates that a problem have occurred and perror outputs "Invalid argument". Strangely enough the error does not always occur at the first usage of setsocketopt() and getsocketopt(), which puzzles me bit.
-
December 13th, 2016, 11:54 AM
#15
Re: example of SO_RCVTIMEO using setsockopt()
Originally Posted by essay
...
In order to set the timeout on the read and write to the socket I'm trying to use of the functions setsocketopt() and getsocketopt(). However I must be doing something wrong as the return value indicates that a problem have occurred and perror outputs "Invalid argument".
You might want to post your code so we could see how you did it...
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|