@@ -94,10 +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,
100
- Response<BUFFER> *result);
101
+ int connectionDecodeResponses (Connection<BUFFER, NetProvider> &conn, int req_sync, Response<BUFFER> *result);
101
102
102
103
private:
103
104
NetProvider m_NetProvider;
@@ -172,7 +173,7 @@ Connector<BUFFER, NetProvider>::close(ConnectionImpl<BUFFER, NetProvider> &conn)
172
173
173
174
template <class BUFFER , class NetProvider >
174
175
int
175
- Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, NetProvider> &conn,
176
+ Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, NetProvider> &conn, int req_sync,
176
177
Response<BUFFER> *result)
177
178
{
178
179
if (!hasDataToDecode (conn))
@@ -183,7 +184,7 @@ Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, Net
183
184
184
185
int rc = 0 ;
185
186
while (hasDataToDecode (conn)) {
186
- DecodeStatus status = processResponse (conn, result);
187
+ DecodeStatus status = processResponse (conn, req_sync, result);
187
188
if (status == DECODE_ERR) {
188
189
rc = -1 ;
189
190
break ;
@@ -213,9 +214,10 @@ Connector<BUFFER, NetProvider>::wait(Connection<BUFFER, NetProvider> &conn,
213
214
Timer timer{timeout};
214
215
timer.start ();
215
216
static constexpr int INVALID_SYNC = -1 ;
217
+ int req_sync = static_cast <int >(future);
216
218
if (result != NULL )
217
219
result->header .sync = INVALID_SYNC;
218
- if (connectionDecodeResponses (conn, result) != 0 )
220
+ if (connectionDecodeResponses (conn, req_sync, result) != 0 )
219
221
return -1 ;
220
222
if (result != NULL && result->header .sync != INVALID_SYNC) {
221
223
LOG_DEBUG (" Future " , future, " is ready and decoded" );
@@ -227,7 +229,7 @@ Connector<BUFFER, NetProvider>::wait(Connection<BUFFER, NetProvider> &conn,
227
229
strerror (errno), errno);
228
230
return -1 ;
229
231
}
230
- if (connectionDecodeResponses (conn, result) != 0 )
232
+ if (connectionDecodeResponses (conn, req_sync, result) != 0 )
231
233
return -1 ;
232
234
if (result != NULL && result->header .sync != INVALID_SYNC) {
233
235
LOG_DEBUG (" Future " , future, " is ready and decoded" );
@@ -266,7 +268,7 @@ Connector<BUFFER, NetProvider>::waitAll(Connection<BUFFER, NetProvider> &conn,
266
268
strerror (errno), errno);
267
269
return -1 ;
268
270
}
269
- if (connectionDecodeResponses (conn, nullptr ) != 0 )
271
+ if (connectionDecodeResponses (conn, 0 , nullptr ) != 0 )
270
272
return -1 ;
271
273
bool finish = true ;
272
274
for (size_t i = last_not_ready; i < futures.size (); ++i) {
@@ -306,7 +308,7 @@ Connector<BUFFER, NetProvider>::waitAny(int timeout)
306
308
}
307
309
Connection<BUFFER, NetProvider> conn = *m_ReadyToDecode.begin ();
308
310
assert (hasDataToDecode (conn));
309
- if (connectionDecodeResponses (conn, nullptr ) != 0 )
311
+ if (connectionDecodeResponses (conn, 0 , nullptr ) != 0 )
310
312
return std::nullopt;
311
313
return conn;
312
314
}
@@ -325,7 +327,7 @@ Connector<BUFFER, NetProvider>::waitCount(Connection<BUFFER, NetProvider> &conn,
325
327
strerror (errno), errno);
326
328
return -1 ;
327
329
}
328
- if (connectionDecodeResponses (conn, nullptr ) != 0 )
330
+ if (connectionDecodeResponses (conn, 0 , nullptr ) != 0 )
329
331
return -1 ;
330
332
if ((conn.getFutureCount () - ready_futures) >= future_count)
331
333
return 0 ;
0 commit comments