提交 8f4c5bc4 authored 作者: Tamas Cseke's avatar Tamas Cseke

add Andrew's patch from FS-3432 as a starting point with todo markers

上级 fbcb8622
...@@ -286,6 +286,7 @@ static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_bu ...@@ -286,6 +286,7 @@ static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_bu
switch_set_flag_locked(listener, LFLAG_EVENTS); switch_set_flag_locked(listener, LFLAG_EVENTS);
} }
/* TODO - listener write lock */
for (i = 1; i < arity; i++) { for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
...@@ -335,6 +336,7 @@ static switch_status_t handle_msg_session_event(listener_t *listener, erlang_msg ...@@ -335,6 +336,7 @@ static switch_status_t handle_msg_session_event(listener_t *listener, erlang_msg
for (i = 1; i < arity; i++) { for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
/* TODO session write locking */
if (custom) { if (custom) {
switch_core_hash_insert(session->event_hash, atom, MARKER); switch_core_hash_insert(session->event_hash, atom, MARKER);
} else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) { } else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
...@@ -380,10 +382,12 @@ static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x ...@@ -380,10 +382,12 @@ static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x
int i = 0; int i = 0;
switch_event_types_t type; switch_event_types_t type;
/* TODO listener write lock */
for (i = 1; i < arity; i++) { for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
if (custom) { if (custom) {
switch_core_hash_delete(listener->event_hash, atom); switch_core_hash_delete(listener->event_hash, atom);
} else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) { } else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
uint32_t x = 0; uint32_t x = 0;
...@@ -426,6 +430,7 @@ static switch_status_t handle_msg_session_nixevent(listener_t *listener, erlang_ ...@@ -426,6 +430,7 @@ static switch_status_t handle_msg_session_nixevent(listener_t *listener, erlang_
int i = 0; int i = 0;
switch_event_types_t type; switch_event_types_t type;
/* TODO session write lock */
for (i = 1; i < arity; i++) { for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) { if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
...@@ -480,6 +485,8 @@ static switch_status_t handle_msg_setevent(listener_t *listener, erlang_msg *msg ...@@ -480,6 +485,8 @@ static switch_status_t handle_msg_setevent(listener_t *listener, erlang_msg *msg
switch_event_types_t type; switch_event_types_t type;
int i = 0; int i = 0;
/* TODO listener write lock */
/* clear any previous event registrations */ /* clear any previous event registrations */
for( x = 0; x <= SWITCH_EVENT_ALL; x++){ for( x = 0; x <= SWITCH_EVENT_ALL; x++){
event_list[x] = 0; event_list[x] = 0;
...@@ -517,6 +524,7 @@ static switch_status_t handle_msg_setevent(listener_t *listener, erlang_msg *msg ...@@ -517,6 +524,7 @@ static switch_status_t handle_msg_setevent(listener_t *listener, erlang_msg *msg
/* update the event subscriptions with the new ones */ /* update the event subscriptions with the new ones */
memcpy(listener->event_list, event_list, sizeof(uint8_t) * (SWITCH_EVENT_ALL + 1)); memcpy(listener->event_list, event_list, sizeof(uint8_t) * (SWITCH_EVENT_ALL + 1));
/* wipe the old hash, and point the pointer at the new one */ /* wipe the old hash, and point the pointer at the new one */
/* TODO make thread safe */
switch_core_hash_destroy(&listener->event_hash); switch_core_hash_destroy(&listener->event_hash);
listener->event_hash = event_hash; listener->event_hash = event_hash;
...@@ -544,12 +552,14 @@ static switch_status_t handle_msg_session_setevent(listener_t *listener, erlang_ ...@@ -544,12 +552,14 @@ static switch_status_t handle_msg_session_setevent(listener_t *listener, erlang_
switch_event_types_t type; switch_event_types_t type;
uint32_t x = 0; uint32_t x = 0;
/* TODO session write lock */
/* clear any previous event registrations */ /* clear any previous event registrations */
for (x = 0; x <= SWITCH_EVENT_ALL; x++){ for (x = 0; x <= SWITCH_EVENT_ALL; x++){
event_list[x] = 0; event_list[x] = 0;
} }
/* create new hash */ /* create new hash */
/* TODO make thread safe*/
switch_core_hash_init(&event_hash, session->pool); switch_core_hash_init(&event_hash, session->pool);
for (i = 1; i < arity; i++){ for (i = 1; i < arity; i++){
...@@ -576,6 +586,7 @@ static switch_status_t handle_msg_session_setevent(listener_t *listener, erlang_ ...@@ -576,6 +586,7 @@ static switch_status_t handle_msg_session_setevent(listener_t *listener, erlang_
/* update the event subscriptions with the new ones */ /* update the event subscriptions with the new ones */
memcpy(session->event_list, event_list, sizeof(uint8_t) * (SWITCH_EVENT_ALL + 1)); memcpy(session->event_list, event_list, sizeof(uint8_t) * (SWITCH_EVENT_ALL + 1));
/* wipe the old hash, and point the pointer at the new one */ /* wipe the old hash, and point the pointer at the new one */
/* TODO make thread safe*/
switch_core_hash_destroy(&session->event_hash); switch_core_hash_destroy(&session->event_hash);
session->event_hash = event_hash; session->event_hash = event_hash;
/* TODO - we should flush any non-matching events from the queue */ /* TODO - we should flush any non-matching events from the queue */
...@@ -1024,6 +1035,7 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e ...@@ -1024,6 +1035,7 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e
listener->event_list[x] = 0; listener->event_list[x] = 0;
} }
/* wipe the hash */ /* wipe the hash */
/* TODO make thread safe*/
switch_core_hash_destroy(&listener->event_hash); switch_core_hash_destroy(&listener->event_hash);
switch_core_hash_init(&listener->event_hash, listener->pool); switch_core_hash_init(&listener->event_hash, listener->pool);
ei_x_encode_atom(rbuf, "ok"); ei_x_encode_atom(rbuf, "ok");
...@@ -1044,6 +1056,7 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e ...@@ -1044,6 +1056,7 @@ static switch_status_t handle_msg_atom(listener_t *listener, erlang_msg * msg, e
session->event_list[x] = 0; session->event_list[x] = 0;
} }
/* wipe the hash */ /* wipe the hash */
/* TODO make thread safe*/
switch_core_hash_destroy(&session->event_hash); switch_core_hash_destroy(&session->event_hash);
switch_core_hash_init(&session->event_hash, session->pool); switch_core_hash_init(&session->event_hash, session->pool);
ei_x_encode_atom(rbuf, "ok"); ei_x_encode_atom(rbuf, "ok");
...@@ -1240,6 +1253,7 @@ int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buf ...@@ -1240,6 +1253,7 @@ int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buf
buf->index = 0; buf->index = 0;
ei_decode_version(buf->buff, &buf->index, &version); ei_decode_version(buf->buff, &buf->index, &version);
ei_get_type(buf->buff, &buf->index, &type, &size); ei_get_type(buf->buff, &buf->index, &type, &size);
switch (type) { switch (type) {
case ERL_SMALL_TUPLE_EXT: case ERL_SMALL_TUPLE_EXT:
case ERL_LARGE_TUPLE_EXT: case ERL_LARGE_TUPLE_EXT:
...@@ -1288,11 +1302,8 @@ int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buf ...@@ -1288,11 +1302,8 @@ int handle_msg(listener_t *listener, erlang_msg * msg, ei_x_buff * buf, ei_x_buf
#ifdef EI_DEBUG #ifdef EI_DEBUG
ei_x_print_msg(rbuf, &msg->from, 1); ei_x_print_msg(rbuf, &msg->from, 1);
#endif #endif
return SWITCH_STATUS_SUCCESS != ret;
if (SWITCH_STATUS_SUCCESS == ret)
return 0;
else /* SWITCH_STATUS_TERM */
return 1;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Empty reply, supressing\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Empty reply, supressing\n");
return 0; return 0;
......
...@@ -39,7 +39,8 @@ typedef enum { ...@@ -39,7 +39,8 @@ typedef enum {
} session_flag_t; } session_flag_t;
typedef enum { typedef enum {
ERLANG_PID = 0, NONE = 0,
ERLANG_PID,
ERLANG_REG_PROCESS ERLANG_REG_PROCESS
} process_type; } process_type;
...@@ -113,6 +114,7 @@ struct listener { ...@@ -113,6 +114,7 @@ struct listener {
#else #else
int sockfd; int sockfd;
#endif #endif
uint8_t dead;
struct ei_cnode_s *ec; struct ei_cnode_s *ec;
struct erlang_process log_process; struct erlang_process log_process;
struct erlang_process event_process; struct erlang_process event_process;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论