summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-12-28 17:43:26 +0800
committer刘学利 <[email protected]>2023-12-28 12:46:51 +0000
commitc131eeda82a32b0db6f4dc56adcc5e5d6815c9fb (patch)
treea4a975b9a345d1fdf639f88deecdea8101195993 /examples
parenta9afd24fafcf867b6fa272e6651c41dac5407567 (diff)
✨ feat(session event dispatch): update dispatch logic and add examplev1.0.8
Diffstat (limited to 'examples')
-rw-r--r--examples/sapp_plugin/publisher_loader.c3
-rw-r--r--examples/stellar_plugin/simple_stellar_plugin.c18
2 files changed, 21 insertions, 0 deletions
diff --git a/examples/sapp_plugin/publisher_loader.c b/examples/sapp_plugin/publisher_loader.c
index d2db719..0003680 100644
--- a/examples/sapp_plugin/publisher_loader.c
+++ b/examples/sapp_plugin/publisher_loader.c
@@ -110,6 +110,7 @@ static unsigned char loader_transfer_stream_entry(struct streaminfo *pstream, UC
case OP_STATE_PENDING:
ctx->sess=adapter_session_new(g_stellar, pstream);
entry_ret=adapter_session_state_update(pstream, ctx->sess, a_packet, SESSION_STATE_OPENING);
+ adapter_session_poll(ctx->sess);
break;
case OP_STATE_DATA:
msg = stream_ctx_dup((const struct simple_stream_ctx *)*pme);
@@ -118,9 +119,11 @@ static unsigned char loader_transfer_stream_entry(struct streaminfo *pstream, UC
FREE(msg);
}
entry_ret=adapter_session_state_update(pstream, ctx->sess, a_packet, SESSION_STATE_ACTIVE);
+ adapter_session_poll(ctx->sess);
break;
case OP_STATE_CLOSE:
entry_ret=adapter_session_state_update(pstream, ctx->sess, a_packet, SESSION_STATE_CLOSING);
+ adapter_session_poll(ctx->sess);
adapter_session_free(ctx->sess);
print_stream_ctx(pstream, ctx);
FREE(*pme);
diff --git a/examples/stellar_plugin/simple_stellar_plugin.c b/examples/stellar_plugin/simple_stellar_plugin.c
index 7e8b7ee..50f38f0 100644
--- a/examples/stellar_plugin/simple_stellar_plugin.c
+++ b/examples/stellar_plugin/simple_stellar_plugin.c
@@ -18,6 +18,7 @@ struct mq_message_stat
uint32_t c2s_bytes;
uint32_t s2c_pkts;
uint32_t s2c_bytes;
+ struct session_event* ud_ev;
};
extern int simple_mq_plugin_entry(struct session *sess, int events, const struct packet *pkt, void *cb_arg);
@@ -51,6 +52,16 @@ static void print_session_ctx(struct session *sess, struct mq_message_stat *ctx,
return;
}
+int simple_event_plugin_user_defined_ev(struct session *sess, int events, const struct packet *pkt, void *cb_arg)
+{
+ if(cb_arg == NULL)return -1;
+ struct simple_stellar_plugin_ctx *plugin_ctx=(struct simple_stellar_plugin_ctx *)cb_arg;
+ struct mq_message_stat *mg_stat = (struct mq_message_stat *)session_get_ex_data(sess, plugin_ctx->exdata_idx);
+ printf("%s(plug:%d)trigger-----------%20s\n", __FUNCTION__, plugin_ctx->plugin_id, session_get0_readable_addr(sess));
+ print_session_ctx(sess, mg_stat, plugin_ctx->plugin_id);
+ return 0;
+}
+
int simple_event_plugin_entry(struct session *sess, int events, const struct packet *pkt, void *cb_arg)
{
if(cb_arg == NULL)return -1;
@@ -62,6 +73,12 @@ int simple_event_plugin_entry(struct session *sess, int events, const struct pac
session_set_ex_data(sess, plugin_ctx->exdata_idx, mg_stat);
}
+ if ((events & SESS_EV_OPENING))
+ {
+ mg_stat->ud_ev=session_event_new(plugin_ctx->st, sess, (SESS_EV_TCP|SESS_EV_UDP|SESS_EV_OPENING|SESS_EV_PACKET|SESS_EV_CLOSING), simple_event_plugin_user_defined_ev, cb_arg);
+ session_event_add(mg_stat->ud_ev, NULL);
+ }
+
if (pkt)
{
size_t payload_len = 0;
@@ -81,6 +98,7 @@ int simple_event_plugin_entry(struct session *sess, int events, const struct pac
if (mg_stat != NULL && (events & SESS_EV_CLOSING))
{
print_session_ctx(sess, mg_stat, plugin_ctx->plugin_id);
+ session_event_free(mg_stat->ud_ev);
}
return 0;
}