Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96930

Re: Lightwight socket IO wrapper

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'binary': 0.05; '21,': 0.07; 'bytes.': 0.07; 'socket': 0.07; 'terminated': 0.07; 'cc:addr :python-list': 0.09; 'encoding.': 0.09; 'read()': 0.09; 'underlying': 0.09; 'buffering': 0.16; 'exclusion': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'readable': 0.16; 'socket.': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'sep': 0.22; 'trying': 0.22; 'needed.': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'chris': 0.26; 'point.': 0.27; 'followed': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'socket,': 0.29; 'there.': 0.30; 'allows': 0.30; 'message.': 0.33; 'facility': 0.33; 'safely': 0.33; 'stream': 0.33; 'handle': 0.34; 'that,': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'next': 0.35; 'text': 0.35; 'possible,': 0.35; 'protocol': 0.35; 'something': 0.35; 'problem.': 0.35; 'but': 0.36; 'too': 0.36; 'lines': 0.36; 'basic': 0.36; 'beginning': 0.36; 'data.': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'anything': 0.38; 'mean': 0.38; 'means': 0.39; 'data': 0.39; 'sure': 0.39; "didn't": 0.39; 'along': 0.39; 'where': 0.40; 'ever': 0.60; 'your': 0.60; 'making': 0.62; 'potentially': 0.67; 'therefore': 0.67; 'obvious': 0.76; '"too': 0.84; 'chrisa': 0.84; 'premature': 0.84; 'wrapper,': 0.84; 'absolutely': 0.88; 'to:none': 0.91; 'imagine': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=0VHGvz1D8iVM3q+ewVu/3R+L1YPIkBGB6Av5tXugNW8=; b=M9TYAF5qVlI7phs4Vgn4Sq7gTjApA8nDhoV4S1GYyMjD0LKhBiJcGlXOZ7TEoQWMXv ZvHmO2pJOj4pOl7zeomD/tV6L+guf+WJAd9MKv7hlco5b75BbHD5In3Xu534/cT5KiGj C8grNaEZSw6XOHrD41jV5ITM+mc4njwLQb2ShVA/LGHrloAKrkuXNLwsdo8+T991IdHi 5kHlc6F2AoBYh01vwxzXiJkwAiKkodNQAPmgwZ0fGRQLncugH2528M6IQl7wOFkPiqeM fNF2Wo79iDg67nuNZY4gMcX4qU6izZjis30Q3pWfhW7lr7Ltr89zc4+axyvSYm621yyW TOLQ==
MIME-Version 1.0
X-Received by 10.107.132.144 with SMTP id o16mr24668480ioi.31.1442825408936; Mon, 21 Sep 2015 01:50:08 -0700 (PDT)
In-Reply-To <871tdsp3ox.fsf@elektro.pacujo.net>
References <CAPTjJmpuYp5uEDnRJqC9qKj-YkNRx1jW48WsRyRn+U0rzGiTYw@mail.gmail.com> <20150921062713.GA77399@cskk.homeip.net> <mailman.23.1442822248.28679.python-list@python.org> <876134p5hw.fsf@elektro.pacujo.net> <mailman.24.1442822846.28679.python-list@python.org> <871tdsp3ox.fsf@elektro.pacujo.net>
Date Mon, 21 Sep 2015 18:50:08 +1000
Subject Re: Lightwight socket IO wrapper
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.26.1442825411.28679.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442825411 news.xs4all.nl 23721 [2001:888:2000:d::a6]:50576
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 5662
X-Received-Body-CRC 1925513667
Xref csiph.com comp.lang.python:96930

Show key headers only | View raw


On Mon, Sep 21, 2015 at 6:38 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> On Mon, Sep 21, 2015 at 5:59 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
>>> 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.
>
> Only one reader can read a socket safely at any given time so mutual
> exclusion is needed.
>
> If you read "too much," the excess can be put in the application's read
> buffer where it is available for whoever wants to process the next
> message.

Oops, premature send - sorry! Trying again.

Which works only if you have a single concept of "application's read
buffer". That means that you have only one place that can ever read
data. Imagine a protocol that mainly consists of lines of text
terminated by CRLF, but allows binary data to be transmitted by
sending "DATA N\r\n" followed by N arbitrary bytes. The simplest and
most obvious way to handle the base protocol is to buffer your reads
as much as possible, but that means potentially reading the beginning
of the data stream along with its header. You therefore cannot use the
basic read() method to read that data - you have to use something from
your line-based wrapper, even though you are decidedly NOT using a
line-based protocol at that point.

That's what I mean by guaranteeing that your buffering function is the
only way data gets read from the socket. Either that, or you need an
underlying facility for un-reading a bunch of data - de-buffering and
making it readable again.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 17:57 +1000
  Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 10:59 +0300
    Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 18:07 +1000
      Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 11:38 +0300
        Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 18:45 +1000
          Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 11:48 +0300
            Re: Lightwight socket IO wrapper Marko Rauhamaa <marko@pacujo.net> - 2015-09-21 11:49 +0300
        Re: Lightwight socket IO wrapper Chris Angelico <rosuav@gmail.com> - 2015-09-21 18:50 +1000
          Re: Lightwight socket IO wrapper Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-09-22 07:59 +0000

csiph-web