fix reply timeout: move hash and pid to session pool FS-3432

This commit is contained in:
Tamas Cseke 2012-06-11 17:25:28 +02:00
parent d2e9e46eb6
commit 3f6b5a5c01
2 changed files with 6 additions and 16 deletions

View File

@ -1108,7 +1108,7 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e
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;
erlang_pid pid;
char hash[100];
int arity;
const void *key;
@ -1123,15 +1123,7 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg,
return SWITCH_STATUS_FALSE;
}
if (!(pid = malloc(sizeof(erlang_pid)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error\n");
ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "badmem");
return SWITCH_STATUS_SUCCESS;
}
if (ei_decode_pid(buf->buff, &buf->index, pid)) {
if (ei_decode_pid(buf->buff, &buf->index, &pid)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid pid in a reference/pid tuple\n");
return SWITCH_STATUS_FALSE;
}
@ -1149,7 +1141,9 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg,
switch_mutex_lock(se->spawn_reply->mutex);
if (se->spawn_reply->state == reply_waiting) {
se->spawn_reply->pid = pid;
se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid));
switch_assert(se->spawn_reply->pid != NULL);
memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid));
switch_thread_cond_signal(se->spawn_reply->ready_or_found);
ei_x_encode_atom(rbuf, "ok");
switch_thread_rwlock_unlock(listener->session_rwlock);
@ -1167,8 +1161,6 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg,
ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "notfound");
switch_safe_free(pid); /* don't need it */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -1377,7 +1377,7 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul
switch_thread_cond_create(&p->ready_or_found, session_element->pool);
switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, session_element->pool);
p->state = reply_waiting;
p->hash = hash;
p->hash = switch_core_strdup(session_element->pool, hash);
p->pid = NULL;
session_element->spawn_reply = p;
@ -1437,8 +1437,6 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul
ei_link(listener, ei_self(listener->ec), &session_element->process.pid);
switch_safe_free(p->pid);
return session_element;
}