@@ -93,10 +93,12 @@ class Connector
9393 /* *
9494 * A helper to decode responses of a connection.
9595 * Can be called when the connection is not ready to decode - it's just no-op.
96+ * If `result` is not `nullptr`, it is used to return response for a request with
97+ * `req_sync` sync. If `result` is `nullptr` - `req_sync` is ignored.
9698 * Returns -1 in the case of any error, 0 on success.
9799 */
98100 int connectionDecodeResponses (Connection<BUFFER, NetProvider> &conn,
99- Response<BUFFER> *result);
101+ int req_sync, Response<BUFFER> *result);
100102private:
101103 NetProvider m_NetProvider;
102104 /* *
@@ -171,7 +173,7 @@ Connector<BUFFER, NetProvider>::close(ConnectionImpl<BUFFER, NetProvider> &conn)
171173template <class BUFFER , class NetProvider >
172174int
173175Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, NetProvider> &conn,
174- Response<BUFFER> *result)
176+ int req_sync, Response<BUFFER> *result)
175177{
176178 if (!hasDataToDecode (conn))
177179 return 0 ;
@@ -181,7 +183,7 @@ Connector<BUFFER, NetProvider>::connectionDecodeResponses(Connection<BUFFER, Net
181183
182184 int rc = 0 ;
183185 while (hasDataToDecode (conn)) {
184- DecodeStatus status = processResponse (conn, result);
186+ DecodeStatus status = processResponse (conn, req_sync, result);
185187 if (status == DECODE_ERR) {
186188 rc = -1 ;
187189 break ;
@@ -211,9 +213,10 @@ Connector<BUFFER, NetProvider>::wait(Connection<BUFFER, NetProvider> &conn,
211213 Timer timer{timeout};
212214 timer.start ();
213215 static constexpr int INVALID_SYNC = -1 ;
216+ int req_sync = static_cast <int >(future);
214217 if (result != NULL )
215218 result->header .sync = INVALID_SYNC;
216- if (connectionDecodeResponses (conn, result) != 0 )
219+ if (connectionDecodeResponses (conn, req_sync, result) != 0 )
217220 return -1 ;
218221 if (result != NULL && result->header .sync != INVALID_SYNC) {
219222 LOG_DEBUG (" Future " , future, " is ready and decoded" );
@@ -225,7 +228,7 @@ Connector<BUFFER, NetProvider>::wait(Connection<BUFFER, NetProvider> &conn,
225228 strerror (errno), errno);
226229 return -1 ;
227230 }
228- if (connectionDecodeResponses (conn, result) != 0 )
231+ if (connectionDecodeResponses (conn, req_sync, result) != 0 )
229232 return -1 ;
230233 if (result != NULL && result->header .sync != INVALID_SYNC) {
231234 LOG_DEBUG (" Future " , future, " is ready and decoded" );
@@ -264,7 +267,7 @@ Connector<BUFFER, NetProvider>::waitAll(Connection<BUFFER, NetProvider> &conn,
264267 strerror (errno), errno);
265268 return -1 ;
266269 }
267- if (connectionDecodeResponses (conn, nullptr ) != 0 )
270+ if (connectionDecodeResponses (conn, 0 , nullptr ) != 0 )
268271 return -1 ;
269272 bool finish = true ;
270273 for (size_t i = last_not_ready; i < futures.size (); ++i) {
@@ -304,7 +307,7 @@ Connector<BUFFER, NetProvider>::waitAny(int timeout)
304307 }
305308 Connection<BUFFER, NetProvider> conn = *m_ReadyToDecode.begin ();
306309 assert (hasDataToDecode (conn));
307- if (connectionDecodeResponses (conn, nullptr ) != 0 )
310+ if (connectionDecodeResponses (conn, 0 , nullptr ) != 0 )
308311 return std::nullopt ;
309312 return conn;
310313}
@@ -323,7 +326,7 @@ Connector<BUFFER, NetProvider>::waitCount(Connection<BUFFER, NetProvider> &conn,
323326 strerror (errno), errno);
324327 return -1 ;
325328 }
326- if (connectionDecodeResponses (conn, nullptr ) != 0 )
329+ if (connectionDecodeResponses (conn, 0 , nullptr ) != 0 )
327330 return -1 ;
328331 if ((conn.getFutureCount () - ready_futures) >= future_count)
329332 return 0 ;
0 commit comments