mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-05 02:34:18 +00:00
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:
parent
86508b853c
commit
e33b676d6e
@ -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,53 +279,62 @@ 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) {
|
|
||||||
char *packet;
|
if (!len) {
|
||||||
uint64_t host_hash = 0;
|
if (SWITCH_STATUS_IS_BREAK(status)) {
|
||||||
|
switch_yield(100000);
|
||||||
memcpy(&host_hash, buf, sizeof(host_hash));
|
|
||||||
packet = buf + sizeof(host_hash);
|
|
||||||
|
|
||||||
if (host_hash == globals.host_hash) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet);
|
|
||||||
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
|
|
||||||
char *var, *val, *term = NULL, tmpname[128];
|
|
||||||
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
|
|
||||||
var = packet;
|
|
||||||
while (*var) {
|
|
||||||
if ((val = strchr(var, ':')) != 0) {
|
|
||||||
*val++ = '\0';
|
|
||||||
while (*val == ' ') {
|
|
||||||
val++;
|
|
||||||
}
|
|
||||||
if ((term = strchr(val, '\r')) != 0 || (term = strchr(val, '\n')) != 0) {
|
|
||||||
*term = '\0';
|
|
||||||
while (*term == '\r' || *term == '\n') {
|
|
||||||
term++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch_snprintf(tmpname, sizeof(tmpname), "Orig-%s", var);
|
|
||||||
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, tmpname, "%s", val);
|
|
||||||
var = term + 1;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (var && strlen(var) > 1) {
|
break;
|
||||||
switch_event_add_body(local_event, var);
|
|
||||||
}
|
|
||||||
|
|
||||||
switch_event_fire(&local_event);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(&host_hash, buf, sizeof(host_hash));
|
||||||
|
packet = buf + sizeof(host_hash);
|
||||||
|
|
||||||
|
if (host_hash == globals.host_hash) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "\nEVENT %d\n--------------------------------\n%s\n", (int) len, packet);
|
||||||
|
if (switch_event_create_subclass(&local_event, SWITCH_EVENT_CUSTOM, MULTICAST_EVENT) == SWITCH_STATUS_SUCCESS) {
|
||||||
|
char *var, *val, *term = NULL, tmpname[128];
|
||||||
|
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, "Multicast", "yes");
|
||||||
|
var = packet;
|
||||||
|
while (*var) {
|
||||||
|
if ((val = strchr(var, ':')) != 0) {
|
||||||
|
*val++ = '\0';
|
||||||
|
while (*val == ' ') {
|
||||||
|
val++;
|
||||||
|
}
|
||||||
|
if ((term = strchr(val, '\r')) != 0 || (term = strchr(val, '\n')) != 0) {
|
||||||
|
*term = '\0';
|
||||||
|
while (*term == '\r' || *term == '\n') {
|
||||||
|
term++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch_snprintf(tmpname, sizeof(tmpname), "Orig-%s", var);
|
||||||
|
switch_event_add_header(local_event, SWITCH_STACK_BOTTOM, tmpname, "%s", val);
|
||||||
|
var = term + 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (var && strlen(var) > 1) {
|
||||||
|
switch_event_add_body(local_event, var);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch_event_fire(&local_event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
globals.running = 0;
|
globals.running = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user