snmp_select_info() timeout behaviour

Joe Stringer <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CAPmMjUmP26hg2d13o0foz7FdsfH_9-MMMZqYHnyhJzDO0q3NjA@mail.gmail.com>
Greetings,

I've been writing a subagent against net-snmp 5.7.1 under a 64-bit
ubuntu linux install, based on the example subagent code
(http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demon/example-demon.c),
using the snmp_select_info() API. In addition to handling snmp
communication with the master, it is sending messages to a nox
application on a regular interval, and dealing with responses from
that socket.

It seems that if select() times out after <15secs, then I call
snmp_select_info(), it will try to set the timeout so that it will
expire 15sec after the original call. All subsequent calls to
snmp_select_info() set the timeout to 1usec.

Example: if poll_interval_ = 14sec,
- socket() times out after 14s, and a message is sent. I reset the
timer to 14sec.
- when snmp_select_info() is next passed the timer object, it resets
the timer to ~1sec.
- After this timeout, I reset the timer to 14sec, then
snmp_select_info() changes the timeout to {0,1}.
- Repeat the last step ad infinitum!

Why does net-snmp do this? It seems to be fine if I set poll_interval_ >=15sec.

Am I missing some API calls that I should be making?

Below is the main loop of the code I'm using, followed by the output I
see. The code beforehand is mostly the same as the example, with a
couple of extra variable declarations, socket setup, sending an
initial msg to noxfd.

-- CODE --
  /* Set up our timers */
  struct timeval expire_time,timer;
  timerclear(&timer);
  timerclear(&expire_time);
  timer.tv_sec = poll_interval_;

  size_t len = 0;
  while(keep_running_) {
    FD_ZERO(&fdset);
    FD_SET(noxfd, &fdset);

    fprintf(stderr, "Timer check %d:%d\n", timer.tv_sec, timer.tv_usec);

    gettimeofday(&expire_time, NULL);
    expire_time.tv_sec += poll_interval_;

    snmp_select_info(&numfds, &fdset, &timer, &block);

    fprintf(stderr, "Timer check1 %d:%d\n", timer.tv_sec, timer.tv_usec);

    count = select(numfds, &fdset, NULL, NULL, &timer);

    if (count == 0) {
      /* Regular stats request sending */
      if (send(noxfd,stats_msg, strlen(stats_msg), 0) != 0)
        snmp_log(LOG_ERR, "Failed to send stats_request");

      snmp_timeout();
      timer.tv_sec = poll_interval_;
      timer.tv_usec = 0;
      fprintf(stderr, "Timer reset %d:%d\n", timer.tv_sec, timer.tv_usec);
    } else if (count > 0) {
      /* Either nox or netsnmp has an event to deal with */
      if(FD_ISSET(noxfd, &fdset)) {
        if ((len = read(noxfd, buf, 2048)) > 0) {
          parse_response(buf, len);
        }

        /* Make sure snmp_read() doesn't tinker with our noxfd */
        FD_CLR(noxfd, &fdset);
        --count;
      }
      if (count > 0) /* If there are SNMP events */
        snmp_read(&fdset);

      struct timeval current;
      gettimeofday(&current, NULL);
      timersub(&expire_time, &current, &timer);

      fprintf(stderr, "Timer check2: %d:%d\n", timer.tv_sec, timer.tv_usec);
    }
  }

-- OUTPUT --
Timer check 14:0
Timer check1 14:0
Parsing response...
Timer check2: 13:998949
Timer check 13:998949
Timer check1 13:998949
Timer reset 14:0
Timer check 14:0
Timer check1 0:985627
Timer reset 14:0
Timer check 14:0
Timer check1 0:1
Timer reset 14:0
Timer check 14:0
Timer check1 0:1
Timer reset 14:0
Timer check 14:0
Timer check1 0:1
Timer reset 14:0
Timer check 14:0
...

Any help would be appreciated.

Cheers,
Joe

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.