Article View: borland.public.cppbuilder.internet.socket
Article #2984Re: Modify the timeout for open() method
From: enzo
Date: Mon, 05 Dec 2005 10:03
Date: Mon, 05 Dec 2005 10:03
94 lines
3535 bytes
3535 bytes
thanks, it works well and seems a very good solution.
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> ha scritto nel messaggio
news:43909cb3$1@newsgroups.borland.com...
>
> "enzo" <enzo.arlati@aesys.it> wrote in message
> news:438ffe59@newsgroups.borland.com...
>
> > I create and open the socket in blocking mode from inside a thread.
>
> You need another thread in order to abort a blocking Open().
>
> > I need to make a fast check before call the open
>
> There is no way to do that. The only way to know if a socket is listening
> on another machine is to connect to it.
>
> > or mybe shorten the timeout if I call open on a pc not ready to listen.
>
> Like I told you before, there is no connect timeout available. You have
to
> implement your own.
>
> > what do you mean for a separate thread to disconnect the socket
>
> I mean exactly what I say. The only way to abort a blocking Open() is to
> disconnect the socket from the context of a different thread than the one
> that is calling Open(). For example (untested):
>
> class TConnectThread : public TThread
> {
> private:
> TClientSocket *FSocket;
> protected:
> virtual void __fastcall Execute();
> public:
> __fastcall TConnectThread(TClientSocket *ASocket);
> };
>
> __fastcall TConnectThread::TConnectThread(TClientSocket *ASocket)
> : TThread(true)
> {
> FSocket = ASocket;
> Resume();
> }
>
> void __fastcall TConnectThread::Execute()
> {
> try
> {
> FSocket->Open();
> }
> catch(const Exception &) {}
> }
>
>
> __fastcall TSocketThread::TSocketThread()
> : TThread(true)
> {
> clientSck = new TClientSocket( NULL );
> clientSck->ClientType = ctBlocking;
> Resume();
> }
>
> __fastcall TSocketThread::~TSocketThread()
> {
> delete clientSck;
> }
>
> void __fastcall TSocketThread::Execute()
> {
> //...
> clientSck->Address = ipTarge;
> clientSck->Port = portTarget;
>
> TConnectThread *CT = new TConnectThread(clientSck);
> if( WaitForSingleObject((HANDLE)CT->Handle, 1000) !=
WAIT_OBJECT_0 )
> {
> clientSck->Close();
> CT->WaitFor();
> }
> delete CT;
>
> if( !clientSck->Active ) return;
>
> // ...
> }
>
>
> Gambit
>
>
Technical Details
Message-ID:
<43941048@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.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:
<438ed040@newsgroups.borland.com> <438f4204$1@newsgroups.borland.com> <438ffe59@newsgroups.borland.com> <43909cb3$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,234cf6f94ba290e1 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "enzo" <enzo.arlati@aesys.it> From: "enzo" <enzo.arlati@aesys.it> Newsgroups: borland.public.cppbuilder.internet.socket References: <438ed040@newsgroups.borland.com> <438f4204$1@newsgroups.borland.com> <438ffe59@newsgroups.borland.com> <43909cb3$1@newsgroups.borland.com> Subject: Re: Modify the timeout for open() method Date: Mon, 5 Dec 2005 11:03:36 +0100 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 81.208.124.114 Message-ID: <43941048@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1133776968 81.208.124.114 (5 Dec 2005 02:02:48 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.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