@@ -159,6 +159,7 @@ static int run_queries(void)
159
159
int32_t timeout = 3 * MSEC_PER_SEC ;
160
160
int ret = 0 ;
161
161
int port = HTTP_PORT ;
162
+ struct http_request req ;
162
163
163
164
if (IS_ENABLED (CONFIG_NET_SOCKETS_SOCKOPT_TLS )) {
164
165
ret = tls_credential_add (CA_CERTIFICATE_TAG ,
@@ -178,21 +179,10 @@ static int run_queries(void)
178
179
(void )connect_socket (AF_INET , SERVER_ADDR4 , port ,
179
180
& sock4 , (struct sockaddr * )& addr4 ,
180
181
sizeof (addr4 ));
181
- }
182
-
183
- if (IS_ENABLED (CONFIG_NET_IPV6 )) {
184
- (void )connect_socket (AF_INET6 , SERVER_ADDR6 , port ,
185
- & sock6 , (struct sockaddr * )& addr6 ,
186
- sizeof (addr6 ));
187
- }
188
-
189
- if (sock4 < 0 && sock6 < 0 ) {
190
- LOG_ERR ("Cannot create HTTP connection." );
191
- return - ECONNABORTED ;
192
- }
193
-
194
- if (sock4 >= 0 && IS_ENABLED (CONFIG_NET_IPV4 )) {
195
- struct http_request req ;
182
+ if (sock4 < 0 ) {
183
+ LOG_ERR ("Cannot create HTTP IPv4 connection." );
184
+ return - ECONNABORTED ;
185
+ }
196
186
197
187
memset (& req , 0 , sizeof (req ));
198
188
@@ -205,12 +195,21 @@ static int run_queries(void)
205
195
req .recv_buf_len = sizeof (recv_buf_ipv4 );
206
196
207
197
ret = http_client_req (sock4 , & req , timeout , "IPv4 GET" );
198
+ if (ret < 0 ) {
199
+ LOG_ERR ("Client error %d" , ret );
200
+ }
208
201
209
202
close (sock4 );
210
203
}
211
204
212
- if (sock6 >= 0 && IS_ENABLED (CONFIG_NET_IPV6 )) {
213
- struct http_request req ;
205
+ if (IS_ENABLED (CONFIG_NET_IPV6 )) {
206
+ (void )connect_socket (AF_INET6 , SERVER_ADDR6 , port ,
207
+ & sock6 , (struct sockaddr * )& addr6 ,
208
+ sizeof (addr6 ));
209
+ if (sock6 < 0 ) {
210
+ LOG_ERR ("Cannot create HTTP IPv6 connection." );
211
+ return - ECONNABORTED ;
212
+ }
214
213
215
214
memset (& req , 0 , sizeof (req ));
216
215
@@ -223,6 +222,9 @@ static int run_queries(void)
223
222
req .recv_buf_len = sizeof (recv_buf_ipv6 );
224
223
225
224
ret = http_client_req (sock6 , & req , timeout , "IPv6 GET" );
225
+ if (ret < 0 ) {
226
+ LOG_ERR ("Client error %d" , ret );
227
+ }
226
228
227
229
close (sock6 );
228
230
}
@@ -234,21 +236,10 @@ static int run_queries(void)
234
236
(void )connect_socket (AF_INET , SERVER_ADDR4 , port ,
235
237
& sock4 , (struct sockaddr * )& addr4 ,
236
238
sizeof (addr4 ));
237
- }
238
-
239
- if (IS_ENABLED (CONFIG_NET_IPV6 )) {
240
- (void )connect_socket (AF_INET6 , SERVER_ADDR6 , port ,
241
- & sock6 , (struct sockaddr * )& addr6 ,
242
- sizeof (addr6 ));
243
- }
244
-
245
- if (sock4 < 0 && sock6 < 0 ) {
246
- LOG_ERR ("Cannot create HTTP connection." );
247
- return - ECONNABORTED ;
248
- }
249
-
250
- if (sock4 >= 0 && IS_ENABLED (CONFIG_NET_IPV4 )) {
251
- struct http_request req ;
239
+ if (sock4 < 0 ) {
240
+ LOG_ERR ("Cannot create HTTP IPv4 connection." );
241
+ return - ECONNABORTED ;
242
+ }
252
243
253
244
memset (& req , 0 , sizeof (req ));
254
245
@@ -263,12 +254,21 @@ static int run_queries(void)
263
254
req .recv_buf_len = sizeof (recv_buf_ipv4 );
264
255
265
256
ret = http_client_req (sock4 , & req , timeout , "IPv4 POST" );
257
+ if (ret < 0 ) {
258
+ LOG_ERR ("Client error %d" , ret );
259
+ }
266
260
267
261
close (sock4 );
268
262
}
269
263
270
- if (sock6 >= 0 && IS_ENABLED (CONFIG_NET_IPV6 )) {
271
- struct http_request req ;
264
+ if (IS_ENABLED (CONFIG_NET_IPV6 )) {
265
+ (void )connect_socket (AF_INET6 , SERVER_ADDR6 , port ,
266
+ & sock6 , (struct sockaddr * )& addr6 ,
267
+ sizeof (addr6 ));
268
+ if (sock6 < 0 ) {
269
+ LOG_ERR ("Cannot create HTTP IPv6 connection." );
270
+ return - ECONNABORTED ;
271
+ }
272
272
273
273
memset (& req , 0 , sizeof (req ));
274
274
@@ -283,6 +283,9 @@ static int run_queries(void)
283
283
req .recv_buf_len = sizeof (recv_buf_ipv6 );
284
284
285
285
ret = http_client_req (sock6 , & req , timeout , "IPv6 POST" );
286
+ if (ret < 0 ) {
287
+ LOG_ERR ("Client error %d" , ret );
288
+ }
286
289
287
290
close (sock6 );
288
291
}
@@ -293,29 +296,19 @@ static int run_queries(void)
293
296
sock6 = -1 ;
294
297
295
298
if (IS_ENABLED (CONFIG_NET_IPV4 )) {
296
- (void )connect_socket (AF_INET , SERVER_ADDR4 , port ,
297
- & sock4 , (struct sockaddr * )& addr4 ,
298
- sizeof (addr4 ));
299
- }
300
-
301
- if (IS_ENABLED (CONFIG_NET_IPV6 )) {
302
- (void )connect_socket (AF_INET6 , SERVER_ADDR6 , port ,
303
- & sock6 , (struct sockaddr * )& addr6 ,
304
- sizeof (addr6 ));
305
- }
306
-
307
- if (sock4 < 0 && sock6 < 0 ) {
308
- LOG_ERR ("Cannot create HTTP connection." );
309
- return - ECONNABORTED ;
310
- }
311
-
312
- if (sock4 >= 0 && IS_ENABLED (CONFIG_NET_IPV4 )) {
313
- struct http_request req ;
314
299
const char * headers [] = {
315
300
"Transfer-Encoding: chunked\r\n" ,
316
301
NULL
317
302
};
318
303
304
+ (void )connect_socket (AF_INET , SERVER_ADDR4 , port ,
305
+ & sock4 , (struct sockaddr * )& addr4 ,
306
+ sizeof (addr4 ));
307
+ if (sock4 < 0 ) {
308
+ LOG_ERR ("Cannot create HTTP IPv4 connection." );
309
+ return - ECONNABORTED ;
310
+ }
311
+
319
312
memset (& req , 0 , sizeof (req ));
320
313
321
314
req .method = HTTP_POST ;
@@ -329,17 +322,27 @@ static int run_queries(void)
329
322
req .recv_buf_len = sizeof (recv_buf_ipv4 );
330
323
331
324
ret = http_client_req (sock4 , & req , timeout , "IPv4 POST" );
325
+ if (ret < 0 ) {
326
+ LOG_ERR ("Client error %d" , ret );
327
+ }
332
328
333
329
close (sock4 );
334
330
}
335
331
336
- if (sock6 >= 0 && IS_ENABLED (CONFIG_NET_IPV6 )) {
337
- struct http_request req ;
332
+ if (IS_ENABLED (CONFIG_NET_IPV6 )) {
338
333
const char * headers [] = {
339
334
"Transfer-Encoding: chunked\r\n" ,
340
335
NULL
341
336
};
342
337
338
+ (void )connect_socket (AF_INET6 , SERVER_ADDR6 , port ,
339
+ & sock6 , (struct sockaddr * )& addr6 ,
340
+ sizeof (addr6 ));
341
+ if (sock6 < 0 ) {
342
+ LOG_ERR ("Cannot create HTTP IPv6 connection." );
343
+ return - ECONNABORTED ;
344
+ }
345
+
343
346
memset (& req , 0 , sizeof (req ));
344
347
345
348
req .method = HTTP_POST ;
@@ -353,6 +356,9 @@ static int run_queries(void)
353
356
req .recv_buf_len = sizeof (recv_buf_ipv6 );
354
357
355
358
ret = http_client_req (sock6 , & req , timeout , "IPv6 POST" );
359
+ if (ret < 0 ) {
360
+ LOG_ERR ("Client error %d" , ret );
361
+ }
356
362
357
363
close (sock6 );
358
364
}
0 commit comments