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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
sockets_priv.h
00001 /** 00002 * @file 00003 * Sockets API internal implementations (do not use in application code) 00004 */ 00005 00006 /* 00007 * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. <joel.cunningham@garmin.com> 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without modification, 00011 * are permitted provided that the following conditions are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. The name of the author may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00024 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00026 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00029 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00030 * OF SUCH DAMAGE. 00031 * 00032 * This file is part of the lwIP TCP/IP stack. 00033 * 00034 * Author: Joel Cunningham <joel.cunningham@me.com> 00035 * 00036 */ 00037 #ifndef LWIP_HDR_SOCKETS_PRIV_H 00038 #define LWIP_HDR_SOCKETS_PRIV_H 00039 00040 #include "lwip/opt.h" 00041 00042 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 00043 00044 #include "lwip/err.h" 00045 #include "lwip/sockets.h" 00046 #include "lwip/sys.h" 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00052 #define NUM_SOCKETS MEMP_NUM_NETCONN 00053 00054 /** This is overridable for the rare case where more than 255 threads 00055 * select on the same socket... 00056 */ 00057 #ifndef SELWAIT_T 00058 #define SELWAIT_T u8_t 00059 #endif 00060 00061 union lwip_sock_lastdata { 00062 struct netbuf *netbuf; 00063 struct pbuf *pbuf; 00064 }; 00065 00066 /** Contains all internal pointers and states used for a socket */ 00067 struct lwip_sock { 00068 /** sockets currently are built on netconns, each socket has one netconn */ 00069 struct netconn *conn; 00070 /** data that was left from the previous read */ 00071 union lwip_sock_lastdata lastdata; 00072 #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL 00073 /** number of times data was received, set by event_callback(), 00074 tested by the receive and select functions */ 00075 s16_t rcvevent; 00076 /** number of times data was ACKed (free send buffer), set by event_callback(), 00077 tested by select */ 00078 u16_t sendevent; 00079 /** error happened for this socket, set by event_callback(), tested by select */ 00080 u16_t errevent; 00081 /** counter of how many threads are waiting for this socket using select */ 00082 SELWAIT_T select_waiting; 00083 #endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ 00084 #if LWIP_NETCONN_FULLDUPLEX 00085 /* counter of how many threads are using a struct lwip_sock (not the 'int') */ 00086 u8_t fd_used; 00087 /* status of pending close/delete actions */ 00088 u8_t fd_free_pending; 00089 #define LWIP_SOCK_FD_FREE_TCP 1 00090 #define LWIP_SOCK_FD_FREE_FREE 2 00091 #endif 00092 }; 00093 00094 #ifndef set_errno 00095 #define set_errno(err) do { if (err) { errno = (err); } } while(0) 00096 #endif 00097 00098 #if !LWIP_TCPIP_CORE_LOCKING 00099 /** Maximum optlen used by setsockopt/getsockopt */ 00100 #define LWIP_SETGETSOCKOPT_MAXOPTLEN LWIP_MAX(16, sizeof(struct ifreq)) 00101 00102 /** This struct is used to pass data to the set/getsockopt_internal 00103 * functions running in tcpip_thread context (only a void* is allowed) */ 00104 struct lwip_setgetsockopt_data { 00105 /** socket index for which to change options */ 00106 int s; 00107 /** level of the option to process */ 00108 int level; 00109 /** name of the option to process */ 00110 int optname; 00111 /** set: value to set the option to 00112 * get: value of the option is stored here */ 00113 #if LWIP_MPU_COMPATIBLE 00114 u8_t optval[LWIP_SETGETSOCKOPT_MAXOPTLEN]; 00115 #else 00116 union { 00117 void *p; 00118 const void *pc; 00119 } optval; 00120 #endif 00121 /** size of *optval */ 00122 socklen_t optlen; 00123 /** if an error occurs, it is temporarily stored here */ 00124 int err; 00125 /** semaphore to wake up the calling task */ 00126 void* completed_sem; 00127 }; 00128 #endif /* !LWIP_TCPIP_CORE_LOCKING */ 00129 00130 #ifdef __cplusplus 00131 } 00132 #endif 00133 00134 struct lwip_sock* lwip_socket_dbg_get_socket(int fd); 00135 00136 #if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL 00137 00138 #if LWIP_NETCONN_SEM_PER_THREAD 00139 #define SELECT_SEM_T sys_sem_t* 00140 #define SELECT_SEM_PTR(sem) (sem) 00141 #else /* LWIP_NETCONN_SEM_PER_THREAD */ 00142 #define SELECT_SEM_T sys_sem_t 00143 #define SELECT_SEM_PTR(sem) (&(sem)) 00144 #endif /* LWIP_NETCONN_SEM_PER_THREAD */ 00145 00146 /** Description for a task waiting in select */ 00147 struct lwip_select_cb { 00148 /** Pointer to the next waiting task */ 00149 struct lwip_select_cb *next; 00150 /** Pointer to the previous waiting task */ 00151 struct lwip_select_cb *prev; 00152 #if LWIP_SOCKET_SELECT 00153 /** readset passed to select */ 00154 fd_set *readset; 00155 /** writeset passed to select */ 00156 fd_set *writeset; 00157 /** unimplemented: exceptset passed to select */ 00158 fd_set *exceptset; 00159 #endif /* LWIP_SOCKET_SELECT */ 00160 #if LWIP_SOCKET_POLL 00161 /** fds passed to poll; NULL if select */ 00162 struct pollfd *poll_fds; 00163 /** nfds passed to poll; 0 if select */ 00164 nfds_t poll_nfds; 00165 #endif /* LWIP_SOCKET_POLL */ 00166 /** don't signal the same semaphore twice: set to 1 when signalled */ 00167 int sem_signalled; 00168 /** semaphore to wake up a task waiting for select */ 00169 SELECT_SEM_T sem; 00170 }; 00171 #endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ 00172 00173 #endif /* LWIP_SOCKET */ 00174 00175 #endif /* LWIP_HDR_SOCKETS_PRIV_H */
Generated on Tue Jul 12 2022 13:54:51 by
1.7.2