I'm designing a C program in linux where I'll have two threads. One main thread is the event_processor_thread which does the main function processing. Second thread is an event_dispatcher thread running always in the background, writing to and reading from multiple interfaces in real time (non blocking async i/o)
I did some research on the net, and found that the best ways to implement non-blocking socket i/o can be accomplished via
- libevent
select()
I chose the latter, as its easier, and i'll have at the most 4 interfaces to read from/write to.
I'm clear on the listen/read mechanisms using readfds
, but I'm unsure on how to use the writefds
! If I put my data from the event_processor_thread to a shared memory and have this event dispatcher thread read this from shared memory and write using send()
, Will select take care of sending the data to socket on its own ? Is this why I need to use writefds
in select()
?
My apologies if my questions is not clear, what I basically want is to have a non blocking i/o thread to dispatch events to/from the event processor thread to the external interface. Any inputs in this regard is highly appreciated. Thanks!