Skip to content

Commit

Permalink
Add a NULL terminator to the data we send out to clients
Browse files Browse the repository at this point in the history
* When sending data from Python to a C client via a ZeroMQ socket
  we need to make sure that the data on the client side can be
  properly understood by the client
  • Loading branch information
dnaeon committed Sep 11, 2014
1 parent 16f2e8f commit 4220677
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/vpoller/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run(self, msg):
# Do we have a reply?
if socks.get(self.zclient) == zmq.POLLIN:
logging.debug('Received response on client socket')
result = self.zclient.recv_json()
result = self.zclient.recv()
logging.debug('Received message was: %s', result)
break
else:
Expand Down
7 changes: 6 additions & 1 deletion src/vpoller/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""

import json
import logging
import importlib
import multiprocessing
Expand Down Expand Up @@ -458,7 +459,11 @@ def wait_for_tasks(self):
self.worker_socket.send(_id, zmq.SNDMORE)
self.worker_socket.send(_empty, zmq.SNDMORE)
try:
self.worker_socket.send_json(result)
# Add a NULL terminator at the end of the result
# so that C clients can properly get the data we send
data = json.dumps(result, ensure_ascii=False)
data += '\0'
self.worker_socket.send(data)
except TypeError as e:
logging.warning('Cannot serialize result: %s', e)
r = {'success': 1, 'msg': 'Cannot serialize result: %s' % e}
Expand Down

0 comments on commit 4220677

Please sign in to comment.