Thread View: borland.public.cppbuilder.internet.socket
16 messages
16 total messages
Started by Eduardo Jauch
Sat, 30 Jun 2007 18:04
timeout of recv
Author: Eduardo Jauch
Date: Sat, 30 Jun 2007 18:04
Date: Sat, 30 Jun 2007 18:04
12 lines
1205 bytes
1205 bytes
Hello! My modem have some "problems", and eventually, he turns a "Timeout" message when I try to access any page. I have an aplication that use send and recv to access a page, and when this happens, the recv don't "return". How to adjust the timeout of recv? There's a way to do this? Thanks!
Re: timeout of recv
Author: Eduardo Jauch
Date: Sat, 30 Jun 2007 18:23
Date: Sat, 30 Jun 2007 18:23
22 lines
1539 bytes
1539 bytes
Eduardo Jauch escreveu: > Hello! > > My modem have some "problems", and eventually, he turns a "Timeout" > message when I try to access any page. > > I have an aplication that use send and recv to access a page, and when > this happens, the recv don't "return". > > How to adjust the timeout of recv? There's a way to do this? > > > Thanks! In time... I use non-block sockets... So, looks I can't use select... right? Anyway, Select seens to be a very "slow" method, isn't it? Thanks!
Re: timeout of recv
Author: Eduardo Jauch
Date: Sat, 30 Jun 2007 18:47
Date: Sat, 30 Jun 2007 18:47
34 lines
1753 bytes
1753 bytes
Eduardo Jauch escreveu: > Eduardo Jauch escreveu: >> Hello! >> >> My modem have some "problems", and eventually, he turns a "Timeout" >> message when I try to access any page. >> >> I have an aplication that use send and recv to access a page, and when >> this happens, the recv don't "return". >> >> How to adjust the timeout of recv? There's a way to do this? >> >> >> Thanks! > > > In time... > > I use non-block sockets... So, looks I can't use select... right? > > Anyway, Select seens to be a very "slow" method, isn't it? > > Thanks! A litle correction... I don't know if my application is "non-block" (because I allways am confused about this... rsrsrs) I use a SOCK_STREAM type socket. And many send/recv. All send will have a recv unless there an error or the server don't respond. Thanks.
Re: timeout of recv
Author: Bob Gonder
Date: Sat, 30 Jun 2007 23:13
Date: Sat, 30 Jun 2007 23:13
21 lines
1807 bytes
1807 bytes
Eduardo Jauch wrote: >>> I have an aplication that use send and recv to access a page, and when >>> this happens, the recv don't "return". >>> >>> How to adjust the timeout of recv? There's a way to do this? So, are you using the Windows API <winsock2.h> ? setsockopt() with SO_RCVTIMEO >> I use non-block sockets... So, looks I can't use select... right? >A litle correction... >I don't know if my application is "non-block" (because I allways am >confused about this... rsrsrs) If your program calls recv and expects the data to be there at the end of the call, then it is "blocked" at that point. If your program calls WSARecv with the Overlapped options set, and continues on doing other things, hoping someday the data will arrive and be handled by the OverlapedRoutine, then it is "non-blocking".
Re: timeout of recv
Author: Colin B Maharaj
Date: Sun, 01 Jul 2007 02:48
Date: Sun, 01 Jul 2007 02:48
24 lines
1533 bytes
1533 bytes
What you want will probably look something like this...... struct timeval timeo; timeo.tv_sec = 1; timeo.tv_usec = 0; int ret = setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeo, sizeof(timeo)); Eduardo Jauch wrote: > Hello! > > My modem have some "problems", and eventually, he turns a "Timeout" > message when I try to access any page. > > I have an aplication that use send and recv to access a page, and when > this happens, the recv don't "return". > > How to adjust the timeout of recv? There's a way to do this? > > > Thanks!
Re: timeout of recv
Author: Eduardo Jauch
Date: Sun, 01 Jul 2007 09:22
Date: Sun, 01 Jul 2007 09:22
31 lines
2101 bytes
2101 bytes
Bob Gonder escreveu: > Eduardo Jauch wrote: > > > So, are you using the Windows API <winsock2.h> ? Yep! :) > > setsockopt() with SO_RCVTIMEO > > If your program calls recv and expects the data to be there at the end of the call, then > it is "blocked" at that point. > If your program calls WSARecv with the Overlapped options set, and continues on doing > other things, hoping someday the data will arrive and be handled by the OverlapedRoutine, > then it is "non-blocking". > Hum... So, my program is "Blocked"... The big problem seens to be when the "internet connection" fail (like a fault by the telecom provider) or when the site go off (when it's on maintenance). When this event's occour, the program "freeze"... But I think that this can be a problem of my code... I'm doing a few modifications and when it's ok, I'll do some tests and tell if this continue happening... I'll see the function. It works with block programs? Thanks!
Re: timeout of recv
Author: Eduardo Jauch
Date: Sun, 01 Jul 2007 09:23
Date: Sun, 01 Jul 2007 09:23
17 lines
1373 bytes
1373 bytes
Colin B Maharaj escreveu: > > What you want will probably look something like this...... > > struct timeval timeo; > timeo.tv_sec = 1; > timeo.tv_usec = 0; > int ret = setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeo, > sizeof(timeo)); > > This will work with block programs? I usually use recv and wait until it returns... Thanks!
Re: timeout of recv
Author: Colin B Maharaj
Date: Sun, 01 Jul 2007 13:31
Date: Sun, 01 Jul 2007 13:31
52 lines
2279 bytes
2279 bytes
Yes it should, however I do things differently now.
Firstly I do not use thus timeout anymore.
I wrote some code where recv waits forever,
then populates a string when data comes in
and if one of the chars is a linefeed
I trigger an event like this......
SetEvent(GotData);
where
HANDLE GotData = CreateEvent(NULL, false, false, NULL);
Then when I read a string, I do like this....
bool Timeout=false;
AnsiString __fastcall MySockets::ReadLn(int timeoutms)
{
AnsiString A = "";
DWORD ret=WaitForSingleObject(GotData, timeoutms);
if (ret==WAIT_TIMEOUT) { Timeout=true; return A; }
if (ret==WAIT_OBJECT_0)
{
<PSEUDOCODE> A = ExtractData() </PSEUDOCODE>
return A;
}
return A; // maybe some other error....
}
Eduardo Jauch wrote:
> Colin B Maharaj escreveu:
>>
>> What you want will probably look something like this......
>>
>> struct timeval timeo;
>> timeo.tv_sec = 1;
>> timeo.tv_usec = 0;
>> int ret = setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeo,
>> sizeof(timeo));
>>
>>
>
> This will work with block programs?
>
> I usually use recv and wait until it returns...
>
> Thanks!
Re: timeout of recv
Author: Bob Gonder
Date: Sun, 01 Jul 2007 15:10
Date: Sun, 01 Jul 2007 15:10
9 lines
1374 bytes
1374 bytes
Eduardo Jauch wrote: >Bob Gonder escreveu: >> setsockopt() with SO_RCVTIMEO > >I'll see the function. It works with block programs? It works with sockets. Doesn't care if it is blocking socket or not.
Re: timeout of recv
Author: Eduardo Jauch
Date: Sun, 01 Jul 2007 16:39
Date: Sun, 01 Jul 2007 16:39
16 lines
1495 bytes
1495 bytes
Bob Gonder escreveu: > Eduardo Jauch wrote: > >> Bob Gonder escreveu: >>> setsockopt() with SO_RCVTIMEO >> I'll see the function. It works with block programs? > > It works with sockets. > Doesn't care if it is blocking socket or not. > > hum... Thanks! :) I'll try to use it! [:)]
Re: timeout of recv
Author: Eduardo Jauch
Date: Sun, 01 Jul 2007 16:48
Date: Sun, 01 Jul 2007 16:48
48 lines
2477 bytes
2477 bytes
Colin B Maharaj escreveu:
>
> Yes it should, however I do things differently now.
>
> Firstly I do not use thus timeout anymore.
>
> I wrote some code where recv waits forever,
> then populates a string when data comes in
> and if one of the chars is a linefeed
> I trigger an event like this......
>
> SetEvent(GotData);
>
> where
>
> HANDLE GotData = CreateEvent(NULL, false, false, NULL);
>
> Then when I read a string, I do like this....
>
> bool Timeout=false;
> AnsiString __fastcall MySockets::ReadLn(int timeoutms)
> {
> AnsiString A = "";
> DWORD ret=WaitForSingleObject(GotData, timeoutms);
> if (ret==WAIT_TIMEOUT) { Timeout=true; return A; }
> if (ret==WAIT_OBJECT_0)
> {
> <PSEUDOCODE> A = ExtractData() </PSEUDOCODE>
> return A;
> }
> return A; // maybe some other error....
> }
>
hum...
I don't now if this aproach work on my application...
I download many html pages in a specific order, one after one...
They are different html, that depends on the results of the last.
Of course that will work... But I think that use timeout to determine if
I need to restart is more simple... I'll try the firs option...
But I'll think in a way to use this... The problem is that I need
"extreme" velocity, and I don't know if work with events is a good idea
in this case...
Anyway, much thanks! =D
Re: timeout of recv
Author: Remy Lebeau (TeamB)
Date: Mon, 02 Jul 2007 17:00
Date: Mon, 02 Jul 2007 17:00
14 lines
1180 bytes
1180 bytes
"Eduardo Jauch" <eduardo.jauch@gmail.com> wrote in message news:46869fb5$1@newsgroups.borland.com... > I use non-block sockets... So, looks I can't use select... right? Yes, you can. > Anyway, Select seens to be a very "slow" method, isn't it? No, it is not. Gambit
Re: timeout of recv
Author: Remy Lebeau (TeamB)
Date: Mon, 02 Jul 2007 17:01
Date: Mon, 02 Jul 2007 17:01
13 lines
1399 bytes
1399 bytes
"Eduardo Jauch" <eduardo.jauch@gmail.com> wrote in message news:4686a522$1@newsgroups.borland.com... > I don't know if my application is "non-block" (because I allways > am confused about this... rsrsrs) All sockets are blocking by default. You have to explicitally call the ioctlsocket() function with the FIONBIO flag set to 1 in order to turn on non-blocking mode. Gambit
Re: timeout of recv
Author: Remy Lebeau (TeamB)
Date: Mon, 02 Jul 2007 17:02
Date: Mon, 02 Jul 2007 17:02
14 lines
1505 bytes
1505 bytes
"Eduardo Jauch" <eduardo.jauch@gmail.com> wrote in message news:46877265$1@newsgroups.borland.com... > The big problem seens to be when the "internet connection" fail > (like a fault by the telecom provider) or when the site go off > (when it's on maintenance). When this event's occour, the program "freeze"... That is why you should be using timeouts. Obviously, you are not doing that yet. Gambit
Re: timeout of recv
Author: Remy Lebeau (TeamB)
Date: Mon, 02 Jul 2007 17:05
Date: Mon, 02 Jul 2007 17:05
14 lines
1337 bytes
1337 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message news:468715f2@newsgroups.borland.com... > What you want will probably look something like this...... Make sure that you initialize WinSock to use version 2.0. Older versions of WinSock did not support SO_RCVTIMEO and SO_SNDTIMEO Personally, I never use SO_RCVTIMEO and SO_SNDTIMEO in my code. I always use select() and it works fine. Gambit
Re: timeout of recv
Author: Eduardo Jauch
Date: Mon, 02 Jul 2007 23:17
Date: Mon, 02 Jul 2007 23:17
21 lines
1506 bytes
1506 bytes
Remy Lebeau (TeamB) escreveu: > > Make sure that you initialize WinSock to use version 2.0. Older > versions of WinSock did not support SO_RCVTIMEO and SO_SNDTIMEO > > Personally, I never use SO_RCVTIMEO and SO_SNDTIMEO in my code. I > always use select() and it works fine. > > > Gambit > > Hum... I was reading about using select... First I'll do a test with SO_RCVTIMEO. And then I'll try to use select. Thanks Remy :)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads