I'm having a hard time figuring out this one. I'm porting net-snmp into a ruby API while also exposing an API which could potentially be embedded into any event loop (eventmachine, celluloid-io...). For that, I have to circumvent the netsnmp lib way of doing things:
so, the libsnmp way:
# after establishing an snmp "session"
snmp_sess_async_read(&session, &pdu, callback, null)
# next call will write the ready-to-read descriptors into this fdset
snmp_sess_select_info(&session, &numfds, &fdset, &timeval, &block)
# fdset now contains a pointer to the fdset of selectable readers
select(numfds, &fdset, null null, tout)
# now fdsets are all readable, and we can read snmp
snmp_sess_read(&session, &fdset)
# this call will read from all the readable fdset. the callback will therefore be activated
So, I found a way to get the file descriptor from the session and exposing it to ruby, which means, I can directly wait on it to be readable using ruby API, my problem being, I still need an fdset pointer to pass to the snmp_sess_read method. So my question would be, how can I do this? I'm assuming I'll have to do some FFI magic, as ruby itself doesn't itself expose an IO collection as an fdset (I've looked into the source code, that's something that happens at the VM level):
# after establishing an snmp "session"
RubyLib.snmp_sess_async_read(session, pdu, callback, nil)
# I find the file descriptors and expose them as io objects in ruby land, and select on them
readers = IO.select([snmp_descriptors])
# now readers are all readable, but how to create the fdset to pass to snmp_sess_read????
RubyLib.snmp_sess_read(session, readers_to_fdset)
Hope someone can help me on this.