-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes binary data sending #62
Open
Wrangl
wants to merge
7
commits into
zeekay:master
Choose a base branch
from
Wrangl:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
50cf425
Fixes binary data sending
Wrangl 63cb792
Add some very low level debugging
Wrangl a0b3472
Live Changes, still working on the recv queue
285fc17
Merge branch 'master' of https://github.com/Wrangl/flask-uwsgi-websocket
84b4d4c
Merge Live changes
130558b
Remove spurious print statement
ba13c69
One more attempt at better ws handling internally.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,24 +13,27 @@ | |
|
||
class GeventWebSocketClient(object): | ||
def __init__(self, environ, fd, send_event, send_queue, recv_event, | ||
recv_queue, timeout=5): | ||
recv_queue, is_binary, timeout=6000): | ||
self.environ = environ | ||
self.fd = fd | ||
self.send_event = send_event | ||
self.send_queue = send_queue | ||
self.recv_event = recv_event | ||
self.recv_queue = recv_queue | ||
self.timeout = timeout | ||
self.timeout = 6000 | ||
self.id = str(uuid.uuid1()) | ||
self.connected = True | ||
self.is_binary = is_binary | ||
|
||
def send(self, msg, binary=True): | ||
if binary: | ||
return self.send_binary(msg) | ||
#self.is_binary.clear() | ||
self.send_queue.put(msg) | ||
self.send_event.set() | ||
|
||
def send_binary(self, msg): | ||
self.is_binary.set() | ||
self.send_queue.put(msg) | ||
self.send_event.set() | ||
|
||
|
@@ -68,10 +71,11 @@ def __call__(self, environ, start_response): | |
|
||
recv_event = Event() | ||
recv_queue = Queue() | ||
is_binary = Event() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still not clear why a boolean will not work here. |
||
|
||
# create websocket client | ||
client = self.client(environ, uwsgi.connection_fd(), send_event, | ||
send_queue, recv_event, recv_queue, | ||
send_queue, recv_event, recv_queue, is_binary, | ||
self.websocket.timeout) | ||
|
||
# spawn handler | ||
|
@@ -81,6 +85,7 @@ def __call__(self, environ, start_response): | |
def listener(client): | ||
# wait max `client.timeout` seconds to allow ping to be sent | ||
select([client.fd], [], [], client.timeout) | ||
print('we received a message') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary logging. |
||
recv_event.set() | ||
listening = spawn(listener, client) | ||
|
||
|
@@ -98,7 +103,10 @@ def listener(client): | |
if send_event.is_set(): | ||
try: | ||
while True: | ||
uwsgi.websocket_send(send_queue.get_nowait()) | ||
if not is_binary.is_set() or not is_binary: | ||
uwsgi.websocket_send(send_queue.get_nowait()) | ||
else: | ||
uwsgi.websocket_send_binary(send_queue.get_nowait()) | ||
except Empty: | ||
send_event.clear() | ||
except IOError: | ||
|
@@ -119,7 +127,12 @@ def listener(client): | |
# should be able to ignore it anyway. | ||
while message: | ||
message = uwsgi.websocket_recv_nb() | ||
recv_queue.put(message) | ||
if message != b'': | ||
recv_queue.put_nowait(message) | ||
|
||
else: | ||
message = False | ||
listening.kill() | ||
listening = spawn(listener, client) | ||
except IOError: | ||
client.connected = False | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not hardcode the timeout here :)