🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #56230

How recv() determines the receiving is finished?

#56230
From: Joshua
Date: Sun, 27 Jan 2002 12:29
40 lines
2322 bytes
I read these codes from a book. I am not sure whether it can work:

char received_buffer[128];
int received_len;

do
{
    received_len=recv(socket,received_buffer,sizeof(received_buffer),0);
    if (SOCKET_ERROR==received_len)    //socket error or session is broken
        break;
    received_buffer[received_len]=0;
    printf(received_buffer);
}
while (0!=received_len);

I think if input stream has any data,recv() will get some of them and return
the size into received_len.But if the input stream is empty,recv() will
block there untill new inputing data is found. So,the do/while maybe never
has a chance to exit,unless some socket error issues.

And now,I am still not sure how to determine to end the receiving when I use
recv() to receive data from input stream. Is it the only way to get anything
from inputing stream and scan the whole inputing data for a specific string
which is given by the server? If the inputing data is large,I have to
prepare a large buffer for containing the whole data, and a very complicated
arithmetic to search the ending-string. I think there must be some
ready-made sample codes for that. Anyone would give me some of them or idea
for that?Thanks.











Technical Details
Message-ID: <a30rss$f0j$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!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!news-out.spamkiller.net!propagator-maxim!feed.newsfeeds.com!news-in.spamkiller.net!news.cn99.com!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <a30rss$f0j$1@mail.cn99.com>
Subject: How recv() determines the receiving is finished?
Date: Sun, 27 Jan 2002 20:29:49 +0800
From: "Joshua" <JoshuaIIII@hotmail.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!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!news-out.spamkiller.net!propagator-maxim!feed.newsfeeds.com!news-in.spamkiller.net!news.cn99.com!not-for-mail
Newsgroups: news.software.nntp
Organization: Bentium Ltd. (CN99)
Lines: 39
NNTP-Posting-Host: 61.156.77.46
X-Trace: mail.cn99.com 1012134620 15379 61.156.77.46 (27 Jan 2002 12:30:20 GMT)
X-Complaints-To: usenet@news.cn99.com
NNTP-Posting-Date: Sun, 27 Jan 2002 12:30:20 +0000 (UTC)
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200