@@ -225,11 +225,21 @@ static void zsock_received_cb(struct net_context *ctx,
225
225
int status ,
226
226
void * user_data )
227
227
{
228
+ if (sock_is_eof (ctx )) {
229
+ /* If receiving is not desired and socket is shutdown,
230
+ * ignore all incoming data.
231
+ */
232
+ NET_DBG ("%sctx=%p, pkt=%p, st=%d, user_data=%p" ,
233
+ "DROP: " , ctx , pkt , status , user_data );
234
+ net_pkt_unref (pkt );
235
+ return ;
236
+ }
237
+
228
238
if (ctx -> cond .lock ) {
229
239
(void )k_mutex_lock (ctx -> cond .lock , K_FOREVER );
230
240
}
231
241
232
- NET_DBG ("ctx =%p, pkt=%p, st=%d, user_data=%p" , ctx , pkt , status ,
242
+ NET_DBG ("%sctx =%p, pkt=%p, st=%d, user_data=%p" , " " , ctx , pkt , status ,
233
243
user_data );
234
244
235
245
if (status < 0 ) {
@@ -363,12 +373,16 @@ int zsock_connect_ctx(struct net_context *ctx, const struct sockaddr *addr,
363
373
errno = - ret ;
364
374
return -1 ;
365
375
}
366
- ret = net_context_recv (ctx , zsock_received_cb ,
367
- K_NO_WAIT , ctx -> user_data );
368
- if (ret < 0 ) {
369
- errno = - ret ;
370
- return -1 ;
376
+
377
+ if (!sock_is_eof (ctx )) {
378
+ ret = net_context_recv (ctx , zsock_received_cb ,
379
+ K_NO_WAIT , ctx -> user_data );
380
+ if (ret < 0 ) {
381
+ errno = - ret ;
382
+ return -1 ;
383
+ }
371
384
}
385
+
372
386
return 0 ;
373
387
}
374
388
#endif
@@ -416,11 +430,14 @@ int zsock_connect_ctx(struct net_context *ctx, const struct sockaddr *addr,
416
430
errno = - ret ;
417
431
return -1 ;
418
432
}
419
- ret = net_context_recv (ctx , zsock_received_cb ,
420
- K_NO_WAIT , ctx -> user_data );
421
- if (ret < 0 ) {
422
- errno = - ret ;
423
- return -1 ;
433
+
434
+ if (!sock_is_eof (ctx )) {
435
+ ret = net_context_recv (ctx , zsock_received_cb ,
436
+ K_NO_WAIT , ctx -> user_data );
437
+ if (ret < 0 ) {
438
+ errno = - ret ;
439
+ return -1 ;
440
+ }
424
441
}
425
442
}
426
443
@@ -643,11 +660,13 @@ ssize_t zsock_sendto_ctx(struct net_context *ctx, const void *buf, size_t len,
643
660
/* Register the callback before sending in order to receive the response
644
661
* from the peer.
645
662
*/
646
- status = net_context_recv (ctx , zsock_received_cb ,
647
- K_NO_WAIT , ctx -> user_data );
648
- if (status < 0 ) {
649
- errno = - status ;
650
- return -1 ;
663
+ if (!sock_is_eof (ctx )) {
664
+ status = net_context_recv (ctx , zsock_received_cb ,
665
+ K_NO_WAIT , ctx -> user_data );
666
+ if (status < 0 ) {
667
+ errno = - status ;
668
+ return -1 ;
669
+ }
651
670
}
652
671
653
672
while (1 ) {
0 commit comments