Path: csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '21,': 0.07; 'bytes.': 0.07; 'cc:addr:python-list': 0.09; 'compact': 0.09; 'encoding.': 0.09; 'length.': 0.09; 'encoding': 0.15; '>on': 0.16; 'buffering': 0.16; 'chunks.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'pulling': 0.16; 'simpson': 0.16; 'wrote:': 0.16; 'byte': 0.18; 'cheap': 0.18; 'integer': 0.18; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'sep': 0.22; 'cheers,': 0.22; 'header :In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'function': 0.28; 'there.': 0.30; "i'm": 0.30; 'certainly': 0.30; 'another': 0.32; 'generally': 0.32; 'values.': 0.33; 'question,': 0.35; 'problem.': 0.35; 'but': 0.36; 'too': 0.36; 'faster': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'anything': 0.38; 'mean': 0.38; 'sure': 0.39; "didn't": 0.39; 'enough': 0.39; 'some': 0.40; 'your': 0.60; 'cameron': 0.66; 'received:61': 0.72; '128,': 0.84; '>you': 0.84; 'absolutely': 0.88 X-Authentication-Info: Submitted using ID cskk@bigpond.com X-Authority-Analysis: v=2.0 cv=Vsyh8pKn c=1 sm=1 a=w7m0j7GrXEBIZM9S8iGOQQ==:17 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=ff-B7xzCdYMA:10 a=pGLkceISAAAA:8 a=KaybevnVAAAA:8 a=lP3RHLpR3IwpShtkuckA:9 a=CjuIK1q_8ugA:10 a=T64d5zCURXxNoTKh:21 a=T5O8b4gUcVDn-82J:21 a=w7m0j7GrXEBIZM9S8iGOQQ==:117 Date: Tue, 22 Sep 2015 07:42:51 +1000 From: Cameron Simpson To: Chris Angelico Cc: "python-list@python.org" Subject: Re: Lightwight socket IO wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) References: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1442871863 news.xs4all.nl 23767 [2001:888:2000:d::a6]:40937 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96967 On 21Sep2015 18:07, Chris Angelico wrote: >On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa wrote: >> Chris Angelico : >> >>> On Mon, Sep 21, 2015 at 4:27 PM, Cameron Simpson wrote: >>>> For sizes below 128, one byte of length. For sizes 128-16383, two bytes. And >>>> so on. Compact yet unbounded. >>> >>> [...] >>> >>> It's generally a lot faster to do a read(2) than a loop with any >>> number of read(1), and you get some kind of bound on your allocations. >>> Whether that's important to you or not is another question, but >>> certainly your chosen encoding is a good way of allowing arbitrary >>> integer values. >> >> You can read a full buffer even if you have a variable-length length >> encoding. > >Not sure what you mean there. Unless you can absolutely guarantee that >you didn't read too much, or can absolutely guarantee that your >buffering function will be the ONLY way anything reads from the >socket, buffering is a problem. I'm using buffered io streams, so that layer will be reading in chunks. Pulling things from that buffer with fp.read(1) is cheap enough for my use. Cheers, Cameron Simpson