🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4511

Re: stThreadBlocking Vs stNonBlocking confusion

#4511
From: Remy Lebeau (TeamB)
Date: Tue, 01 Feb 2005 19:05
42 lines
2823 bytes
"Stefano Bonifazi" <stefboombastic@email.it> wrote in message
news:41ffb890@newsgroups.borland.com...

> - with non-blocking the server socket can receive simultaneously
> from many clients

The server can do that regardless of blocking or non-blocking.

> when one client dedicated buffer is full or when a certain time has
> elapsed the OnClientRead is triggered, but as we have only one
> thread, only one instance of this handler can run in the same time

Yes.  However, the data in the socket is already buffered in memory by the
time the OnClientRead event is triggered.  You can query how many data is
actually available via ReceiveLength() and then perform a single read to
copy the entire buffer into your application's own buffers in a single
operation very quickly.  If your processing of the data is simple, the event
handler will exit relatively quickly, and other sockets can then be serviced
just as quickly.  If, on the other hand, your processing of the data can be
time-consuming, then you should copy the data to a different thread so that
the event handler can exit as soon as possible.

> - with thread-Blocking multiple instances of the same OnClientRead
> event handler can run at the same time, because of multiple threads,
> but inside them we have to BLOCK the execution WHILE receiving the data

A thread that is reading from a blocking socket doesn't need to do anything
else while it is reading, so blocking the thread is fine.

> I should be able to have a non-blocking Client and a ThreadBlocking server

Correct.

> The problem is that with the simple test I'm posting in this thread right
> now the Threadblocking server does nothing with my simple non-blocking
> client...

You are probably not using it correctly.


Gambit
Technical Details
Message-ID: <41ffd228$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41fe906e@newsgroups.borland.com> <41fe99bf$1@newsgroups.borland.com> <41ff64b9@newsgroups.borland.com> <41ff691e$1@newsgroups.borland.com> <41ffb890@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,4f7607071b9a8537
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: <41fe906e@newsgroups.borland.com> <41fe99bf$1@newsgroups.borland.com> <41ff64b9@newsgroups.borland.com> <41ff691e$1@newsgroups.borland.com> <41ffb890@newsgroups.borland.com>
Subject: Re: stThreadBlocking Vs stNonBlocking confusion
Date: Tue, 1 Feb 2005 11:05:01 -0800
Lines: 44
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: <41ffd228$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1107284520 68.69.17.41 (1 Feb 2005 11:02:00 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail