[Freeswitch-trunk] [commit] r12543 - freeswitch/trunk/src/mod/event_handlers/mod_erlang_event
FreeSWITCH SVN
andrew at freeswitch.org
Mon Mar 9 13:22:42 PDT 2009
Author: andrew
Date: Mon Mar 9 15:22:42 2009
New Revision: 12543
Log:
Some more memory management tweaks
Modified:
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c
freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/handle_msg.c Mon Mar 9 15:22:42 2009
@@ -165,20 +165,47 @@
static switch_status_t handle_msg_fetch_reply(listener_t *listener, ei_x_buff *buf, ei_x_buff *rbuf)
{
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH + 1];
+ void *p;
if (ei_decode_string_or_binary(buf->buff, &buf->index, SWITCH_UUID_FORMATTED_LENGTH, uuid_str)) {
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badarg");
} else {
- ei_x_buff *nbuf = switch_core_alloc(listener->pool, sizeof(nbuf));
- nbuf->buff = switch_core_alloc(listener->pool, buf->buffsz);
+ ei_x_buff *nbuf = malloc(sizeof(nbuf));
+ nbuf->buff = malloc(buf->buffsz);
memcpy(nbuf->buff, buf->buff, buf->buffsz);
nbuf->index = buf->index;
nbuf->buffsz = buf->buffsz;
-
- switch_core_hash_insert(listener->fetch_reply_hash, uuid_str, nbuf);
- ei_x_encode_atom(rbuf, "ok");
+
+ if ((p = switch_core_hash_find(listener->fetch_reply_hash, uuid_str))) {
+ if (p == &globals.TIMEOUT) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Handler for %s timed out\n", uuid_str);
+ switch_core_hash_delete(listener->fetch_reply_hash, uuid_str);
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "timeout");
+ } else if (p == &globals.WAITING) {
+ /* update the key to point at a pid */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found waiting slot for %s\n", uuid_str);
+ switch_core_hash_delete(listener->fetch_reply_hash, uuid_str);
+ switch_core_hash_insert(listener->fetch_reply_hash, uuid_str, nbuf);
+ ei_x_encode_atom(rbuf, "ok");
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Found filled slot for %s\n", uuid_str);
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "duplicate_response");
+ }
+ } else {
+ /* nothin in the hash */
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Empty slot for %s\n", uuid_str);
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "invalid_uuid");
+ }
+
+ /*switch_core_hash_insert(listener->fetch_reply_hash, uuid_str, nbuf);*/
}
return SWITCH_STATUS_SUCCESS;
}
@@ -700,7 +727,7 @@
static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg *msg, ei_x_buff *buf, ei_x_buff *rbuf)
{
erlang_ref ref;
- erlang_pid *pid;/* = switch_core_alloc(listener->pool, sizeof(erlang_pid));*/
+ erlang_pid *pid;
void *p;
char hash[100];
int arity;
Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c Mon Mar 9 15:22:42 2009
@@ -388,7 +388,7 @@
_ei_x_encode_string(&buf, uuid_str);
ei_encode_switch_event_headers(&buf, params);
- /*switch_core_hash_insert(ptr->reply_hash, uuid_str, );*/
+ switch_core_hash_insert(ptr->listener->fetch_reply_hash, uuid_str, &globals.WAITING);
switch_mutex_lock(ptr->listener->sock_mutex);
ei_sendto(ptr->listener->ec, ptr->listener->sockfd, &ptr->process, &buf);
@@ -396,16 +396,19 @@
int i = 0;
ei_x_buff *rep;
- /*int index = 3;*/
- while (!(rep = (ei_x_buff *) switch_core_hash_find(ptr->listener->fetch_reply_hash, uuid_str))) {
+ void *p = NULL;
+
+ while (!(p = switch_core_hash_find(ptr->listener->fetch_reply_hash, uuid_str)) || p == &globals.WAITING) {
if (i > 50) { /* half a second timeout */
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for XML fetch response!\n");
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Timed out when waiting for XML fetch response\n");
+ switch_core_hash_insert(ptr->listener->fetch_reply_hash, uuid_str, &globals.TIMEOUT); /* TODO lock this? */
return NULL;
}
i++;
switch_yield(10000); /* 10ms */
}
+ rep = (ei_x_buff *) p;
int type, size;
ei_get_type(rep->buff, &rep->index, &type, &size);
@@ -432,10 +435,10 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "XML parsed OK!\n");
}
+ /* cleanup */
switch_core_hash_delete(ptr->listener->fetch_reply_hash, uuid_str);
-
- /*switch_safe_free(rep->buff);*/
- /*switch_safe_free(rep);*/
+ free(rep->buff);
+ free(rep);
free(xmlstr);
return xml;
More information about the Freeswitch-trunk
mailing list