Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rainer Weikusat Newsgroups: comp.os.linux.development.apps Subject: Re: Program hanging on recv() Date: Mon, 04 Feb 2013 19:43:19 +0000 Lines: 24 Message-ID: <87bobzj25k.fsf@sapphire.mobileactivedefense.com> References: <871ucxoz78.fsf@araminta.anjou.terraraq.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: individual.net hBIEucrcr+V356H9jEqyLwiWGiS7B09/SR3DPXXhuo6SFQIUrZYrMldbSEzh58flg= Cancel-Lock: sha1:AO3mmWSbH+YqIA6oiQrbk9YdMd0= sha1:bj4nCHcosDg4rsL2DRvFQdVXs80= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Xref: csiph.com comp.os.linux.development.apps:576 Ramon writes: > What I'm actually doing is just downloading an XML page to memory > using the HTTP > protocol. (e.g. http://weather.yahooapis.com/forecastrss?w=2502265) [...] > *Question*: Is it possible to know the size of the page to download > beforehand? If you're only interested in using the TCP connection for a single request-reply exchange, send a HTTP1.0 request without a Connection: header or with Connection: close as connection header and call shutdown(sockfd, SHUT_WR) on you socket after sending the complete request. The server is then required/ supposed to mark the end of the reply by closing the connection so you can just read until EOF. Otherwise, there are (AFAIK) two additional cases to deal with: - length of the content is provided in form a a Content-Length header - so-called 'chunked transfer coding' (reply is send in chunks each of which is preceded by a chunk length)