[svn-commits] dvossel: branch dvossel/stun_monitor r281872 - /team/dvossel/stun_monitor/res/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Aug 11 15:56:45 CDT 2010
Author: dvossel
Date: Wed Aug 11 15:56:41 2010
New Revision: 281872
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=281872
Log:
purge stun sock before new request
Modified:
team/dvossel/stun_monitor/res/res_stun_monitor.c
Modified: team/dvossel/stun_monitor/res/res_stun_monitor.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/stun_monitor/res/res_stun_monitor.c?view=diff&rev=281872&r1=281871&r2=281872
==============================================================================
--- team/dvossel/stun_monitor/res/res_stun_monitor.c (original)
+++ team/dvossel/stun_monitor/res/res_stun_monitor.c Wed Aug 11 15:56:41 2010
@@ -34,6 +34,7 @@
#include "asterisk/stun.h"
#include "asterisk/netsock2.h"
#include "asterisk/lock.h"
+#include <fcntl.h>
#define STANDARD_STUN_PORT 3478
#define DEFAULT_MONITOR_REFRESH 30
@@ -61,6 +62,21 @@
}
}
+/* \brief purge the stun socket's receive buffer before issuing a new request */
+static void stun_purge_socket(void)
+{
+ int flags = fcntl(args.stunsock, F_GETFL);
+ int res = 0;
+ unsigned char reply_buf[1024];
+
+ fcntl(args.stunsock, F_SETFL, flags | O_NONBLOCK);
+ while (res != -1) {
+ /* throw away everything in the buffer until we reach the end. */
+ res = recv(args.stunsock, reply_buf, sizeof(reply_buf), 0);
+ }
+ fcntl(args.stunsock, F_SETFL, flags & ~O_NONBLOCK);
+}
+
/* \brief called by scheduler to send STUN request */
static int stun_monitor_request(const void *blarg)
{
@@ -75,6 +91,9 @@
ast_log(LOG_ERROR, "STUN monitor: can not send STUN request, socket is not open\n");
goto monitor_request_cleanup;
}
+
+ stun_purge_socket();
+
if (!(ast_stun_request(args.stunsock, &args.stunaddr, NULL, &answer)) &&
(memcmp(&args.externaladdr, &answer, sizeof(args.externaladdr)))) {
const char *newaddr = ast_strdupa(ast_inet_ntoa(answer.sin_addr));
More information about the svn-commits
mailing list