![]() |
| | #1 |
| Registered User Join Date: Oct 2003
Posts: 53
| recv() without waiting... |
| eam is offline | |
| | #2 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| What you do is to use select() to see if the socket is avialable to read from, if it is you do the read, if not you move on. |
| Thantos is offline | |
| | #3 |
| Registered User Join Date: Oct 2003
Posts: 53
| Do you know where I could find a decent select() example? |
| eam is offline | |
| | #4 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Yes in fact I do. Since I want you to work for it I'll give you a couple of hints instead of flat out telling you: Networking/Device Communication, search, Beej, select |
| Thantos is offline | |
| | #5 |
| Registered User Join Date: Oct 2003
Posts: 53
| Aww Beej's example is the example I found to be "undecent." One is too simplified (stdin! how do I do this with sockets?) and the other is too complex... Thanks anyway. |
| eam is offline | |
| | #6 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,683
| http://cboard.cprogramming.com/search.php Search: Key Word(s): select, recv Showing results 1 to 20 of 20 Search took 0.32 seconds. |
| Salem is offline | |
| | #7 |
| Registered User Join Date: Oct 2003
Posts: 53
| It still waits... What'd I do wrong? Code: fd_set readfds;
struct timeval count;
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
select(0, &readfds, 0, 0, &count);
if (FD_ISSET(sockfd, &readfds))
{
if ((bytes=recv(sockfd, buffer2, 200, 0)) == -1) {
return 0;
}
}
|
| eam is offline | |
| | #8 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,683
| > What'd I do wrong? You didn't initialise count You didn't check the return result |
| Salem is offline | |
| | #9 |
| Politics&Cpp geek Join Date: Oct 2004
Posts: 104
| Im no expert here, but might WSAAsyncSelect fulfil your requirements? http://msdn.microsoft.com/library/en...ncselect_2.asp What it does: It makes all the WINSOCK functions which usually waits for such things as you desribed, before moving on. This often hang your programs. This function makes such functions return if nothing are found, and when they succseed(or something else, which you can pass as a parameter), they send your program a WM_SOMETHING instead Looks to me like this is exactly what you need? ![]() Moore info about this can also be found at the botttom of this page: http://www.hal-pc.org/~johnnie2/winsock.html A sweet tutorial.. Last edited by Da-Nuka; 02-28-2005 at 09:54 AM. |
| Da-Nuka is offline | |
| | #10 |
| Registered User Join Date: Dec 2004
Posts: 95
| Yes, WSAAsyncSelect or other related functions are probably more appropriate for a Windows app. |
| azteched is offline | |
| | #11 | |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Of course no where has it been said if this is for a Window's app. select() is a better solution if you want it to be cross platform. Quote:
You need to initalize your count with the maxiumn timeout value. After the call it's value can be how much time was left (or is it how long did it wait) or the same value. You can't be exactly sure so each time you have to reset count. | |
| Thantos is offline | |
| | #12 |
| End Of Line Join Date: Apr 2002
Posts: 6,240
| Another example: http://faq.cprogramming.com/cgi-bin/...=1045780608#03
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] |
| Hammer is offline | |
| | #13 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 3,020
| Code: select(0, &readfds, 0, 0, &count); |
| bithub is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| recv() returns 0 the second time | Overlord | Networking/Device Communication | 7 | 07-10-2009 04:09 AM |
| Question about recv | carrotcake1029 | Networking/Device Communication | 2 | 02-26-2009 02:10 PM |
| Query related to recv()? | dp_76 | Networking/Device Communication | 4 | 05-16-2005 07:25 AM |
| recv() | afisher | Networking/Device Communication | 3 | 03-24-2004 05:32 PM |
| non blocking recv | rohit | Linux Programming | 4 | 03-05-2002 09:35 PM |