🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #56239

Re: How recv() determines the receiving is finished?

#56239
From: Andrew Gierth
Date: Sun, 27 Jan 2002 22:05
31 lines
2540 bytes
>>>>> "Joshua" == Joshua  <JoshuaIIII@hotmail.com> writes:

 Joshua> Thank you,Russ.

 Joshua> In fact, I knew what happens when the remote side closes the
 Joshua> connection. I only don't know when the input stream is
 Joshua> ending.  The News client and Server may run require-respond
 Joshua> many times in every single socket session.The client send
 Joshua> require command such as "mode reader",and waits the server's
 Joshua> respond. Here,client uses recv() to get the responding
 Joshua> data. The session will keep open, so client can not determine
 Joshua> the ending of the responding data by estimating "return
 Joshua> 0".Before the session is closed by any side,the recv() will
 Joshua> generally not return 0.

For NNTP, the client knows whether it's expecting a single-line or a
multi-line response. It reads the first line (status line) and, if it's
a success response and a multi-line response is expected, then it reads
following lines until it gets a line consisting only of '.'+CRLF. This
is all explained in the RFC.

The example you gave is just a simple "read until connection closed"
loop (with, I might add, a security bug of the "format string" type),
and clearly has nothing to do with NNTP. I suggest you throw away
whatever book you got it from, because an author who writes
    printf(received_buffer);
is almost certain to have made other equally serious errors.

-- 
Andrew.
Technical Details
Message-ID: <87665ntppq.fsf@erlenstar.demon.co.uk>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!news.litech.org!news-feed.riddles.org.uk!news-spur.riddles.org.uk!newsmonster
References: <a30rss$f0j$1@mail.cn99.com> <yly9iju1i5.fsf@windlord.stanford.edu> <a31khk$895$1@mail.cn99.com>

Show Full Headers
Complete Article Headers
Message-ID: <87665ntppq.fsf@erlenstar.demon.co.uk>
Subject: Re: How recv() determines the receiving is finished?
Date: Sun, 27 Jan 2002 22:05:05 +0000
From: Andrew Gierth <andrew@erlenstar.demon.co.uk>
References: <a30rss$f0j$1@mail.cn99.com> <yly9iju1i5.fsf@windlord.stanford.edu> <a31khk$895$1@mail.cn99.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.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!news.litech.org!news-feed.riddles.org.uk!news-spur.riddles.org.uk!newsmonster
Newsgroups: news.software.nntp
Organization: disorganised
Lines: 30
X-Mayan-Date: Long count = 12.19.8.16.17; tzolkin = 12 Caban; haab = 15 Muan
X-Pgp-0x0E9FFBE9: 87 25 7F 14 41 24 B3 51 E0 19 8B DE 49 74 0C 29
X-Attribution: AG
X-P-Persistent-Headers: are a bad idea.
X-Newsreader: Gnus v5.5/Emacs 20.2
X-Complaints-To: abuse@news-spur.riddles.org.uk
X-Post-Filter: postfilter v0.6 alpha