TuyaOS
sockets_priv.h
浏览该文件的文档.
1
6/*
7 * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. <joel.cunningham@garmin.com>
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * This file is part of the lwIP TCP/IP stack.
33 *
34 * Author: Joel Cunningham <joel.cunningham@me.com>
35 *
36 */
37#ifndef LWIP_HDR_SOCKETS_PRIV_H
38#define LWIP_HDR_SOCKETS_PRIV_H
39
40#include "lwip/opt.h"
41
42#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
43
44#include "lwip/err.h"
45#include "lwip/sockets.h"
46#include "lwip/sys.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52#define NUM_SOCKETS MEMP_NUM_NETCONN
53
57#ifndef SELWAIT_T
58#define SELWAIT_T u8_t
59#endif
60
61union lwip_sock_lastdata {
62 struct netbuf *netbuf;
63 struct pbuf *pbuf;
64};
65
67struct lwip_sock {
69 struct netconn *conn;
71 union lwip_sock_lastdata lastdata;
72#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL
75 s16_t rcvevent;
78 u16_t sendevent;
80 u16_t errevent;
82 SELWAIT_T select_waiting;
83#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */
84#if LWIP_NETCONN_FULLDUPLEX
85 /* counter of how many threads are using a struct lwip_sock (not the 'int') */
86 u8_t fd_used;
87 /* status of pending close/delete actions */
88 u8_t fd_free_pending;
89#define LWIP_SOCK_FD_FREE_TCP 1
90#define LWIP_SOCK_FD_FREE_FREE 2
91#endif
92
93#if SOCK_API_SYNC
94 /* closing is 0, when the socket is created. It is 1, when the function "close" is called, */
95 /* and then send / recv function is not able to be called */
96 int closing;
97 sys_mutex_t mutex_recv;
98 sys_mutex_t mutex_send;
99#endif
100};
101
102#ifndef set_errno
103#define set_errno(err) do { if (err) { errno = (err); } } while(0)
104#endif
105
106#if !LWIP_TCPIP_CORE_LOCKING
108#define LWIP_SETGETSOCKOPT_MAXOPTLEN LWIP_MAX(16, sizeof(struct ifreq))
109
112struct lwip_setgetsockopt_data {
114 int s;
116 int level;
118 int optname;
121#if LWIP_MPU_COMPATIBLE
122 u8_t optval[LWIP_SETGETSOCKOPT_MAXOPTLEN];
123#else
124 union {
125 void *p;
126 const void *pc;
127 } optval;
128#endif
130 socklen_t optlen;
132 int err;
134 void* completed_sem;
135};
136#endif /* !LWIP_TCPIP_CORE_LOCKING */
137
138#ifdef __cplusplus
139}
140#endif
141
142struct lwip_sock* lwip_socket_dbg_get_socket(int fd);
143
144#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL
145
146#if LWIP_NETCONN_SEM_PER_THREAD
147#define SELECT_SEM_T sys_sem_t*
148#define SELECT_SEM_PTR(sem) (sem)
149#else /* LWIP_NETCONN_SEM_PER_THREAD */
150#define SELECT_SEM_T sys_sem_t
151#define SELECT_SEM_PTR(sem) (&(sem))
152#endif /* LWIP_NETCONN_SEM_PER_THREAD */
153
155struct lwip_select_cb {
157 struct lwip_select_cb *next;
159 struct lwip_select_cb *prev;
160#if LWIP_SOCKET_SELECT
162 fd_set *readset;
164 fd_set *writeset;
166 fd_set *exceptset;
167#endif /* LWIP_SOCKET_SELECT */
168#if LWIP_SOCKET_POLL
170 struct pollfd *poll_fds;
172 nfds_t poll_nfds;
173#endif /* LWIP_SOCKET_POLL */
175 int sem_signalled;
177 SELECT_SEM_T sem;
178};
179#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */
180
181#endif /* LWIP_SOCKET */
182
183#endif /* LWIP_HDR_SOCKETS_PRIV_H */
Definition: pbuf.h:186