reply state seems to be unnecessary FS-3432

This commit is contained in:
Tamas Cseke 2012-06-12 11:37:35 +02:00
parent 44fb1d00d7
commit 794f8cfb8b
3 changed files with 18 additions and 17 deletions

View File

@ -1115,6 +1115,7 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg,
void *val; void *val;
session_elem_t *se; session_elem_t *se;
switch_hash_index_t *iter; switch_hash_index_t *iter;
int found = 0;
ei_decode_tuple_header(buf->buff, &buf->index, &arity); ei_decode_tuple_header(buf->buff, &buf->index, &arity);
@ -1137,29 +1138,32 @@ static switch_status_t handle_ref_tuple(listener_t *listener, erlang_msg * msg,
switch_hash_this(iter, &key, NULL, &val); switch_hash_this(iter, &key, NULL, &val);
se = (session_elem_t*)val; se = (session_elem_t*)val;
if (se->spawn_reply && !strncmp(se->spawn_reply->hash, hash, 100)) { if (se->spawn_reply && !strncmp(se->spawn_reply->hash, hash, 100)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found matching session for %s : %s\n", hash, se->uuid_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "found matching session for %s : %s\n", hash, se->uuid_str);
switch_mutex_lock(se->spawn_reply->mutex); switch_mutex_lock(se->spawn_reply->mutex);
if (se->spawn_reply->state == reply_waiting) {
se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid)); se->spawn_reply->pid = switch_core_alloc(se->pool, sizeof(erlang_pid));
switch_assert(se->spawn_reply->pid != NULL); switch_assert(se->spawn_reply->pid != NULL);
memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid)); memcpy(se->spawn_reply->pid, &pid, sizeof(erlang_pid));
switch_thread_cond_signal(se->spawn_reply->ready_or_found); switch_thread_cond_signal(se->spawn_reply->ready_or_found);
ei_x_encode_atom(rbuf, "ok");
switch_mutex_unlock(se->spawn_reply->mutex); switch_mutex_unlock(se->spawn_reply->mutex);
switch_thread_rwlock_unlock(listener->session_rwlock);
return SWITCH_STATUS_SUCCESS; found++;
}
switch_mutex_unlock(se->spawn_reply->mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "get_pid came in too late for %s; %s\n", hash, se->uuid_str);
break; break;
} }
} }
switch_thread_rwlock_unlock(listener->session_rwlock); switch_thread_rwlock_unlock(listener->session_rwlock);
if (found) {
ei_x_encode_atom(rbuf, "ok");
} else {
ei_x_encode_tuple_header(rbuf, 2); ei_x_encode_tuple_header(rbuf, 2);
ei_x_encode_atom(rbuf, "error"); ei_x_encode_atom(rbuf, "error");
ei_x_encode_atom(rbuf, "notfound"); ei_x_encode_atom(rbuf, "notfound");
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -1376,7 +1376,6 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul
p = switch_core_alloc(session_element->pool, sizeof(*p)); p = switch_core_alloc(session_element->pool, sizeof(*p));
switch_thread_cond_create(&p->ready_or_found, session_element->pool); switch_thread_cond_create(&p->ready_or_found, session_element->pool);
switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, session_element->pool); switch_mutex_init(&p->mutex, SWITCH_MUTEX_UNNESTED, session_element->pool);
p->state = reply_waiting;
p->hash = switch_core_strdup(session_element->pool, hash); p->hash = switch_core_strdup(session_element->pool, hash);
p->pid = NULL; p->pid = NULL;
@ -1421,7 +1420,6 @@ session_elem_t *attach_call_to_spawned_process(listener_t *listener, char *modul
if (!p->pid) { if (!p->pid) {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
p->state = reply_timeout;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid %s %s\n", hash, session_element->uuid_str); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING, "Timed out when waiting for outbound pid %s %s\n", hash, session_element->uuid_str);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER); switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return NULL; return NULL;

View File

@ -71,7 +71,6 @@ struct spawn_reply_struct
{ {
switch_thread_cond_t *ready_or_found; switch_thread_cond_t *ready_or_found;
switch_mutex_t *mutex; switch_mutex_t *mutex;
enum reply_state state;
erlang_pid *pid; erlang_pid *pid;
char *hash; char *hash;
}; };