I have a few propositions regarding socket usage in send_pdu() and read_pdu() methods.
Here, instead of manually tracking how much is sent in a loop, using socket.sendall() method should make the code more concise and readable.
|
sent = 0 |
|
|
|
while sent < len(generated): |
|
try: |
|
sent_last = self._socket.send(generated[sent:]) |
|
except socket.error as e: |
|
self.logger.warning(e) |
|
raise exceptions.ConnectionError() |
|
if sent_last == 0: |
|
raise exceptions.ConnectionError() |
|
sent += sent_last |
In read_pdu, we don't check len(raw_len) == 4. For less than 4 bytes we raise PDUError. But we could possibly get raw_len in multiple with recv, just like when we are reading the rest of the PDU.
I propose we refactor the "keep recving until we got all bytes" into a separate method (i.e. _recv_exact(n)), and then read raw_len and raw_pdu with this method.
If you are interested, I will send pull requests for these changes.
I have a few propositions regarding socket usage in
send_pdu()andread_pdu()methods.Here, instead of manually tracking how much is sent in a loop, using
socket.sendall()method should make the code more concise and readable.python-smpplib/smpplib/client.py
Lines 215 to 225 in 9ca29cf
In
read_pdu, we don't checklen(raw_len) == 4. For less than 4 bytes we raisePDUError. But we could possibly getraw_lenin multiple withrecv, just like when we are reading the rest of the PDU.I propose we refactor the "keep
recving until we got all bytes" into a separate method (i.e._recv_exact(n)), and then readraw_lenandraw_pduwith this method.If you are interested, I will send pull requests for these changes.