summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2013-10-17 15:17:40 -0700
committerGuido van Rossum <guido@python.org>2013-10-17 15:17:40 -0700
commit111969f365503b17cb402966ffd24e579d21ac37 (patch)
treec33490c06266116bcbf19bfd0172e01682f318d3 /examples
parentba21aaf80c470165978251adb7c8b7d689f65d8b (diff)
downloadtrollius-111969f365503b17cb402966ffd24e579d21ac37.tar.gz
Add size argument to source example.
Diffstat (limited to 'examples')
-rw-r--r--examples/source.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/examples/source.py b/examples/source.py
index f5d0291..c484224 100644
--- a/examples/source.py
+++ b/examples/source.py
@@ -19,6 +19,9 @@ ARGS.add_argument(
ARGS.add_argument(
'--port', action='store', dest='port',
default=1111, type=int, help='Port number')
+ARGS.add_argument(
+ '--size', action='store', dest='size',
+ default=16*1024, type=int, help='Data size')
args = None
@@ -29,8 +32,6 @@ def dprint(*args):
class Client(Protocol):
- data = b'x'*16*1024
-
def connection_made(self, tr):
dprint('connecting to', tr.get_extra_info('peername'))
dprint('my socket is', tr.get_extra_info('sockname'))
@@ -42,15 +43,16 @@ class Client(Protocol):
self.tr.write(b'stop')
self.tr.close()
else:
- self.write_some_data()
+ data = b'x' * args.size
+ self.write_some_data(data)
- def write_some_data(self):
+ def write_some_data(self, data):
if self.lost:
dprint('lost already')
return
- dprint('writing', len(self.data), 'bytes')
- self.tr.write(self.data)
- self.loop.call_soon(self.write_some_data)
+ dprint('writing', len(data), 'bytes')
+ self.tr.write(data)
+ self.loop.call_soon(self.write_some_data, data)
def connection_lost(self, exc):
dprint('lost connection', repr(exc))