Forum Discussion
Netx Duo Question - NX_TCP_SOCKET and BSD fd_sets Functionality
Hi,
I hope this is the correct place to ask this question.
I'm looking at porting an existing application across to Duo, this app uses WEBSOCKETS/TLS/TCP within a BSD socket and makes use of the BSD fd_sets mechanism to detect receive data, ability to send data and loss of connection, sending multiple messages over a single socket.
Using the Duo API's I need to use the NX_TCP_SOCKET based APIs, to gain WEBSOCKETS/TLS functionality but so far, I haven't spotted a bsd_fd_set equivalent mechanism for this socket type. Is there a similar feature available?
The examples I've found don't persist a socket across multiple messages so don't need that feature. Any help/information on this appreciated.
Many Thanks
Wayne
1 Reply
- trntGLCopper Contributor
Hi Wayne,
You’re right - the Duo/NetX stack doesn’t provide a direct equivalent to fd_set/select() like you’d see in a BSD socket environment. With NX_TCP_SOCKET you’re mostly working with callback-driven events and explicit status checking rather than multiplexing across a set of sockets.
The usual approach is:
Use NetX Duo socket callbacks (nx_tcp_socket_receive_notify, nx_tcp_socket_disconnect_complete_notify, etc.) to get notified when data arrives or the state changes.
Maintain your own lightweight state machine if you need to track multiple sockets and their readiness at once.
For WebSockets/TLS specifically, you’ll typically wrap the NX_SECURE_TLS_SESSION over an NX_TCP_SOCKET and keep the socket open across multiple sends/receives.
if you’re porting code that depends heavily on select()/fd_set, you’ll likely need to build a small abstraction layer that normalizes the NetX Duo callbacks into a poll-like API. We had to do some equal thing in a project at Modsen, where we migrated a legacy BSD-sockets application onto NetX Duo. Our solution was to implement a “socket manager” task that monitored callbacks and queued readiness events, which the rest of the app could consume in a select()-like fashion.
So short answer: there’s no built-in fd_set, but with callbacks + a small abstraction you can get equivalent behavior.
Hope it will be useful!