Hi there.

I have two threads.  The main thread sends snmp requests, the other receives
responses.  And I can only use snmp_sess_*() calls since it is
multithreaded.

I want to be able to send requests and forget about them until a response is
detected on the socket.  I want to do this so that I don't have to wait on
responses as they could take a long time (might get timeout).  This will
slow things down considerably.  Hence, that's why the receive thread will
block on select() waiting for responses.

In the main thread, I send the requests using snmp_sess_async_send(), where
the callback function will be called in the receive thread after
snmp_sess_read() is called (also in the receive thread).

Basically, when I add a new snmp session (which are created for every snmp
request) I get the session's socket fd and update a global fd_set so that
the receive thread can call select() on it.  I also use a pipe to wake up
the receive thread and tell it to call select() again on the updated
fd_set.  Once the receive thread gets a response, I call snmp_sess_read() on
the corresponding session which calls the callback function.

I am using opaque pointers for sessions and only using snmp_sess_*() calls
as per README.threads recommendation.  However, I am getting segmentation
faults when running my progam.  It segfaults in the same place every time,
which is _sess_read which is called by snmp_sess_read().  I am guessing both
threads are trying to access the same data or something?

One thing I noticed is that if I don't clean up the sessions with
snmp_sess_close() then I do not get a segault.  But obviously this is not
good since I get "Too many open files" error as I'm not clearing the
sessions.  Hopefully this is a clue for someone.

I thought maybe cleaning up the sessions in the receive thread as opposed to
the main thread might have been the problem.  So I tried cleaning any old
sessions lying about in the main thread instead.  Didn't work, same
outcome.  Seg fault on _sess_read().

Anyway, here is the pertinent code - http://pastebin.com/5SAke4FA
Hopefully you can see what I am trying to do.  I would really appreciate any
help on this.

Thanks,
T
------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to