🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #69675

Re: POST -> no response, but message is posted.

#69675
From: Curt Welch
Date: Mon, 09 Aug 2004 02:42
107 lines
6692 bytes
Florian Zschocke <edv@zschocke-berlin.de> wrote:
> curt@kcwc.com (Curt Welch) wrote:
> >
> Thank you Curt
> >
> >If you are using ASYNC IO by setting a NONBLOCK option, then you are
> >into a more complex programming problem.  It's unlcear from your
> >response above if you have done that, or if you have not, and are just
> >confused by what your code is doing.  If you are using ASYNC IO, then
> >you need to use a select() with (or without) a timeout value to wait for
> >data to show up (or to wait forever).  But you still need to loop doing
> >the select, and reading data, until the full command has shown up,
> >because like above, you can't assume the full response will show up in a
> >single read.
>
> I think, that is my main problem, that I still don't understand what is
> the difference between blocking an nonblocking.

Blocking is the normal way for both computers and programing langauges to
work.  When you write a program as a list of instructions, the computer
performs the instructions in sequence.  It will not perform the second
instruction until the first has finished.  It will not perform the third
instruction until the second has finished.

So, when you write something like:

   A <- 1
   A <- 2
   B <- A

You know that the value of B will be 2 after these instructions finish,
because the third instruction which copies the value of A, to B, will not
happen until after the second instruction, where the value of 2 is assigned
to A.  This is norm "blocking" behavior so it's nothing unusal for any
programing language.  But it's also what you expect the computer hardware
to do, so it's odd trying to think of anything else.

However, if you do something like read data from a disk, it takes a lot of
time, and runs parallel to the processing of the computer.  The computer
sends a command to the disk controller telling it to read block N from the
disk and put the data it gets into memory at some location.  When the disk
controler is done reading the data, it signals the computer with an
interrupt.

If you want, you can write the computer disk driver code so that's it's
blocking.  By that, I mean that once it sends the command to the disk to
read the data, it hangs in a busy loop constantly checking the status to
see if the read is done.  If it does that, the computer of course can not
do anything else while it's waiting for the disk IO to finish.

So, all modern OSs will allow the computer to be working on many different
tasks at the same time.  Each processes can do a disk read, but will block
for that processes.  That means the OS sends the command to the disk to
start the IO, but then goes to work on any other processes which is not
blocked, waiting for some external task to finish.

So in a typical programing langauge, when you use code to read data from
the disk, just like all statements in the langauge, the program will not
continue with the next statement until the read is done.  It blocks, even
though the CPU can still be used to run other tasks.

Many programming langages however offer special nonblocking versions of
fuctions like disk IO, and network IO.  So, for disk IO, the program can
make a request to read a block from disk, but not block, and continue
processing - but the programer of course has to deal with the fact that the
data requested will show up at some time in the future.

For reading from a network, you can never "request" the network sends data
to you, you simply have to check to see if data has been sent, and respond
to it correctly.  A typical blocking read for network data will hang until
some network data shows up.  A non-blocking read will return data if it's
there, otherwise, it will return an indication that no data was available.

It sounds like the language/Class you are using implements non-blocking
reads.

Protocols like NNTP do not require the more complex non-blocking reads.
However, if you want a program which is dealing with multiple connections
at the same time, you need non-blocking reads so that the program can work
on a response from one connection, while waiting for the next response on
the second connection.

If your program is not trying to do anything else while it's waiting for
the response from the server, then you should use a blocking read, instead
of using a non-blocking read, and sleeping for 500 ms between checks for
data.  It's poor technique to force your program to delay for 500 ms if the
server you are using responds in 5 ms.

If the routines you are using do not support a blocking read, but you do
have the ability to do a select(), then you should do that.  Use select to
wait for the data, and then read the data once the select() says it's
there.  The select is a blocking call which will cause the program to puase
until the data shows up, but allow it to continue when it shows up, so
there will be no extra delays in your code.

And if you want, you can use the timeout feature of select to limit how
long the program will wait before it gives up on the server and reports an
error to the user.

But, on another note, if you are working in some GUI environmet, where the
GUI stops responding when you block, then select() is not what you want to
do.  You need something more complex.  But that answer to how that needs to
be done is a function of what environment you are trying to program for.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                          Webmaster for http://NewsReader.Com/
Technical Details
Message-ID: <20040808224221.335$Rb@newsreader.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.dca.giganews.com!internal1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!newsh.newsreader.com!ellis.newsreader.com!not-for-mail
References: <20040808125855.840$hk@newsreader.com> <41167396$0$28854$9b4e6d93@newsread4.arcor-online.net>

Show Full Headers
Complete Article Headers
Message-ID: <20040808224221.335$Rb@newsreader.com>
Subject: Re: POST -> no response, but message is posted.
Date: Mon, 09 Aug 2004 02:42:21 +0000
From: curt@kcwc.com (Curt Welch)
References: <20040808125855.840$hk@newsreader.com> <41167396$0$28854$9b4e6d93@newsread4.arcor-online.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.dca.giganews.com!internal1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!feed5.newsreader.com!newsreader.com!newsh.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com t5KV,vk4Ze+OROC1CAW6DJhGYkMXtJgWYgD.TXX1hwMMQJ
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,
 ?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
 %IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 107