summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-09-08 12:07:51 +0800
committeryangwei <[email protected]>2023-09-08 12:07:51 +0800
commitaf3ae06cd6fa98349d2ed9753d54f4f3f1683681 (patch)
treee3793cb22ed02e6b3af9a7c8a1f1d7b436972457
parentd2d1106ab0637217462bc3cca3041bbfdf9709cf (diff)
✨ feat(packet_arrive_time): get arrived timestamp from packet
-rw-r--r--include/stellar/session.h1
-rw-r--r--src/adapter/adapter.c14
2 files changed, 13 insertions, 2 deletions
diff --git a/include/stellar/session.h b/include/stellar/session.h
index 0f5e15c..ca78423 100644
--- a/include/stellar/session.h
+++ b/include/stellar/session.h
@@ -97,6 +97,7 @@ const struct packet *session_get0_current_packet(struct session *sess);
#define PACKET_DIRECTION_S2C 1
int packet_get_direction(const struct packet *pkt);
const char *packet_get0_data(const struct packet *pkt, size_t *data_len);
+int packet_arrive_time(const struct packet *pkt, struct timeval *ts);
#define SESS_EV_OPENING 1<<1
#define SESS_EV_PACKET 1<<2
diff --git a/src/adapter/adapter.c b/src/adapter/adapter.c
index 806f94e..fdddc9a 100644
--- a/src/adapter/adapter.c
+++ b/src/adapter/adapter.c
@@ -270,8 +270,8 @@ const char *packet_get0_data(const struct packet *pkt, size_t *data_len)
{
const void *raw_data=NULL;
int raw_datalen=0;
- int ret1 = get_opt_from_rawpkt(pkt, RAW_PKT_GET_DATA, &raw_data);
- int ret2 = get_opt_from_rawpkt(pkt, RAW_PKT_GET_TOT_LEN, &raw_datalen);
+ int ret1 = get_opt_from_rawpkt(pkt->a_packet, RAW_PKT_GET_DATA, &raw_data);
+ int ret2 = get_opt_from_rawpkt(pkt->a_packet, RAW_PKT_GET_TOT_LEN, &raw_datalen);
if(ret1 >= 0 || ret2 >= 0)
{
*data_len = raw_datalen;
@@ -372,4 +372,14 @@ int stellar_get_worker_thread_num(struct stellar *st)
int stellar_get_current_thread_id(struct stellar *st)
{
return get_current_worker_thread_id();
+}
+
+int packet_arrive_time(const struct packet *pkt, struct timeval *ts)
+{
+ if(pkt == NULL || ts == NULL)return -1;
+ if(pkt->a_packet == NULL || pkt->a_stream == NULL)return -1;
+
+ get_opt_from_rawpkt(pkt->a_packet , RAW_PKT_GET_TIMESTAMP, &ts);
+ if(ts->tv_sec == 0 && ts->tv_usec == 0)return -1;
+ return 0;
} \ No newline at end of file