diff options
-rw-r--r-- | include/bsc_data.h | 1 | ||||
-rw-r--r-- | include/snmp_mtp.h | 1 | ||||
-rw-r--r-- | src/link_udp.c | 11 | ||||
-rw-r--r-- | src/snmp_mtp.c | 27 |
4 files changed, 40 insertions, 0 deletions
diff --git a/include/bsc_data.h b/include/bsc_data.h index 587afec..3311d53 100644 --- a/include/bsc_data.h +++ b/include/bsc_data.h @@ -43,6 +43,7 @@ struct snmp_mtp_session; struct mtp_udp_data { struct write_queue write_queue; struct snmp_mtp_session *session; + struct timer_list snmp_poll; struct llist_head links; }; diff --git a/include/snmp_mtp.h b/include/snmp_mtp.h index a42b08e..beefa48 100644 --- a/include/snmp_mtp.h +++ b/include/snmp_mtp.h @@ -34,5 +34,6 @@ void snmp_mtp_stop_c7_datalink(struct snmp_mtp_session *, int link_id); struct snmp_mtp_session *snmp_mtp_session_create(char *host); void snmp_mtp_deactivate(struct snmp_mtp_session *, int link_id); void snmp_mtp_activate(struct snmp_mtp_session *, int link_id); +void snmp_mtp_poll(); #endif diff --git a/src/link_udp.c b/src/link_udp.c index 04dcec8..fd6b1f9 100644 --- a/src/link_udp.c +++ b/src/link_udp.c @@ -232,6 +232,13 @@ int link_udp_init(struct mtp_udp_link *link, const char *remote, int port) return 0; } +static void snmp_poll(void *_data) +{ + struct mtp_udp_data *data = _data; + snmp_mtp_poll(); + bsc_schedule_timer(&data->snmp_poll, 0, 5000); +} + int link_global_init(struct mtp_udp_data *data, int src_port) { struct sockaddr_in addr; @@ -274,5 +281,9 @@ int link_global_init(struct mtp_udp_data *data, int src_port) return -1; } + data->snmp_poll.data = data; + data->snmp_poll.cb = snmp_poll; + snmp_poll(data); + return 0; } diff --git a/src/snmp_mtp.c b/src/snmp_mtp.c index ba3a219..fc347aa 100644 --- a/src/snmp_mtp.c +++ b/src/snmp_mtp.c @@ -109,3 +109,30 @@ void snmp_mtp_activate(struct snmp_mtp_session *session, int index) { snmp_mtp_start_c7_datalink(session, index); } + +/** + * This is the easiest way to integrate SNMP without + * introducing threads. It would be nicer if it could + * register a timeout and the fd it wants to have selected + * for reading. We could try to find the fd's it is using + * for the session but there is no difference in performance + */ +void snmp_mtp_poll() +{ + int num_fds = 0, block = 0; + fd_set fds; + FD_ZERO(&fds); + struct timeval tv; + int rc; + + snmp_select_info(&num_fds, &fds, &tv, &block); + + + memset(&tv, 0, sizeof(tv)); + + rc = select(num_fds, &fds, NULL, NULL, &tv); + if (rc == 0) + snmp_timeout(); + else + snmp_read(&fds); +} |