void *val;
session_elem_t *se;
switch_hash_index_t *iter;
+ int found = 0;
ei_decode_tuple_header(buf->buff, &buf->index, &arity);
switch_hash_this(iter, &key, NULL, &val);
se = (session_elem_t*)val;
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_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));
- 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_mutex_unlock(se->spawn_reply->mutex);
- switch_thread_rwlock_unlock(listener->session_rwlock);
- return SWITCH_STATUS_SUCCESS;
- }
+ 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);
+
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);
+
+ found++;
+
break;
}
}
switch_thread_rwlock_unlock(listener->session_rwlock);
- ei_x_encode_tuple_header(rbuf, 2);
- ei_x_encode_atom(rbuf, "error");
- ei_x_encode_atom(rbuf, "notfound");
+ if (found) {
+ ei_x_encode_atom(rbuf, "ok");
+ } else {
+ ei_x_encode_tuple_header(rbuf, 2);
+ ei_x_encode_atom(rbuf, "error");
+ ei_x_encode_atom(rbuf, "notfound");
+ }
return SWITCH_STATUS_SUCCESS;
}
p = switch_core_alloc(session_element->pool, sizeof(*p));
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 = switch_core_strdup(session_element->pool, hash);
p->pid = NULL;
if (!p->pid) {
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_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return NULL;