Article View: borland.public.cppbuilder.internet.socket
Article #939Re: timeout of recv
From: 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!
Technical Details
Message-ID:
<4687acb2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<46869b18$1@newsgroups.borland.com> <468715f2@newsgroups.borland.com> <46877297@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,76bc0c5b0ec153e0 X-Google-Attributes: gid11508e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Sun, 01 Jul 2007 09:31:33 -0400 From: Colin B Maharaj <noreply@myhost.com> User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: timeout of recv References: <46869b18$1@newsgroups.borland.com> <468715f2@newsgroups.borland.com> <46877297@newsgroups.borland.com> In-Reply-To: <46877297@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 000752-7, 07/01/2007), Outbound message X-Antivirus-Status: Clean NNTP-Posting-Host: 190.58.14.110 Message-ID: <4687acb2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1183296690 190.58.14.110 (1 Jul 2007 06:31:30 -0700) Lines: 52 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail