Commits

Anonymous committed 90d7b2e

just make everything 8 bytes for now

Comments (0)

Files changed (4)

client/tinymq_client.py

     def connect(self):
         return self.socket.connect((self.ip, self.port))
 
+    def _send_command(self, command):
+        return self._send("L", command)
+
+    def _send_get(self):
+        self._send_command(self.GET)
+        return struct.unpack("LL", self.socket.recv(16))
+
     def get(self):
-        self._send("I", self.GET)
-        msg_id, = self._recv(8, "L")
-        msg_len, = self._recv(4, "I")
+        msg_id, msg_len = self._send_get()
         recvd = 0
         buf = []
         while (recvd < msg_len):
         return (msg_id, msg_data)
 
     def ack(self, message_id):
-        self._send("I", self.ACK)
-        self._send("Q", message_id)
+        self.socket.send(struct.pack("LL", self.ACK, message_id))
 
     def put(self, message):
         msg_len = len(message)
-        self._send("I", self.PUT)
-        self._send("I", msg_len)
-        self._send("%ss" % msg_len, message)
-        msg_id, = self._recv(8, "Q")
+        self.socket.send(struct.pack("LL%ss" % msg_len,
+                                     self.PUT, msg_len, message))
+        msg_id, = self._recv(8, "L")
         return msg_id
 
 def test():

src/connection.cpp

     socket_(io_service),
     server_(server),
     client_(new tcp_client(&server->queue(), io_service)),
-    curmsg_() {}
+    curmsg_() {
+}
 
 connection::~connection() {
 
         std::size_t bytes_transferred) {
     if (!e) {
         a::const_buffer b = a::buffer(buffer_);
-        const std::size_t *msg_size = a::buffer_cast<const std::size_t*>(b);
+        const message_len_t *msg_size = a::buffer_cast<const message_len_t*>(b);
         incoming_.reserve(*msg_size);
         incoming_.insert(incoming_.begin(), *msg_size, 0);
         a::async_read(socket_, a::buffer(incoming_),

src/connection.hpp

         ack_msg = 1,
         put_msg = 2
     };
-    enum { command_length = 4 };
+    enum { command_length = 8 };
 public: // construction
     explicit connection(boost::asio::io_service& io_service, server *server);
     virtual ~connection();
 namespace bip = boost::interprocess;
 
 typedef uint64_t message_id;
-typedef uint32_t message_len_t;
+typedef uint64_t message_len_t;
 
 struct message_header {
     message_id id;