Webserver+3d print
cyclone_tcp/core/socket.h@0:8918a71cdbe9, 2017-02-04 (annotated)
- Committer:
- Sergunb
- Date:
- Sat Feb 04 18:15:49 2017 +0000
- Revision:
- 0:8918a71cdbe9
nothing else
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sergunb | 0:8918a71cdbe9 | 1 | /** |
Sergunb | 0:8918a71cdbe9 | 2 | * @file socket.h |
Sergunb | 0:8918a71cdbe9 | 3 | * @brief Socket API |
Sergunb | 0:8918a71cdbe9 | 4 | * |
Sergunb | 0:8918a71cdbe9 | 5 | * @section License |
Sergunb | 0:8918a71cdbe9 | 6 | * |
Sergunb | 0:8918a71cdbe9 | 7 | * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. |
Sergunb | 0:8918a71cdbe9 | 8 | * |
Sergunb | 0:8918a71cdbe9 | 9 | * This file is part of CycloneTCP Open. |
Sergunb | 0:8918a71cdbe9 | 10 | * |
Sergunb | 0:8918a71cdbe9 | 11 | * This program is free software; you can redistribute it and/or |
Sergunb | 0:8918a71cdbe9 | 12 | * modify it under the terms of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 13 | * as published by the Free Software Foundation; either version 2 |
Sergunb | 0:8918a71cdbe9 | 14 | * of the License, or (at your option) any later version. |
Sergunb | 0:8918a71cdbe9 | 15 | * |
Sergunb | 0:8918a71cdbe9 | 16 | * This program is distributed in the hope that it will be useful, |
Sergunb | 0:8918a71cdbe9 | 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Sergunb | 0:8918a71cdbe9 | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Sergunb | 0:8918a71cdbe9 | 19 | * GNU General Public License for more details. |
Sergunb | 0:8918a71cdbe9 | 20 | * |
Sergunb | 0:8918a71cdbe9 | 21 | * You should have received a copy of the GNU General Public License |
Sergunb | 0:8918a71cdbe9 | 22 | * along with this program; if not, write to the Free Software Foundation, |
Sergunb | 0:8918a71cdbe9 | 23 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
Sergunb | 0:8918a71cdbe9 | 24 | * |
Sergunb | 0:8918a71cdbe9 | 25 | * @author Oryx Embedded SARL (www.oryx-embedded.com) |
Sergunb | 0:8918a71cdbe9 | 26 | * @version 1.7.6 |
Sergunb | 0:8918a71cdbe9 | 27 | **/ |
Sergunb | 0:8918a71cdbe9 | 28 | |
Sergunb | 0:8918a71cdbe9 | 29 | #ifndef _SOCKET_H |
Sergunb | 0:8918a71cdbe9 | 30 | #define _SOCKET_H |
Sergunb | 0:8918a71cdbe9 | 31 | |
Sergunb | 0:8918a71cdbe9 | 32 | //Forward declaration of Socket structure |
Sergunb | 0:8918a71cdbe9 | 33 | struct _Socket; |
Sergunb | 0:8918a71cdbe9 | 34 | #define Socket struct _Socket |
Sergunb | 0:8918a71cdbe9 | 35 | |
Sergunb | 0:8918a71cdbe9 | 36 | //Dependencies |
Sergunb | 0:8918a71cdbe9 | 37 | #include "core/net.h" |
Sergunb | 0:8918a71cdbe9 | 38 | #include "core/ip.h" |
Sergunb | 0:8918a71cdbe9 | 39 | #include "core/tcp.h" |
Sergunb | 0:8918a71cdbe9 | 40 | |
Sergunb | 0:8918a71cdbe9 | 41 | //Number of sockets that can be opened simultaneously |
Sergunb | 0:8918a71cdbe9 | 42 | #ifndef SOCKET_MAX_COUNT |
Sergunb | 0:8918a71cdbe9 | 43 | #define SOCKET_MAX_COUNT 16 |
Sergunb | 0:8918a71cdbe9 | 44 | #elif (SOCKET_MAX_COUNT < 1) |
Sergunb | 0:8918a71cdbe9 | 45 | #error SOCKET_MAX_COUNT parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 46 | #endif |
Sergunb | 0:8918a71cdbe9 | 47 | |
Sergunb | 0:8918a71cdbe9 | 48 | //Dynamic port range (lower limit) |
Sergunb | 0:8918a71cdbe9 | 49 | #ifndef SOCKET_EPHEMERAL_PORT_MIN |
Sergunb | 0:8918a71cdbe9 | 50 | #define SOCKET_EPHEMERAL_PORT_MIN 49152 |
Sergunb | 0:8918a71cdbe9 | 51 | #elif (SOCKET_EPHEMERAL_PORT_MIN < 1024) |
Sergunb | 0:8918a71cdbe9 | 52 | #error SOCKET_EPHEMERAL_PORT_MIN parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 53 | #endif |
Sergunb | 0:8918a71cdbe9 | 54 | |
Sergunb | 0:8918a71cdbe9 | 55 | //Dynamic port range (upper limit) |
Sergunb | 0:8918a71cdbe9 | 56 | #ifndef SOCKET_EPHEMERAL_PORT_MAX |
Sergunb | 0:8918a71cdbe9 | 57 | #define SOCKET_EPHEMERAL_PORT_MAX 65535 |
Sergunb | 0:8918a71cdbe9 | 58 | #elif (SOCKET_EPHEMERAL_PORT_MAX <= SOCKET_EPHEMERAL_PORT_MIN || SOCKET_EPHEMERAL_PORT_MAX > 65535) |
Sergunb | 0:8918a71cdbe9 | 59 | #error SOCKET_EPHEMERAL_PORT_MAX parameter is not valid |
Sergunb | 0:8918a71cdbe9 | 60 | #endif |
Sergunb | 0:8918a71cdbe9 | 61 | |
Sergunb | 0:8918a71cdbe9 | 62 | |
Sergunb | 0:8918a71cdbe9 | 63 | /** |
Sergunb | 0:8918a71cdbe9 | 64 | * @brief Socket types |
Sergunb | 0:8918a71cdbe9 | 65 | **/ |
Sergunb | 0:8918a71cdbe9 | 66 | |
Sergunb | 0:8918a71cdbe9 | 67 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 68 | { |
Sergunb | 0:8918a71cdbe9 | 69 | SOCKET_TYPE_UNUSED = 0, |
Sergunb | 0:8918a71cdbe9 | 70 | SOCKET_TYPE_STREAM = 1, |
Sergunb | 0:8918a71cdbe9 | 71 | SOCKET_TYPE_DGRAM = 2, |
Sergunb | 0:8918a71cdbe9 | 72 | SOCKET_TYPE_RAW_IP = 3, |
Sergunb | 0:8918a71cdbe9 | 73 | SOCKET_TYPE_RAW_ETH = 4 |
Sergunb | 0:8918a71cdbe9 | 74 | } SocketType; |
Sergunb | 0:8918a71cdbe9 | 75 | |
Sergunb | 0:8918a71cdbe9 | 76 | |
Sergunb | 0:8918a71cdbe9 | 77 | /** |
Sergunb | 0:8918a71cdbe9 | 78 | * @brief IP protocols |
Sergunb | 0:8918a71cdbe9 | 79 | **/ |
Sergunb | 0:8918a71cdbe9 | 80 | |
Sergunb | 0:8918a71cdbe9 | 81 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 82 | { |
Sergunb | 0:8918a71cdbe9 | 83 | SOCKET_IP_PROTO_ICMP = 1, |
Sergunb | 0:8918a71cdbe9 | 84 | SOCKET_IP_PROTO_IGMP = 2, |
Sergunb | 0:8918a71cdbe9 | 85 | SOCKET_IP_PROTO_TCP = 6, |
Sergunb | 0:8918a71cdbe9 | 86 | SOCKET_IP_PROTO_UDP = 17, |
Sergunb | 0:8918a71cdbe9 | 87 | SOCKET_IP_PROTO_ICMPV6 = 58 |
Sergunb | 0:8918a71cdbe9 | 88 | } SocketIpProtocol; |
Sergunb | 0:8918a71cdbe9 | 89 | |
Sergunb | 0:8918a71cdbe9 | 90 | |
Sergunb | 0:8918a71cdbe9 | 91 | /** |
Sergunb | 0:8918a71cdbe9 | 92 | * @brief Ethernet protocols |
Sergunb | 0:8918a71cdbe9 | 93 | **/ |
Sergunb | 0:8918a71cdbe9 | 94 | |
Sergunb | 0:8918a71cdbe9 | 95 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 96 | { |
Sergunb | 0:8918a71cdbe9 | 97 | SOCKET_ETH_PROTO_ALL = 0x0000, |
Sergunb | 0:8918a71cdbe9 | 98 | SOCKET_ETH_PROTO_IPV4 = 0x0800, |
Sergunb | 0:8918a71cdbe9 | 99 | SOCKET_ETH_PROTO_ARP = 0x0806, |
Sergunb | 0:8918a71cdbe9 | 100 | SOCKET_ETH_PROTO_IPV6 = 0x86DD |
Sergunb | 0:8918a71cdbe9 | 101 | } SocketEthProtocol; |
Sergunb | 0:8918a71cdbe9 | 102 | |
Sergunb | 0:8918a71cdbe9 | 103 | |
Sergunb | 0:8918a71cdbe9 | 104 | /** |
Sergunb | 0:8918a71cdbe9 | 105 | * @brief Flags used by I/O functions |
Sergunb | 0:8918a71cdbe9 | 106 | **/ |
Sergunb | 0:8918a71cdbe9 | 107 | |
Sergunb | 0:8918a71cdbe9 | 108 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 109 | { |
Sergunb | 0:8918a71cdbe9 | 110 | SOCKET_FLAG_PEEK = 0x0200, |
Sergunb | 0:8918a71cdbe9 | 111 | SOCKET_FLAG_DONT_ROUTE = 0x0400, |
Sergunb | 0:8918a71cdbe9 | 112 | SOCKET_FLAG_WAIT_ALL = 0x0800, |
Sergunb | 0:8918a71cdbe9 | 113 | SOCKET_FLAG_DONT_WAIT = 0x0100, |
Sergunb | 0:8918a71cdbe9 | 114 | SOCKET_FLAG_BREAK_CHAR = 0x1000, |
Sergunb | 0:8918a71cdbe9 | 115 | SOCKET_FLAG_BREAK_CRLF = 0x100A, |
Sergunb | 0:8918a71cdbe9 | 116 | SOCKET_FLAG_WAIT_ACK = 0x2000, |
Sergunb | 0:8918a71cdbe9 | 117 | SOCKET_FLAG_NO_DELAY = 0x4000, |
Sergunb | 0:8918a71cdbe9 | 118 | SOCKET_FLAG_DELAY = 0x8000 |
Sergunb | 0:8918a71cdbe9 | 119 | } SocketFlags; |
Sergunb | 0:8918a71cdbe9 | 120 | |
Sergunb | 0:8918a71cdbe9 | 121 | |
Sergunb | 0:8918a71cdbe9 | 122 | //The SOCKET_FLAG_BREAK macro causes the I/O functions to stop reading |
Sergunb | 0:8918a71cdbe9 | 123 | //data whenever the specified break character is encountered |
Sergunb | 0:8918a71cdbe9 | 124 | #define SOCKET_FLAG_BREAK(c) (SOCKET_FLAG_BREAK_CHAR | LSB(c)) |
Sergunb | 0:8918a71cdbe9 | 125 | |
Sergunb | 0:8918a71cdbe9 | 126 | |
Sergunb | 0:8918a71cdbe9 | 127 | /** |
Sergunb | 0:8918a71cdbe9 | 128 | * @brief Flags used by shutdown function |
Sergunb | 0:8918a71cdbe9 | 129 | **/ |
Sergunb | 0:8918a71cdbe9 | 130 | |
Sergunb | 0:8918a71cdbe9 | 131 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 132 | { |
Sergunb | 0:8918a71cdbe9 | 133 | SOCKET_SD_RECEIVE = 0, |
Sergunb | 0:8918a71cdbe9 | 134 | SOCKET_SD_SEND = 1, |
Sergunb | 0:8918a71cdbe9 | 135 | SOCKET_SD_BOTH = 2 |
Sergunb | 0:8918a71cdbe9 | 136 | } SocketShutdownFlags; |
Sergunb | 0:8918a71cdbe9 | 137 | |
Sergunb | 0:8918a71cdbe9 | 138 | |
Sergunb | 0:8918a71cdbe9 | 139 | /** |
Sergunb | 0:8918a71cdbe9 | 140 | * @brief Socket events |
Sergunb | 0:8918a71cdbe9 | 141 | **/ |
Sergunb | 0:8918a71cdbe9 | 142 | |
Sergunb | 0:8918a71cdbe9 | 143 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 144 | { |
Sergunb | 0:8918a71cdbe9 | 145 | SOCKET_EVENT_TIMEOUT = 0x0000, |
Sergunb | 0:8918a71cdbe9 | 146 | SOCKET_EVENT_CONNECTED = 0x0001, |
Sergunb | 0:8918a71cdbe9 | 147 | SOCKET_EVENT_CLOSED = 0x0002, |
Sergunb | 0:8918a71cdbe9 | 148 | SOCKET_EVENT_TX_READY = 0x0004, |
Sergunb | 0:8918a71cdbe9 | 149 | SOCKET_EVENT_TX_DONE = 0x0008, |
Sergunb | 0:8918a71cdbe9 | 150 | SOCKET_EVENT_TX_ACKED = 0x0010, |
Sergunb | 0:8918a71cdbe9 | 151 | SOCKET_EVENT_TX_SHUTDOWN = 0x0020, |
Sergunb | 0:8918a71cdbe9 | 152 | SOCKET_EVENT_RX_READY = 0x0040, |
Sergunb | 0:8918a71cdbe9 | 153 | SOCKET_EVENT_RX_SHUTDOWN = 0x0080, |
Sergunb | 0:8918a71cdbe9 | 154 | SOCKET_EVENT_LINK_UP = 0x0100, |
Sergunb | 0:8918a71cdbe9 | 155 | SOCKET_EVENT_LINK_DOWN = 0x0200 |
Sergunb | 0:8918a71cdbe9 | 156 | } SocketEvent; |
Sergunb | 0:8918a71cdbe9 | 157 | |
Sergunb | 0:8918a71cdbe9 | 158 | |
Sergunb | 0:8918a71cdbe9 | 159 | /** |
Sergunb | 0:8918a71cdbe9 | 160 | * @brief Host types |
Sergunb | 0:8918a71cdbe9 | 161 | **/ |
Sergunb | 0:8918a71cdbe9 | 162 | |
Sergunb | 0:8918a71cdbe9 | 163 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 164 | { |
Sergunb | 0:8918a71cdbe9 | 165 | HOST_TYPE_ANY = 0, |
Sergunb | 0:8918a71cdbe9 | 166 | HOST_TYPE_IPV4 = 16, |
Sergunb | 0:8918a71cdbe9 | 167 | HOST_TYPE_IPV6 = 32 |
Sergunb | 0:8918a71cdbe9 | 168 | } HostType; |
Sergunb | 0:8918a71cdbe9 | 169 | |
Sergunb | 0:8918a71cdbe9 | 170 | |
Sergunb | 0:8918a71cdbe9 | 171 | /** |
Sergunb | 0:8918a71cdbe9 | 172 | * @brief Name resolution protocols |
Sergunb | 0:8918a71cdbe9 | 173 | **/ |
Sergunb | 0:8918a71cdbe9 | 174 | |
Sergunb | 0:8918a71cdbe9 | 175 | typedef enum |
Sergunb | 0:8918a71cdbe9 | 176 | { |
Sergunb | 0:8918a71cdbe9 | 177 | HOST_NAME_RESOLVER_ANY = 0, |
Sergunb | 0:8918a71cdbe9 | 178 | HOST_NAME_RESOLVER_DNS = 1, |
Sergunb | 0:8918a71cdbe9 | 179 | HOST_NAME_RESOLVER_MDNS = 2, |
Sergunb | 0:8918a71cdbe9 | 180 | HOST_NAME_RESOLVER_NBNS = 4, |
Sergunb | 0:8918a71cdbe9 | 181 | HOST_NAME_RESOLVER_LLMNR = 8 |
Sergunb | 0:8918a71cdbe9 | 182 | } HostnameResolver; |
Sergunb | 0:8918a71cdbe9 | 183 | |
Sergunb | 0:8918a71cdbe9 | 184 | |
Sergunb | 0:8918a71cdbe9 | 185 | /** |
Sergunb | 0:8918a71cdbe9 | 186 | * @brief Receive queue item |
Sergunb | 0:8918a71cdbe9 | 187 | **/ |
Sergunb | 0:8918a71cdbe9 | 188 | |
Sergunb | 0:8918a71cdbe9 | 189 | typedef struct _SocketQueueItem |
Sergunb | 0:8918a71cdbe9 | 190 | { |
Sergunb | 0:8918a71cdbe9 | 191 | struct _SocketQueueItem *next; |
Sergunb | 0:8918a71cdbe9 | 192 | IpAddr srcIpAddr; |
Sergunb | 0:8918a71cdbe9 | 193 | uint16_t srcPort; |
Sergunb | 0:8918a71cdbe9 | 194 | IpAddr destIpAddr; |
Sergunb | 0:8918a71cdbe9 | 195 | NetBuffer *buffer; |
Sergunb | 0:8918a71cdbe9 | 196 | size_t offset; |
Sergunb | 0:8918a71cdbe9 | 197 | } SocketQueueItem; |
Sergunb | 0:8918a71cdbe9 | 198 | |
Sergunb | 0:8918a71cdbe9 | 199 | |
Sergunb | 0:8918a71cdbe9 | 200 | /** |
Sergunb | 0:8918a71cdbe9 | 201 | * @brief Structure describing a socket |
Sergunb | 0:8918a71cdbe9 | 202 | **/ |
Sergunb | 0:8918a71cdbe9 | 203 | |
Sergunb | 0:8918a71cdbe9 | 204 | struct _Socket |
Sergunb | 0:8918a71cdbe9 | 205 | { |
Sergunb | 0:8918a71cdbe9 | 206 | uint_t descriptor; |
Sergunb | 0:8918a71cdbe9 | 207 | uint_t type; |
Sergunb | 0:8918a71cdbe9 | 208 | uint_t protocol; |
Sergunb | 0:8918a71cdbe9 | 209 | NetInterface *interface; |
Sergunb | 0:8918a71cdbe9 | 210 | IpAddr localIpAddr; |
Sergunb | 0:8918a71cdbe9 | 211 | uint16_t localPort; |
Sergunb | 0:8918a71cdbe9 | 212 | IpAddr remoteIpAddr; |
Sergunb | 0:8918a71cdbe9 | 213 | uint16_t remotePort; |
Sergunb | 0:8918a71cdbe9 | 214 | systime_t timeout; |
Sergunb | 0:8918a71cdbe9 | 215 | uint8_t ttl; |
Sergunb | 0:8918a71cdbe9 | 216 | int_t errnoCode; |
Sergunb | 0:8918a71cdbe9 | 217 | OsEvent event; |
Sergunb | 0:8918a71cdbe9 | 218 | uint_t eventMask; |
Sergunb | 0:8918a71cdbe9 | 219 | uint_t eventFlags; |
Sergunb | 0:8918a71cdbe9 | 220 | OsEvent *userEvent; |
Sergunb | 0:8918a71cdbe9 | 221 | |
Sergunb | 0:8918a71cdbe9 | 222 | //TCP specific variables |
Sergunb | 0:8918a71cdbe9 | 223 | #if (TCP_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 224 | TcpState state; ///<Current state of the TCP finite state machine |
Sergunb | 0:8918a71cdbe9 | 225 | bool_t ownedFlag; ///<The user is the owner of the TCP socket |
Sergunb | 0:8918a71cdbe9 | 226 | bool_t closedFlag; ///<The connection has been closed properly |
Sergunb | 0:8918a71cdbe9 | 227 | bool_t resetFlag; ///<The connection has been reset |
Sergunb | 0:8918a71cdbe9 | 228 | |
Sergunb | 0:8918a71cdbe9 | 229 | uint16_t smss; ///<Sender maximum segment size |
Sergunb | 0:8918a71cdbe9 | 230 | uint16_t rmss; ///<Receiver maximum segment size |
Sergunb | 0:8918a71cdbe9 | 231 | uint32_t iss; ///<Initial send sequence number |
Sergunb | 0:8918a71cdbe9 | 232 | uint32_t irs; ///<Initial receive sequence number |
Sergunb | 0:8918a71cdbe9 | 233 | |
Sergunb | 0:8918a71cdbe9 | 234 | uint32_t sndUna; ///<Data that have been sent but not yet acknowledged |
Sergunb | 0:8918a71cdbe9 | 235 | uint32_t sndNxt; ///<Sequence number of the next byte to be sent |
Sergunb | 0:8918a71cdbe9 | 236 | uint16_t sndUser; ///<Amount of data buffered but not yet sent |
Sergunb | 0:8918a71cdbe9 | 237 | uint16_t sndWnd; ///<Size of the send window |
Sergunb | 0:8918a71cdbe9 | 238 | uint16_t maxSndWnd; ///<Maximum send window it has seen so far on the connection |
Sergunb | 0:8918a71cdbe9 | 239 | uint32_t sndWl1; ///<Segment sequence number used for last window update |
Sergunb | 0:8918a71cdbe9 | 240 | uint32_t sndWl2; ///<Segment acknowledgment number used for last window update |
Sergunb | 0:8918a71cdbe9 | 241 | |
Sergunb | 0:8918a71cdbe9 | 242 | uint32_t rcvNxt; ///<Receive next sequence number |
Sergunb | 0:8918a71cdbe9 | 243 | uint16_t rcvUser; ///<Number of data received but not yet consumed |
Sergunb | 0:8918a71cdbe9 | 244 | uint16_t rcvWnd; ///<Receive window |
Sergunb | 0:8918a71cdbe9 | 245 | |
Sergunb | 0:8918a71cdbe9 | 246 | bool_t rttBusy; ///<RTT measurement is being performed |
Sergunb | 0:8918a71cdbe9 | 247 | uint32_t rttSeqNum; ///<Sequence number identifying a TCP segment |
Sergunb | 0:8918a71cdbe9 | 248 | systime_t rttStartTime; ///<Round-trip start time |
Sergunb | 0:8918a71cdbe9 | 249 | systime_t srtt; ///<Smoothed round-trip time |
Sergunb | 0:8918a71cdbe9 | 250 | systime_t rttvar; ///<Round-trip time variation |
Sergunb | 0:8918a71cdbe9 | 251 | systime_t rto; ///<Retransmission timeout |
Sergunb | 0:8918a71cdbe9 | 252 | |
Sergunb | 0:8918a71cdbe9 | 253 | #if (TCP_CONGEST_CONTROL_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 254 | TcpCongestState congestState; ///<Congestion state |
Sergunb | 0:8918a71cdbe9 | 255 | uint16_t cwnd; ///<Congestion window |
Sergunb | 0:8918a71cdbe9 | 256 | uint16_t ssthresh; ///<Slow start threshold |
Sergunb | 0:8918a71cdbe9 | 257 | uint_t dupAckCount; ///<Number of consecutive duplicate ACKs |
Sergunb | 0:8918a71cdbe9 | 258 | uint_t n; ///<Number of bytes acknowledged during the whole round-trip |
Sergunb | 0:8918a71cdbe9 | 259 | uint32_t recover; ///<NewReno modification to TCP's fast recovery algorithm |
Sergunb | 0:8918a71cdbe9 | 260 | #endif |
Sergunb | 0:8918a71cdbe9 | 261 | |
Sergunb | 0:8918a71cdbe9 | 262 | TcpTxBuffer txBuffer; ///<Send buffer |
Sergunb | 0:8918a71cdbe9 | 263 | size_t txBufferSize; ///<Size of the send buffer |
Sergunb | 0:8918a71cdbe9 | 264 | TcpRxBuffer rxBuffer; ///<Receive buffer |
Sergunb | 0:8918a71cdbe9 | 265 | size_t rxBufferSize; ///<Size of the receive buffer |
Sergunb | 0:8918a71cdbe9 | 266 | |
Sergunb | 0:8918a71cdbe9 | 267 | TcpQueueItem *retransmitQueue; ///<Retransmission queue |
Sergunb | 0:8918a71cdbe9 | 268 | TcpTimer retransmitTimer; ///<Retransmission timer |
Sergunb | 0:8918a71cdbe9 | 269 | uint_t retransmitCount; ///<Number of retransmissions |
Sergunb | 0:8918a71cdbe9 | 270 | |
Sergunb | 0:8918a71cdbe9 | 271 | TcpSynQueueItem *synQueue; ///<SYN queue for listening sockets |
Sergunb | 0:8918a71cdbe9 | 272 | uint_t synQueueSize; ///<Maximum number of pending connections for listening sockets |
Sergunb | 0:8918a71cdbe9 | 273 | |
Sergunb | 0:8918a71cdbe9 | 274 | uint_t wndProbeCount; ///<Zero window probe counter |
Sergunb | 0:8918a71cdbe9 | 275 | systime_t wndProbeInterval; ///<Interval between successive probes |
Sergunb | 0:8918a71cdbe9 | 276 | |
Sergunb | 0:8918a71cdbe9 | 277 | TcpTimer persistTimer; ///<Persist timer |
Sergunb | 0:8918a71cdbe9 | 278 | TcpTimer overrideTimer; ///<Override timer |
Sergunb | 0:8918a71cdbe9 | 279 | TcpTimer finWait2Timer; ///<FIN-WAIT-2 timer |
Sergunb | 0:8918a71cdbe9 | 280 | TcpTimer timeWaitTimer; ///<2MSL timer |
Sergunb | 0:8918a71cdbe9 | 281 | |
Sergunb | 0:8918a71cdbe9 | 282 | bool_t sackPermitted; ///<SACK Permitted option received |
Sergunb | 0:8918a71cdbe9 | 283 | TcpSackBlock sackBlock[TCP_MAX_SACK_BLOCKS]; ///<List of non-contiguous blocks that have been received |
Sergunb | 0:8918a71cdbe9 | 284 | uint_t sackBlockCount; ///<Number of non-contiguous blocks that have been received |
Sergunb | 0:8918a71cdbe9 | 285 | #endif |
Sergunb | 0:8918a71cdbe9 | 286 | |
Sergunb | 0:8918a71cdbe9 | 287 | //UDP specific variables |
Sergunb | 0:8918a71cdbe9 | 288 | #if (UDP_SUPPORT == ENABLED || RAW_SOCKET_SUPPORT == ENABLED) |
Sergunb | 0:8918a71cdbe9 | 289 | SocketQueueItem *receiveQueue; |
Sergunb | 0:8918a71cdbe9 | 290 | #endif |
Sergunb | 0:8918a71cdbe9 | 291 | }; |
Sergunb | 0:8918a71cdbe9 | 292 | |
Sergunb | 0:8918a71cdbe9 | 293 | |
Sergunb | 0:8918a71cdbe9 | 294 | /** |
Sergunb | 0:8918a71cdbe9 | 295 | * @brief Structure describing socket events |
Sergunb | 0:8918a71cdbe9 | 296 | **/ |
Sergunb | 0:8918a71cdbe9 | 297 | |
Sergunb | 0:8918a71cdbe9 | 298 | typedef struct |
Sergunb | 0:8918a71cdbe9 | 299 | { |
Sergunb | 0:8918a71cdbe9 | 300 | Socket *socket; ///<Handle to a socket to monitor |
Sergunb | 0:8918a71cdbe9 | 301 | uint_t eventMask; ///<Requested events |
Sergunb | 0:8918a71cdbe9 | 302 | uint_t eventFlags; ///<Returned events |
Sergunb | 0:8918a71cdbe9 | 303 | } SocketEventDesc; |
Sergunb | 0:8918a71cdbe9 | 304 | |
Sergunb | 0:8918a71cdbe9 | 305 | |
Sergunb | 0:8918a71cdbe9 | 306 | //Global variables |
Sergunb | 0:8918a71cdbe9 | 307 | extern Socket socketTable[SOCKET_MAX_COUNT]; |
Sergunb | 0:8918a71cdbe9 | 308 | |
Sergunb | 0:8918a71cdbe9 | 309 | //Socket related functions |
Sergunb | 0:8918a71cdbe9 | 310 | error_t socketInit(void); |
Sergunb | 0:8918a71cdbe9 | 311 | |
Sergunb | 0:8918a71cdbe9 | 312 | Socket *socketOpen(uint_t type, uint_t protocol); |
Sergunb | 0:8918a71cdbe9 | 313 | |
Sergunb | 0:8918a71cdbe9 | 314 | error_t socketSetTimeout(Socket *socket, systime_t timeout); |
Sergunb | 0:8918a71cdbe9 | 315 | error_t socketSetTxBufferSize(Socket *socket, size_t size); |
Sergunb | 0:8918a71cdbe9 | 316 | error_t socketSetRxBufferSize(Socket *socket, size_t size); |
Sergunb | 0:8918a71cdbe9 | 317 | |
Sergunb | 0:8918a71cdbe9 | 318 | error_t socketBindToInterface(Socket *socket, NetInterface *interface); |
Sergunb | 0:8918a71cdbe9 | 319 | error_t socketBind(Socket *socket, const IpAddr *localIpAddr, uint16_t localPort); |
Sergunb | 0:8918a71cdbe9 | 320 | error_t socketConnect(Socket *socket, const IpAddr *remoteIpAddr, uint16_t remotePort); |
Sergunb | 0:8918a71cdbe9 | 321 | error_t socketListen(Socket *socket, uint_t backlog); |
Sergunb | 0:8918a71cdbe9 | 322 | Socket *socketAccept(Socket *socket, IpAddr *clientIpAddr, uint16_t *clientPort); |
Sergunb | 0:8918a71cdbe9 | 323 | |
Sergunb | 0:8918a71cdbe9 | 324 | error_t socketSend(Socket *socket, const void *data, |
Sergunb | 0:8918a71cdbe9 | 325 | size_t length, size_t *written, uint_t flags); |
Sergunb | 0:8918a71cdbe9 | 326 | |
Sergunb | 0:8918a71cdbe9 | 327 | error_t socketSendTo(Socket *socket, const IpAddr *destIpAddr, uint16_t destPort, |
Sergunb | 0:8918a71cdbe9 | 328 | const void *data, size_t length, size_t *written, uint_t flags); |
Sergunb | 0:8918a71cdbe9 | 329 | |
Sergunb | 0:8918a71cdbe9 | 330 | error_t socketReceive(Socket *socket, void *data, |
Sergunb | 0:8918a71cdbe9 | 331 | size_t size, size_t *received, uint_t flags); |
Sergunb | 0:8918a71cdbe9 | 332 | |
Sergunb | 0:8918a71cdbe9 | 333 | error_t socketReceiveFrom(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, |
Sergunb | 0:8918a71cdbe9 | 334 | void *data, size_t size, size_t *received, uint_t flags); |
Sergunb | 0:8918a71cdbe9 | 335 | |
Sergunb | 0:8918a71cdbe9 | 336 | error_t socketReceiveEx(Socket *socket, IpAddr *srcIpAddr, uint16_t *srcPort, |
Sergunb | 0:8918a71cdbe9 | 337 | IpAddr *destIpAddr, void *data, size_t size, size_t *received, uint_t flags); |
Sergunb | 0:8918a71cdbe9 | 338 | |
Sergunb | 0:8918a71cdbe9 | 339 | error_t socketGetLocalAddr(Socket *socket, IpAddr *localIpAddr, uint16_t *localPort); |
Sergunb | 0:8918a71cdbe9 | 340 | error_t socketGetRemoteAddr(Socket *socket, IpAddr *remoteIpAddr, uint16_t *remotePort); |
Sergunb | 0:8918a71cdbe9 | 341 | |
Sergunb | 0:8918a71cdbe9 | 342 | error_t socketShutdown(Socket *socket, uint_t how); |
Sergunb | 0:8918a71cdbe9 | 343 | void socketClose(Socket *socket); |
Sergunb | 0:8918a71cdbe9 | 344 | |
Sergunb | 0:8918a71cdbe9 | 345 | error_t socketPoll(SocketEventDesc *eventDesc, uint_t size, OsEvent *extEvent, systime_t timeout); |
Sergunb | 0:8918a71cdbe9 | 346 | error_t socketRegisterEvents(Socket *socket, OsEvent *event, uint_t eventMask); |
Sergunb | 0:8918a71cdbe9 | 347 | error_t socketUnregisterEvents(Socket *socket); |
Sergunb | 0:8918a71cdbe9 | 348 | error_t socketGetEvents(Socket *socket, uint_t *eventFlags); |
Sergunb | 0:8918a71cdbe9 | 349 | |
Sergunb | 0:8918a71cdbe9 | 350 | error_t getHostByName(NetInterface *interface, |
Sergunb | 0:8918a71cdbe9 | 351 | const char_t *name, IpAddr *ipAddr, uint_t flags); |
Sergunb | 0:8918a71cdbe9 | 352 | |
Sergunb | 0:8918a71cdbe9 | 353 | #endif |
Sergunb | 0:8918a71cdbe9 | 354 |