@@ -58,17 +58,25 @@ extern "C" {
58
58
*/
59
59
60
60
/* Flags for netconn_write (u8_t) */
61
- #define NETCONN_NOFLAG 0x00
62
- #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
63
- #define NETCONN_COPY 0x01
64
- #define NETCONN_MORE 0x02
65
- #define NETCONN_DONTBLOCK 0x04
61
+ #define NETCONN_NOFLAG 0x00
62
+ #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
63
+ #define NETCONN_COPY 0x01
64
+ #define NETCONN_MORE 0x02
65
+ #define NETCONN_DONTBLOCK 0x04
66
+ #define NETCONN_NOAUTORCVD 0x08 /* prevent netconn_recv_data_tcp() from updating the tcp window - must be done manually via netconn_tcp_recvd() */
67
+ #define NETCONN_NOFIN 0x10 /* upper layer already received data, leave FIN in queue until called again */
66
68
67
69
/* Flags for struct netconn.flags (u8_t) */
70
+ /** This netconn had an error, don't block on recvmbox/acceptmbox any more */
71
+ #define NETCONN_FLAG_MBOXCLOSED 0x01
68
72
/** Should this netconn avoid blocking? */
69
73
#define NETCONN_FLAG_NON_BLOCKING 0x02
70
74
/** Was the last connect action a non-blocking one? */
71
75
#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
76
+ #if LWIP_NETCONN_FULLDUPLEX
77
+ /** The mbox of this netconn is being deallocated, don't use it anymore */
78
+ #define NETCONN_FLAG_MBOXINVALID 0x08
79
+ #endif /* LWIP_NETCONN_FULLDUPLEX */
72
80
/** If a nonblocking write has been rejected before, poll_tcp needs to
73
81
check if the netconn is writable again */
74
82
#define NETCONN_FLAG_CHECK_WRITESPACE 0x10
@@ -78,7 +86,12 @@ extern "C" {
78
86
dual-stack usage by default. */
79
87
#define NETCONN_FLAG_IPV6_V6ONLY 0x20
80
88
#endif /* LWIP_IPV6 */
81
-
89
+ #if LWIP_NETBUF_RECVINFO
90
+ /** Received packet info will be recorded for this netconn */
91
+ #define NETCONN_FLAG_PKTINFO 0x40
92
+ #endif /* LWIP_NETBUF_RECVINFO */
93
+ /** A FIN has been received but not passed to the application yet */
94
+ #define NETCONN_FIN_RX_PENDING 0x80
82
95
83
96
/* Helpers to process several netconn_types by the same code */
84
97
#define NETCONNTYPE_GROUP (t ) ((t)&0xF0)
@@ -214,8 +227,8 @@ struct netconn {
214
227
struct udp_pcb * udp ;
215
228
struct raw_pcb * raw ;
216
229
} pcb ;
217
- /** the last error this netconn had */
218
- err_t last_err ;
230
+ /** the last asynchronous unreported error this netconn had */
231
+ err_t pending_err ;
219
232
#if !LWIP_NETCONN_SEM_PER_THREAD
220
233
/** sem that is used to synchronously execute functions in the core context */
221
234
sys_sem_t op_completed ;
@@ -228,6 +241,11 @@ struct netconn {
228
241
by the application thread */
229
242
sys_mbox_t acceptmbox ;
230
243
#endif /* LWIP_TCP */
244
+ #if LWIP_NETCONN_FULLDUPLEX
245
+ /** number of threads waiting on an mbox. This is required to unblock
246
+ all threads when closing while threads are waiting. */
247
+ int mbox_threads_waiting ;
248
+ #endif
231
249
/** only used for socket layer */
232
250
#if LWIP_SOCKET
233
251
int socket ;
@@ -240,7 +258,7 @@ struct netconn {
240
258
#if LWIP_SO_RCVTIMEO
241
259
/** timeout in milliseconds to wait for new data to be received
242
260
(or connections to arrive for listening netconns) */
243
- int recv_timeout ;
261
+ u32_t recv_timeout ;
244
262
#endif /* LWIP_SO_RCVTIMEO */
245
263
#if LWIP_SO_RCVBUF
246
264
/** maximum amount of bytes queued in recvmbox
@@ -258,9 +276,6 @@ struct netconn {
258
276
/** flags holding more netconn-internal state, see NETCONN_FLAG_* defines */
259
277
u8_t flags ;
260
278
#if LWIP_TCP
261
- /** TCP: when data passed to netconn_write doesn't fit into the send buffer,
262
- this temporarily stores how much is already sent. */
263
- size_t write_offset ;
264
279
/** TCP: when data passed to netconn_write doesn't fit into the send buffer,
265
280
this temporarily stores the message.
266
281
Also used during connect and close. */
@@ -270,21 +285,23 @@ struct netconn {
270
285
netconn_callback callback ;
271
286
};
272
287
288
+ /** This vector type is passed to @ref netconn_write_vectors_partly to send
289
+ * multiple buffers at once.
290
+ * ATTENTION: This type has to directly map struct iovec since one is casted
291
+ * into the other!
292
+ */
293
+ struct netvector {
294
+ /** pointer to the application buffer that contains the data to send */
295
+ const void * ptr ;
296
+ /** size of the application data to send */
297
+ size_t len ;
298
+ };
299
+
273
300
/** Register an Network connection event */
274
301
#define API_EVENT (c ,e ,l ) if (c->callback) { \
275
302
(*c->callback)(c, e, l); \
276
303
}
277
304
278
- /** Set conn->last_err to err but don't overwrite fatal errors */
279
- #define NETCONN_SET_SAFE_ERR (conn , err ) do { if ((conn) != NULL) { \
280
- SYS_ARCH_DECL_PROTECT(netconn_set_safe_err_lev); \
281
- SYS_ARCH_PROTECT(netconn_set_safe_err_lev); \
282
- if (!ERR_IS_FATAL((conn)->last_err)) { \
283
- (conn)->last_err = err; \
284
- } \
285
- SYS_ARCH_UNPROTECT(netconn_set_safe_err_lev); \
286
- }} while(0);
287
-
288
305
/* Network connection functions: */
289
306
290
307
/** @ingroup netconn_common
@@ -294,6 +311,7 @@ struct netconn {
294
311
#define netconn_new_with_callback (t , c ) netconn_new_with_proto_and_callback(t, 0, c)
295
312
struct netconn * netconn_new_with_proto_and_callback (enum netconn_type t , u8_t proto ,
296
313
netconn_callback callback );
314
+ err_t netconn_prepare_delete (struct netconn * conn );
297
315
err_t netconn_delete (struct netconn * conn );
298
316
/** Get the type of a netconn (as enum netconn_type). */
299
317
#define netconn_type (conn ) (conn->type)
@@ -306,19 +324,26 @@ err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
306
324
#define netconn_addr (c ,i ,p ) netconn_getaddr(c,i,p,1)
307
325
308
326
err_t netconn_bind (struct netconn * conn , const ip_addr_t * addr , u16_t port );
327
+ err_t netconn_bind_if (struct netconn * conn , u8_t if_idx );
309
328
err_t netconn_connect (struct netconn * conn , const ip_addr_t * addr , u16_t port );
310
329
err_t netconn_disconnect (struct netconn * conn );
311
330
err_t netconn_listen_with_backlog (struct netconn * conn , u8_t backlog );
312
331
/** @ingroup netconn_tcp */
313
332
#define netconn_listen (conn ) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
314
333
err_t netconn_accept (struct netconn * conn , struct netconn * * new_conn );
315
334
err_t netconn_recv (struct netconn * conn , struct netbuf * * new_buf );
335
+ err_t netconn_recv_udp_raw_netbuf (struct netconn * conn , struct netbuf * * new_buf );
336
+ err_t netconn_recv_udp_raw_netbuf_flags (struct netconn * conn , struct netbuf * * new_buf , u8_t apiflags );
316
337
err_t netconn_recv_tcp_pbuf (struct netconn * conn , struct pbuf * * new_buf );
338
+ err_t netconn_recv_tcp_pbuf_flags (struct netconn * conn , struct pbuf * * new_buf , u8_t apiflags );
339
+ err_t netconn_tcp_recvd (struct netconn * conn , size_t len );
317
340
err_t netconn_sendto (struct netconn * conn , struct netbuf * buf ,
318
341
const ip_addr_t * addr , u16_t port );
319
342
err_t netconn_send (struct netconn * conn , struct netbuf * buf );
320
343
err_t netconn_write_partly (struct netconn * conn , const void * dataptr , size_t size ,
321
344
u8_t apiflags , size_t * bytes_written );
345
+ err_t netconn_write_vectors_partly (struct netconn * conn , struct netvector * vectors , u16_t vectorcnt ,
346
+ u8_t apiflags , size_t * bytes_written );
322
347
/** @ingroup netconn_tcp */
323
348
#define netconn_write (conn , dataptr , size , apiflags ) \
324
349
netconn_write_partly(conn, dataptr, size, apiflags, NULL)
@@ -328,6 +353,8 @@ err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
328
353
#if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD )
329
354
err_t netconn_join_leave_group (struct netconn * conn , const ip_addr_t * multiaddr ,
330
355
const ip_addr_t * netif_addr , enum netconn_igmp join_or_leave );
356
+ err_t netconn_join_leave_group_netif (struct netconn * conn , const ip_addr_t * multiaddr ,
357
+ u8_t if_idx , enum netconn_igmp join_or_leave );
331
358
#endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
332
359
#if LWIP_DNS
333
360
#if LWIP_IPV4 && LWIP_IPV6
@@ -339,14 +366,18 @@ err_t netconn_gethostbyname(const char *name, ip_addr_t *addr);
339
366
#endif /* LWIP_IPV4 && LWIP_IPV6 */
340
367
#endif /* LWIP_DNS */
341
368
342
- #define netconn_err (conn ) (( conn)->last_err)
369
+ err_t netconn_err (struct netconn * conn );
343
370
#define netconn_recv_bufsize (conn ) ((conn)->recv_bufsize)
344
371
372
+ #define netconn_set_flags (conn , set_flags ) do { (conn)->flags = (u8_t)((conn)->flags | (set_flags)); } while(0)
373
+ #define netconn_clear_flags (conn , clr_flags ) do { (conn)->flags = (u8_t)((conn)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
374
+ #define netconn_is_flag_set (conn , flag ) (((conn)->flags & (flag)) != 0)
375
+
345
376
/** Set the blocking status of netconn calls (@todo: write/send is missing) */
346
377
#define netconn_set_nonblocking (conn , val ) do { if(val) { \
347
- (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
378
+ netconn_set_flags (conn, NETCONN_FLAG_NON_BLOCKING) ; \
348
379
} else { \
349
- (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
380
+ netconn_clear_flags (conn, NETCONN_FLAG_NON_BLOCKING) ; }} while(0)
350
381
/** Get the blocking status of netconn calls (@todo: write/send is missing) */
351
382
#define netconn_is_nonblocking (conn ) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
352
383
@@ -355,9 +386,9 @@ err_t netconn_gethostbyname(const char *name, ip_addr_t *addr);
355
386
* TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY)
356
387
*/
357
388
#define netconn_set_ipv6only (conn , val ) do { if(val) { \
358
- (conn)->flags |= NETCONN_FLAG_IPV6_V6ONLY; \
389
+ netconn_set_flags (conn, NETCONN_FLAG_IPV6_V6ONLY) ; \
359
390
} else { \
360
- (conn)->flags &= ~ NETCONN_FLAG_IPV6_V6ONLY; }} while(0)
391
+ netconn_clear_flags (conn, NETCONN_FLAG_IPV6_V6ONLY) ; }} while(0)
361
392
/** @ingroup netconn_common
362
393
* TCP: Get the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY)
363
394
*/
0 commit comments