@@ -94,9 +94,11 @@ class Connector
94
94
/* *
95
95
* A helper to decode responses of a connection.
96
96
* Can be called when the connection is not ready to decode - it's just no-op.
97
+ * If `result` is not `nullptr`, it is used to return response for a request with
98
+ * `req_sync` sync. If `result` is `nullptr` - `req_sync` is ignored.
97
99
* Returns -1 in the case of any error, 0 on success.
98
100
*/
99
- int connectionDecodeResponses (Connection<BUFFER, NetProvider> &conn,
101
+ int connectionDecodeResponses (Connection<BUFFER, NetProvider> &conn, int req_sync = - 1 ,
100
102
Response<BUFFER> *result = nullptr );
101
103
102
104
private:
@@ -172,7 +174,7 @@ Connector<BUFFER, NetProvider>::close(ConnectionImpl<BUFFER, NetProvider> &conn)
172
174
173
175
template <class BUFFER , class NetProvider >
174
176
int
175
- Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, NetProvider> &conn,
177
+ Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, NetProvider> &conn, int req_sync,
176
178
Response<BUFFER> *result)
177
179
{
178
180
if (!hasDataToDecode (conn))
@@ -183,7 +185,7 @@ Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, Net
183
185
184
186
int rc = 0 ;
185
187
while (hasDataToDecode (conn)) {
186
- DecodeStatus status = processResponse (conn, result);
188
+ DecodeStatus status = processResponse (conn, req_sync, result);
187
189
if (status == DECODE_ERR) {
188
190
rc = -1 ;
189
191
break ;
@@ -213,11 +215,13 @@ Connector<BUFFER, NetProvider>::wait(Connection<BUFFER, NetProvider> &conn,
213
215
Timer timer{timeout};
214
216
timer.start ();
215
217
static constexpr int INVALID_SYNC = -1 ;
218
+ int req_sync = static_cast <int >(future);
216
219
if (result != NULL )
217
220
result->header .sync = INVALID_SYNC;
218
- if (connectionDecodeResponses (conn, result) != 0 )
221
+ if (connectionDecodeResponses (conn, req_sync, result) != 0 )
219
222
return -1 ;
220
223
if (result != NULL && result->header .sync != INVALID_SYNC) {
224
+ assert (result->header .sync == req_sync);
221
225
LOG_DEBUG (" Future " , future, " is ready and decoded" );
222
226
return 0 ;
223
227
}
@@ -227,9 +231,10 @@ Connector<BUFFER, NetProvider>::wait(Connection<BUFFER, NetProvider> &conn,
227
231
strerror (errno), errno);
228
232
return -1 ;
229
233
}
230
- if (connectionDecodeResponses (conn, result) != 0 )
234
+ if (connectionDecodeResponses (conn, req_sync, result) != 0 )
231
235
return -1 ;
232
236
if (result != NULL && result->header .sync != INVALID_SYNC) {
237
+ assert (result->header .sync == req_sync);
233
238
LOG_DEBUG (" Future " , future, " is ready and decoded" );
234
239
return 0 ;
235
240
}
0 commit comments