Skip to content

Commit

Permalink
Fix to working buffer #8 .
Browse files Browse the repository at this point in the history
  • Loading branch information
dhananjaysathe committed May 16, 2013
1 parent 577f4e2 commit da1d552
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
18 changes: 10 additions & 8 deletions rce-comm/rce/comm/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@
#
#
from zope.interface import implements
from twisted.internet.interfaces import IPushProducer
from twisted.internet.interfaces import IPullProducer

from autobahn.websocket import WebSocketProtocol
from collections import defaultdict, deque


class BufferManager(object):
implements(IPushProducer)
implements(IPullProducer)

def __init__(self, consumer, protocol):
self.consumer = consumer
self.protocol = protocol
self._paused = False
self._paused = True
self._new = True
self._binary_buff = deque(maxlen=10)

def push_data(self, data):
Expand All @@ -54,7 +55,10 @@ def push_data(self, data):
self._binary_buff.append(data)

def resumeProducing(self):
self._paused = False
if not self._new:
self._paused = False
else:
self._new = False
while not self._paused:
try:
uriBinary, msgURI = self._binary_buff.popleft()
Expand All @@ -63,13 +67,11 @@ def resumeProducing(self):
msg = data[0] + data[1].getvalue()
WebSocketProtocol.sendMessage(self.protocol, msg, binary=True)
except IndexError:
self._paused = True
pass

def pauseProducing(self):
self._paused = True

def stopProducing(self):
pass
self._paused = True

# TODO Implement Buffer Queues
class BufferQueue(object):
Expand Down
2 changes: 1 addition & 1 deletion rce-comm/rce/comm/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(self, conn):
def connectionMade(self):
WebSocketClientProtocol.connectionMade(self)
self._buffermanager = BufferManager(self.transport, self)
self.transport.registerProducer(self._buffermanager, True)
self.transport.registerProducer(self._buffermanager, False)

def onOpen(self):
""" This method is called by twisted as soon as the WebSocket
Expand Down
2 changes: 1 addition & 1 deletion rce-comm/rce/comm/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def __init__(self, realm):
def connectionMade(self):
WebSocketServerProtocol.connectionMade(self)
self._buffermanager = BufferManager(self.transport, self)
self.transport.registerProducer(self._buffermanager, True)
self.transport.registerProducer(self._buffermanager, False)

def onConnect(self, req):
""" Method is called by the Autobahn engine when a request to establish
Expand Down

0 comments on commit da1d552

Please sign in to comment.