Esempio n. 1
0
 def send_event(self, evtname, payload, blobs):
     self.event_sock.sendall(STX + event2code[evtname] +
                             (b'%c' % len(blobs)) +
                             LENGTH.pack(len(payload)))
     # send data separately to avoid copying lots of data
     self.event_sock.sendall(payload)
     for blob in blobs:
         self.event_sock.sendall(LENGTH.pack(len(blob)))
         self.event_sock.sendall(blob)
Esempio n. 2
0
 def send_error_reply(self, reason):
     try:
         data = self.serializer.serialize_error_reply(reason)
     except Exception as err:
         raise ProtocolError('send_error_reply: could not serialize')
     try:
         self.sock.sendall(NAK + LENGTH.pack(len(data)) + data)
     except socket.error as err:
         raise ProtocolError('send_error_reply: connection broken (%s)' % err)
Esempio n. 3
0
 def send_ok_reply(self, payload):
     try:
         if payload is None:
             self.sock.sendall(ACK)
         else:
             try:
                 data = self.serializer.serialize_ok_reply(payload)
             except Exception as err:
                 raise ProtocolError('send_ok_reply: could not serialize')
             self.sock.sendall(STX + LENGTH.pack(len(data)) + data)
     except socket.error as err:
         raise ProtocolError('send_ok_reply: connection broken (%s)' % err)
Esempio n. 4
0
 def send_event(self, evtname, payload):
     # payload is already serialized if necessary!
     self.event_sock.sendall(STX + event2code[evtname] +
                             LENGTH.pack(len(payload)))
     # send data separately to avoid copying lots of data
     self.event_sock.sendall(payload)
Esempio n. 5
0
 def send_command(self, cmdname, args):
     data = self.serializer.serialize_cmd(cmdname, args)
     self.sock.sendall(ENQ + command2code[cmdname] +
                       LENGTH.pack(len(data)) + data)