🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #69685

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

#69685
From: Curt Welch
Date: Tue, 10 Aug 2004 14:14
111 lines
7022 bytes
Florian Zschocke <edv@zschocke-berlin.de> wrote:
> curt@kcwc.com (Curt Welch) wrote:
> >
> Thank you Curt for that detailed answer
> >
> >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.
>
> So what i have now is, that I am sure that I use *blocking* cause
> non-bolcking is never set with fnctl().
> Do I understand this right, that even if I use non-blocking sockets, I
> will still not be able to have a asynchronous or parallel download of
> information on one socket?

A TCP connection (i.e. a single socket) is a single serial data stream
between your program, and the news server.  The NNTP protocol is a simple
command response protocol.  When you ask for an article, it sends that
article, and you can't do anything else with the connection until the
article is completely sent.  There's no way with NNTP to do two things at
the same time, like download two articles at the same time.

You can pipeline most (but not all) NNTP commands, but that gets very
tricky with blocking sockets because your program can deadlock.  That is,
you can send two ARTICLE commands before reading the response to the first
command.  If you write too much before reading however, the system will
flow control all the way back to you and block you as you are writing, and
your program will just lock up.

> >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
> >
> Like you mentioned before, that was a mistake and did not change
> anything in the behavior of my program. My mistake was that I left some
> characters on the socket.

Yeah, it's easy to make that mistake and then get very confused about what
your program is doing when those extra characters seem to just "show up" at
the wrong time later.  Network programing can be very confusing.

> I don't use select anymore. To speed up
> things I have detached the time consuming download from the socket as
> thread. In my GUI if you download a message with a binary and step to
> the next message before the binary is there, the program will make up a
> new socket. In praxis that dose not happen often. But perhaps I have to
> set a limit of sockets to protect the server.

Yes, you have to set limits.  Many servers will limit how many connections
you can use (some have limits as small as 1 or 2), so not only do you need
to limit it to something reasonable to protect the server, you also have to
deal with the fact that some servers won't let you make multiple connetions
or will only let you make a small number of connections.

> Is that a bad style, to have more than one socket ?

No, it's fine.  Many programs use multiple sockets to the same server.  You
just have to be careful about how it works, and you should try to do
whatever you can to minimize the number of sockets.

Larger servers also use complex distributed systems that can, at times,
either by accident, or design, get out of sync with one another.  So
another thing to watch out for is the fact that two connections to the same
server, may in fact be connections to different servers which are very
similar, but not identical.  The time new articles show up for example
might be slightly different, so the high-water mark for a group may be
different.  One connection may say the high water mark for a group is 100,
and the other server is still at 98.  If you trust the high water mark
returned from a GROUP command on one connction, and then try to fetch
article 100 from a second connection, you risk (small risk), that the
article won't be there because the two connections are slightly out of
sync.

The amount of stuff like this that you would expect to work, but doesn't
always work, is large.  So, the tricker you get with multiple connections,
the more likely you will run into these unexpected conditions.  So the more
you can do with a single connection, the better.

> Could I do the same
> thing I do now with multiple blocking sockets with one non-blocking
> socket ?

There is no way to abort a command with NNTP other than closing the socket.
So if you want to allow the user to abort a download (like transfering a
large binary article that the user thought was just a small text message),
instead of forcing them to wait, you have to close the socket and open a
new one.

If you want the first one to finsih in the background, while a new
connection downloads the next article, that's fine, and you have to use two
connections to do that.

The one thing I hate about many newsreaders is that they try to isolate the
user from these complexities of how NNTP works.  They think they can design
a GUI with no regard to the fact that it's a front-end for an NNTP server.
They think it's ok for all the NNTP "stuff" to happen magically in the
background as if it's not important to the user.  But then something
happens, like connections hang on authentication for 30 seconds, and all
the user sees is that the GUI stops responding for an unknown reason at an
unknown time.

A good NNTP newsreader will not try to hide the nature, and problems, of
NNTP from the user.

-- 
Curt Welch                                            http://CurtWelch.Com/
curt@kcwc.com                                        http://NewsReader.Com/
Technical Details
Message-ID: <20040810101435.585$px@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!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!38.144.126.100.MISMATCH!feed5.newsreader.com!newsreader.com!newsh.newsreader.com!bravo.newsreader.com!not-for-mail
References: <20040808224221.335$Rb@newsreader.com> <D8293589-E9D2-11D8-BF7C-000393453BC2-2554-000001A80A065E1F%edv@zschocke-berlin.de>

Show Full Headers
Complete Article Headers
Message-ID: <20040810101435.585$px@newsreader.com>
Subject: Re: POST -> no response, but message is posted.
Date: Tue, 10 Aug 2004 14:14:35 +0000
From: curt@kcwc.com (Curt Welch)
References: <20040808224221.335$Rb@newsreader.com> <D8293589-E9D2-11D8-BF7C-000393453BC2-2554-000001A80A065E1F%edv@zschocke-berlin.de>
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!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!38.144.126.100.MISMATCH!feed5.newsreader.com!newsreader.com!newsh.newsreader.com!bravo.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com @uz1YMz-wpFMdk55D22TIFBXcJw_FVNm4R.BUZXZ8Ksnk0+@.Q
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: 111