Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of lwip by
api_msg.h
00001 /* 00002 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright notice, 00011 * this list of conditions and the following disclaimer in the documentation 00012 * and/or other materials provided with the distribution. 00013 * 3. The name of the author may not be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00017 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00018 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00019 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00020 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00021 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00022 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00023 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00024 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00025 * OF SUCH DAMAGE. 00026 * 00027 * This file is part of the lwIP TCP/IP stack. 00028 * 00029 * Author: Adam Dunkels <adam@sics.se> 00030 * 00031 */ 00032 #ifndef __LWIP_API_MSG_H__ 00033 #define __LWIP_API_MSG_H__ 00034 00035 #include "lwip/opt.h" 00036 00037 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ 00038 00039 #include <stddef.h> /* for size_t */ 00040 00041 #include "lwip/ip_addr.h" 00042 #include "lwip/err.h" 00043 #include "lwip/sys.h" 00044 #include "lwip/igmp.h" 00045 #include "lwip/api.h" 00046 00047 #ifdef __cplusplus 00048 extern "C" { 00049 #endif 00050 00051 /* For the netconn API, these values are use as a bitmask! */ 00052 #define NETCONN_SHUT_RD 1 00053 #define NETCONN_SHUT_WR 2 00054 #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR) 00055 00056 /* IP addresses and port numbers are expected to be in 00057 * the same byte order as in the corresponding pcb. 00058 */ 00059 /** This struct includes everything that is necessary to execute a function 00060 for a netconn in another thread context (mainly used to process netconns 00061 in the tcpip_thread context to be thread safe). */ 00062 struct api_msg_msg { 00063 /** The netconn which to process - always needed: it includes the semaphore 00064 which is used to block the application thread until the function finished. */ 00065 struct netconn *conn; 00066 /** The return value of the function executed in tcpip_thread. */ 00067 err_t err; 00068 /** Depending on the executed function, one of these union members is used */ 00069 union { 00070 /** used for do_send */ 00071 struct netbuf *b; 00072 /** used for do_newconn */ 00073 struct { 00074 u8_t proto; 00075 } n; 00076 /** used for do_bind and do_connect */ 00077 struct { 00078 ip_addr_t *ipaddr; 00079 u16_t port; 00080 } bc; 00081 /** used for do_getaddr */ 00082 struct { 00083 ip_addr_t *ipaddr; 00084 u16_t *port; 00085 u8_t local; 00086 } ad; 00087 /** used for do_write */ 00088 struct { 00089 const void *dataptr; 00090 size_t len; 00091 u8_t apiflags; 00092 } w; 00093 /** used for do_recv */ 00094 struct { 00095 u32_t len; 00096 } r; 00097 /** used for do_close (/shutdown) */ 00098 struct { 00099 u8_t shut; 00100 } sd; 00101 #if LWIP_IGMP 00102 /** used for do_join_leave_group */ 00103 struct { 00104 ip_addr_t *multiaddr; 00105 ip_addr_t *netif_addr; 00106 enum netconn_igmp join_or_leave; 00107 } jl; 00108 #endif /* LWIP_IGMP */ 00109 #if TCP_LISTEN_BACKLOG 00110 struct { 00111 u8_t backlog; 00112 } lb; 00113 #endif /* TCP_LISTEN_BACKLOG */ 00114 } msg; 00115 }; 00116 00117 /** This struct contains a function to execute in another thread context and 00118 a struct api_msg_msg that serves as an argument for this function. 00119 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */ 00120 struct api_msg { 00121 /** function to execute in tcpip_thread context */ 00122 void (* function)(struct api_msg_msg *msg); 00123 /** arguments for this function */ 00124 struct api_msg_msg msg; 00125 }; 00126 00127 #if LWIP_DNS 00128 /** As do_gethostbyname requires more arguments but doesn't require a netconn, 00129 it has its own struct (to avoid struct api_msg getting bigger than necessary). 00130 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg 00131 (see netconn_gethostbyname). */ 00132 struct dns_api_msg { 00133 /** Hostname to query or dotted IP address string */ 00134 const char *name; 00135 /** Rhe resolved address is stored here */ 00136 ip_addr_t *addr; 00137 /** This semaphore is posted when the name is resolved, the application thread 00138 should wait on it. */ 00139 sys_sem_t *sem; 00140 /** Errors are given back here */ 00141 err_t *err; 00142 }; 00143 #endif /* LWIP_DNS */ 00144 00145 void do_newconn ( struct api_msg_msg *msg); 00146 void do_delconn ( struct api_msg_msg *msg); 00147 void do_bind ( struct api_msg_msg *msg); 00148 void do_connect ( struct api_msg_msg *msg); 00149 void do_disconnect ( struct api_msg_msg *msg); 00150 void do_listen ( struct api_msg_msg *msg); 00151 void do_send ( struct api_msg_msg *msg); 00152 void do_recv ( struct api_msg_msg *msg); 00153 void do_write ( struct api_msg_msg *msg); 00154 void do_getaddr ( struct api_msg_msg *msg); 00155 void do_close ( struct api_msg_msg *msg); 00156 void do_shutdown ( struct api_msg_msg *msg); 00157 #if LWIP_IGMP 00158 void do_join_leave_group( struct api_msg_msg *msg); 00159 #endif /* LWIP_IGMP */ 00160 00161 #if LWIP_DNS 00162 void do_gethostbyname(void *arg); 00163 #endif /* LWIP_DNS */ 00164 00165 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback); 00166 void netconn_free(struct netconn *conn); 00167 00168 #ifdef __cplusplus 00169 } 00170 #endif 00171 00172 #endif /* LWIP_NETCONN */ 00173 00174 #endif /* __LWIP_API_MSG_H__ */
Generated on Tue Jul 12 2022 13:44:40 by
