@@ -85,7 +85,7 @@ def __init__(self, _socket, field_types=None):
85
85
:params _socket: socket connected to the server
86
86
:type _socket: instance of socket.socket class (from stdlib)
87
87
'''
88
-
88
+ # This is not necessary, because underlying list data structures are created in the __new__(). But let it be.
89
89
super (Response , self ).__init__ ()
90
90
91
91
self ._body_length = None
@@ -100,23 +100,32 @@ def __init__(self, _socket, field_types=None):
100
100
# Read response header
101
101
buff = ctypes .create_string_buffer (16 )
102
102
nbytes = _socket .recv_into (buff , 16 , )
103
+
103
104
# Immediately raises an exception if the data cannot be read
104
105
if nbytes != 16 :
105
106
raise socket .error (socket .errno .ECONNABORTED , "Software caused connection abort" )
107
+
106
108
# Unpack header (including <return_code> attribute)
107
109
self ._request_type , self ._body_length , self ._request_id , self ._return_code = struct_LLLL .unpack (buff )
110
+
108
111
# Separate return_code and completion_code
109
112
self ._completion_status = self ._return_code & 0x00ff
110
113
self ._return_code = self ._return_code >> 8
114
+
111
115
# Unpack body if there is one (i.e. not PING)
112
116
if self ._body_length != 0 :
113
- self ._body_length -= 4 # In the protocol description <body_length> includes 4 bytes of <return_code>
117
+
118
+ # In the protocol description <body_length> includes 4 bytes of <return_code>
119
+ self ._body_length -= 4
120
+
114
121
# Read response body
115
122
buff = ctypes .create_string_buffer (self ._body_length )
116
123
nbytes = _socket .recv_into (buff )
124
+
117
125
# Immediately raises an exception if the data cannot be read
118
126
if nbytes != self ._body_length :
119
127
raise socket .error (socket .errno .ECONNABORTED , "Software caused connection abort" )
128
+
120
129
if self ._return_code == 0 :
121
130
# If no errors, unpack response body
122
131
self ._unpack_body (buff )
0 commit comments