Article View: borland.public.cppbuilder.internet.socket
Article #2474Re: TServerSocket SendText Exception
From: Remy Lebeau (TeamB)
Date: Mon, 17 Apr 2006 21:18
Date: Mon, 17 Apr 2006 21:18
74 lines
2858 bytes
2858 bytes
"Eric Patterson" <eric.patterson@bepco.com> wrote in message
news:4443dd4e@newsgroups.borland.com...
> After thinking a minute, what about this:
<snip>
> That way it will continue to send until no more length is detected.
No, because you are re-sending the entire string contents every time, even
for portions of it that are successfully sent in previous loop iterations.
Youare not adjusting the sending to send only the characters that are
actually pending.
A more accurate approach is as follows:
TCustomWinSocket *Socket =
Server->ServerSocket1->Socket->Connections[ii];
AnsiString temp = AMsg + "\n";
int len;
while( temp.Length() > 0 )
{
len = Socket->SendText(temp);
if( len > 0 )
{
temp = temp.SubString(len+1, MaxInt);
continue;
}
if( (len == -1) && (WSAGetLastError() == WSAEWOULDBLOCK) )
{
Sleep(10);
continue;
}
break;
}
Alternatively:
TCustomWinSocket *Socket =
Server->ServerSocket1->Socket->Connections[ii];
AnsiString temp = AMsg + "\n";
int sent, len = temp.Length();
char *ptr = temp.c_str();
while( len > 0 )
{
sent = Socket->SendBuf(ptr, len);
if( sent > 0 )
{
ptr += sent;
len -= sent;
continue;
}
if( (sent == -1) && (WSAGetLastError() == WSAEWOULDBLOCK) )
{
Sleep(10);
continue;
}
break;
}
> I figure if a negative is returned then the OnError event should catch it.
SendText/Buf() will still return the negative value regardless of whether
the OnError event is used. All the OnError event can do is choose whether
to stop the error from throwing an exception or not.
Gambit
Technical Details
Message-ID:
<44440644$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.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:
<44439c71$1@newsgroups.borland.com> <4443ca2a$1@newsgroups.borland.com> <4443dd4e@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,fea0b13af0f4efa8 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <44439c71$1@newsgroups.borland.com> <4443ca2a$1@newsgroups.borland.com> <4443dd4e@newsgroups.borland.com> Subject: Re: TServerSocket SendText Exception Date: Mon, 17 Apr 2006 14:18:52 -0700 Lines: 76 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <44440644$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1145308740 68.69.17.41 (17 Apr 2006 14:19:00 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.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