make multicast event handler nonblocking

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7633 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-02-15 21:16:39 +00:00
parent 86508b853c
commit e33b676d6e

View File

@ -237,6 +237,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_multicast_load)
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
switch_socket_opt_set(globals.udp_socket, SWITCH_SO_NONBLOCK, TRUE);
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
@ -247,10 +248,6 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_event_multicast_shutdown)
{ {
int x = 0; int x = 0;
if (globals.udp_socket) {
switch_socket_shutdown(globals.udp_socket, SWITCH_SHUTDOWN_READWRITE);
}
if (globals.running == 1) { if (globals.running == 1) {
globals.running = -1; globals.running = -1;
while (x < 100000 && globals.running) { while (x < 100000 && globals.running) {
@ -282,13 +279,22 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
while (globals.running == 1) { while (globals.running == 1) {
char *myaddr; char *myaddr;
size_t len = MULTICAST_BUFFSIZE; size_t len = MULTICAST_BUFFSIZE;
char *packet;
uint64_t host_hash = 0;
switch_status_t status;
memset(buf, 0, len); memset(buf, 0, len);
switch_sockaddr_ip_get(&myaddr, globals.addr); switch_sockaddr_ip_get(&myaddr, globals.addr);
status = switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len);
if (switch_socket_recvfrom(addr, globals.udp_socket, 0, buf, &len) == SWITCH_STATUS_SUCCESS) { if (!len) {
char *packet; if (SWITCH_STATUS_IS_BREAK(status)) {
uint64_t host_hash = 0; switch_yield(100000);
continue;
}
break;
}
memcpy(&host_hash, buf, sizeof(host_hash)); memcpy(&host_hash, buf, sizeof(host_hash));
packet = buf + sizeof(host_hash); packet = buf + sizeof(host_hash);
@ -328,7 +334,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_multicast_runtime)
switch_event_fire(&local_event); switch_event_fire(&local_event);
} }
}
} }
globals.running = 0; globals.running = 0;