MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / tcp_client_entry

Function tcp_client_entry

components/net/utest/tc_lwip.c:104–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104static void tcp_client_entry(void *parameter)
105{
106#define LWIP_TCP_TEST_BUF_SIZE 2048
107
108 rt_tick_t old_tick = 0;
109 rt_bool_t fail_flag = RT_TRUE;
110 int sock = -1, mode, port, ret, i, flag;
111 struct sockaddr_in server_addr;
112 char *send_buf = RT_NULL;
113 char *recv_buf = RT_NULL;
114
115 port = RT_UTEST_LWIP_TCP_PORT;
116
117 /* create socket */
118 if ((sock = lwip_socket(AF_INET, SOCK_STREAM, 0)) == -1)
119 {
120 uassert_true(RT_FALSE);
121 goto __exit;
122 }
123 else
124 {
125 uassert_true(RT_TRUE);
126 }
127
128 /* Set no-blocking mode */
129 flag = lwip_fcntl(sock, F_GETFL, 0);
130 lwip_fcntl(sock, F_SETFL, flag | O_NONBLOCK);
131 flag = lwip_fcntl(sock, F_GETFL, 0);
132 uassert_true(flag & O_NONBLOCK);
133
134 /* Set blocking mode */
135 mode = 0;
136 lwip_ioctl(sock, FIONBIO, &mode);
137
138 server_addr.sin_family = AF_INET;
139 server_addr.sin_port = htons(port);
140 /* server addr:127.0.0.1 */
141 server_addr.sin_addr.s_addr = htonl(IPADDR_LOOPBACK);
142 rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
143
144 old_tick = rt_tick_get();
145 /* connect to server */
146 while (1)
147 {
148 if (lwip_connect(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
149 {
150 /* timeout: 5s */
151 if (rt_tick_get() - old_tick > 5 * RT_TICK_PER_SECOND)
152 {
153 rt_kprintf("TCP client connect timeout\n");
154 uassert_true(RT_FALSE);
155 goto __exit;
156 }
157 else
158 {
159 rt_thread_mdelay(RT_TICK_PER_SECOND);
160 continue;
161 }

Callers

nothing calls this directly

Calls 15

rt_memsetFunction · 0.85
rt_tick_getFunction · 0.85
rt_kprintfFunction · 0.85
rt_thread_mdelayFunction · 0.85
rt_mallocFunction · 0.85
rt_memcmpFunction · 0.85
rt_event_sendFunction · 0.85
rt_freeFunction · 0.85
lwip_socketFunction · 0.50
lwip_fcntlFunction · 0.50
lwip_ioctlFunction · 0.50
lwip_connectFunction · 0.50

Tested by

no test coverage detected