From d863b8381584e5ff2785d7e573c4f703270627f3 Mon Sep 17 00:00:00 2001 From: Teddy Date: Thu, 29 Aug 2013 18:43:36 +0800 Subject: limit the size of pending queues --- server/piztor/mesg_sender.py | 1 + server/piztor/server.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/piztor/mesg_sender.py b/server/piztor/mesg_sender.py index 64349a3..96a3a9d 100644 --- a/server/piztor/mesg_sender.py +++ b/server/piztor/mesg_sender.py @@ -24,4 +24,5 @@ send_text_mesg(token, username, mesg) send_text_mesg(token, username, "a") update_location(token, username, 1.2345, 2.468) update_location(token, username, 1.2345, 2.468) +send_text_mesg(token, username, "the last") #logout(token, username) diff --git a/server/piztor/server.py b/server/piztor/server.py index 1814a39..ed4e0b9 100644 --- a/server/piztor/server.py +++ b/server/piztor/server.py @@ -52,6 +52,8 @@ _HEADER_SIZE = _SectionSize.LENGTH + \ _MAX_TEXT_MESG_SIZE = 1024 +_MAX_PENDING_PUSH = 100 + class _OptCode: user_auth = 0x00 location_update = 0x01 @@ -96,6 +98,9 @@ class PushTunnel(object): def add(self, pdata): logger.info("-- Push data enqued --") self.pending.append(pdata) + if len(self.pending) > _MAX_PENDING_PUSH: + logger.info("-- Push queue is full, discarded an obsolete push --") + self.pending.popleft() # discard old push def on_receive(self, data): front = self.pending.popleft() @@ -670,6 +675,6 @@ from twisted.internet import reactor f = PTPFactory() f.protocol = PTP -reactor.listenTCP(2222, f) +reactor.listenTCP(2223, f) logger.warning("The server is lanuched") reactor.run() -- cgit v1.2.3-70-g09d2