Skip to content

Commit 85e37d7

Browse files
committed
librdmacm: ensure poll handles normal file descriptors correctly
When using rdma-core's preload library, the poll function needs to correctly distinguish between rsocket-managed fds and normal fds. This change ensures that pollfd structures are properly prepared and the call is routed to either the native poll or rpoll based on the actual fd type. Signed-off-by: zhangwenge <zhangwengege@126.com>
1 parent 0f5413e commit 85e37d7

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

librdmacm/preload.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -966,16 +966,10 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
966966
{
967967
struct pollfd *rfds;
968968
int i, ret;
969+
int has_rsocket = 0;
969970

970971
init_preload();
971-
for (i = 0; i < nfds; i++) {
972-
if (fd_gett(fds[i].fd) == fd_rsocket)
973-
goto use_rpoll;
974-
}
975972

976-
return real.poll(fds, nfds, timeout);
977-
978-
use_rpoll:
979973
rfds = fds_alloc(nfds);
980974
if (!rfds)
981975
return ERR(ENOMEM);
@@ -984,9 +978,15 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout)
984978
rfds[i].fd = fd_getd(fds[i].fd);
985979
rfds[i].events = fds[i].events;
986980
rfds[i].revents = 0;
981+
982+
if (fd_gett(fds[i].fd) == fd_rsocket)
983+
has_rsocket = 1;
987984
}
988985

989-
ret = rpoll(rfds, nfds, timeout);
986+
if (!has_rsocket)
987+
ret = real.poll(rfds, nfds, timeout);
988+
else
989+
ret = rpoll(rfds, nfds, timeout);
990990

991991
for (i = 0; i < nfds; i++)
992992
fds[i].revents = rfds[i].revents;

0 commit comments

Comments
 (0)