1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#include <pthread.h>
#include "lwip/memp.h"
#include "lwip/mem.h"
#include "arch/queue.h"
#include "lwip/sys.h"
#include "nstack_log.h"
#include "lwip/sockets.h"
#include "stackx_spl_share.h"
#include "lwip/api.h"
#include "lwip/ip.h"
#include <netif/sc_dpdk.h>
err_t
queue_push (queue_t * q, void *pmsg, int isTrypush)
{
int pushRet;
// struct tcpip_msg* _msg = pmsg;
//enum tcpip_msg_type tcpip_type = TCPIP_MSG_MAX;
//struct new_api_msg* lo_newapimsg = NULL;
// enum api_msg_type api_type = NEW_MSG_API_MAX;
// struct netconn *lo_conn = NULL;
//u64_t tcp_tx_bytes = 0;
while (1)
{
pushRet = nsfw_mem_ring_enqueue (q->llring, pmsg);
switch (pushRet)
{
case -1:
NSSOC_LOGERR ("Box range check has failed]llring_a=%p, msg=%p",
q->llring, pmsg);
return ERR_MEM;
case 1:
return ERR_OK;
default:
if (isTrypush)
{
return ERR_MEM;
}
else
{
continue;
}
}
}
}
void *
queue_pop (queue_t * q, u32_t * timeout, int isTryPop)
{
void *pmsg;
int popRet;
int retVal;
u32_t ellapsetime = 0;
// struct tcpip_msg* _msg;
struct timespec starttm = { 0 };
struct timespec endtm;
u32_t timeDiff;
if (*timeout != 0)
{
retVal = clock_gettime (CLOCK_MONOTONIC, &starttm);
if (0 != retVal)
{
NSPOL_LOGERR ("clock_gettime() failed]");
*timeout = SYS_ARCH_TIMEOUT;
return NULL;
}
}
while (1)
{
//TODO:May have to consider, take out the data sharing problem
popRet = nsfw_mem_ring_dequeue (q->llring, &pmsg);
switch (popRet)
{
case 1:
*timeout = ellapsetime;
return pmsg;
default:
if (isTryPop)
{
*timeout = SYS_ARCH_TIMEOUT;
return NULL;
}
else
{
if (*timeout != 0)
{
retVal = clock_gettime (CLOCK_MONOTONIC, &endtm);
if (0 != retVal)
{
NSPOL_LOGERR ("clock_gettime() failed]");
*timeout = SYS_ARCH_TIMEOUT;
return NULL;
}
timeDiff = endtm.tv_sec - starttm.tv_sec;
if (timeDiff > *timeout)
{
*timeout = SYS_ARCH_TIMEOUT;
return NULL;
}
sys_sleep_ns (0, 100000);
}
continue;
}
}
}
}
|