Reputation: 91
I think the question is not new: I have a thread which should read from an X server (via XCB) and another server connected with TCP, so calling select is needed.
What's confusing me is, when the program returns from select, turning out there is data in the X server link, what if the data is not enough for an XCB event? In this case xcb_poll_for_event() should return NULL, but when the program calls select again it does not block because there is some data after all, so the program is trapped in the "busy" waiting state.
Is this a valid concern? I believe so because each XCB event is composed of many bytes and the server may be interrupted during sending.
Upvotes: 1
Views: 493
Reputation: 551
How about setting the SO_RCVLOWAT for the xcb fd with the required size of an XCB event using setsockopt(). Now, the socket's file descriptor will only select as readable when there is at least that amount of data read to read. This is normal approach we used when dealing with TCP server's, haven't tried this with XCB fd's though.
Upvotes: 0