Skip to content

Commit f80b82b

Browse files
committed
Add timeout handling in RDMA buffer sending
The ep_send_buf() function keeps running a loop forever. Avoid this by checking the timeout. Signed-off-by: Konstantin Ilichev <konstantin.ilichev@intel.com>
1 parent b035ca1 commit f80b82b

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

media-proxy/src/libfabric_ep.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,13 @@ int ep_send_buf(ep_ctx_t* ep_ctx, void* buf, size_t buf_size) {
196196
}
197197

198198
int ret;
199+
struct timespec start_time, current_time;
200+
long elapsed_time_ms;
199201

200-
do {
202+
// Get the current time as the start time
203+
clock_gettime(CLOCK_MONOTONIC, &start_time);
204+
205+
for (;;) {
201206
// Check if the stop flag is set
202207
if (ep_ctx->stop_flag) {
203208
ERROR("RDMA stop flag is set. Aborting send.");
@@ -210,7 +215,22 @@ int ep_send_buf(ep_ctx_t* ep_ctx, void* buf, size_t buf_size) {
210215
struct fi_cq_entry cq_entry;
211216
(void)fi_cq_read(ep_ctx->cq_ctx.cq, &cq_entry, 1); // Drain CQ
212217
}
213-
} while (ret == -EAGAIN);
218+
219+
// Get the current time and calculate the elapsed time
220+
clock_gettime(CLOCK_MONOTONIC, &current_time);
221+
elapsed_time_ms = (current_time.tv_sec - start_time.tv_sec) * 1000 +
222+
(current_time.tv_nsec - start_time.tv_nsec) / 1000000;
223+
224+
if (ret == -EAGAIN) {
225+
// Check if the elapsed time exceeds the timeout interval
226+
if (elapsed_time_ms > 100)
227+
return -ETIMEDOUT;
228+
else
229+
continue;
230+
}
231+
232+
break;
233+
}
214234

215235
return ret;
216236
}

0 commit comments

Comments
 (0)