Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020-2021 Project CHIP Authors
4 : * Copyright (c) 2013-2017 Nest Labs, Inc.
5 : *
6 : * Licensed under the Apache License, Version 2.0 (the "License");
7 : * you may not use this file except in compliance with the License.
8 : * You may obtain a copy of the License at
9 : *
10 : * http://www.apache.org/licenses/LICENSE-2.0
11 : *
12 : * Unless required by applicable law or agreed to in writing, software
13 : * distributed under the License is distributed on an "AS IS" BASIS,
14 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 : * See the License for the specific language governing permissions and
16 : * limitations under the License.
17 : */
18 :
19 : /**
20 : * @file
21 : * This header file defines the <tt>Inet::TCPEndPoint</tt>
22 : * class, where the CHIP Inet Layer encapsulates methods for
23 : * interacting with TCP transport endpoints (SOCK_DGRAM sockets
24 : * on Linux and BSD-derived systems) or LwIP TCP protocol
25 : * control blocks, as the system is configured accordingly.
26 : */
27 :
28 : #pragma once
29 :
30 : #include <inet/EndPointBasis.h>
31 : #include <inet/IPAddress.h>
32 : #include <inet/InetInterface.h>
33 : #include <inet/InetLayer.h>
34 : #include <system/SystemLayer.h>
35 : #include <system/SystemPacketBuffer.h>
36 :
37 : #include <utility>
38 :
39 : namespace chip {
40 :
41 : namespace Inet {
42 :
43 : class TCPTest;
44 :
45 : /**
46 : * @brief Objects of this class represent TCP transport endpoints.
47 : *
48 : * @details
49 : * CHIP Inet Layer encapsulates methods for interacting with TCP transport
50 : * endpoints (SOCK_STREAM sockets on Linux and BSD-derived systems) or LwIP
51 : * TCP protocol control blocks, as the system is configured accordingly.
52 : */
53 : class DLL_EXPORT TCPEndPoint : public EndPointBasis<TCPEndPoint>
54 : {
55 : public:
56 : /**
57 : * @brief Bind the endpoint to an interface IP address.
58 : *
59 : * @param[in] addrType the protocol version of the IP address
60 : * @param[in] addr the IP address (must be an interface address)
61 : * @param[in] port the TCP port
62 : * @param[in] reuseAddr option to share binding with other endpoints
63 : *
64 : * @retval CHIP_NO_ERROR success: endpoint bound to address
65 : * @retval CHIP_ERROR_INCORRECT_STATE endpoint has been bound previously
66 : * @retval CHIP_ERROR_NO_MEMORY insufficient memory for endpoint
67 : *
68 : * @retval INET_ERROR_WRONG_PROTOCOL_TYPE
69 : * \c addrType does not match \c IPVer.
70 : *
71 : * @retval INET_ERROR_WRONG_ADDRESS_TYPE
72 : * \c addrType is \c IPAddressType::kAny, or the type of \c addr is not
73 : * equal to \c addrType.
74 : *
75 : * @retval other another system or platform error
76 : *
77 : * @details
78 : * Binds the endpoint to the specified network interface IP address.
79 : *
80 : * On LwIP, this method must not be called with the LwIP stack lock
81 : * already acquired.
82 : */
83 : CHIP_ERROR Bind(IPAddressType addrType, const IPAddress & addr, uint16_t port, bool reuseAddr = false);
84 :
85 : /**
86 : * @brief Prepare the endpoint to receive TCP messages.
87 : *
88 : * @param[in] backlog maximum depth of connection acceptance queue
89 : *
90 : * @retval CHIP_NO_ERROR success: endpoint ready to receive messages.
91 : * @retval CHIP_ERROR_INCORRECT_STATE endpoint is already listening.
92 : *
93 : * @details
94 : * If \c mState is already \c State::kListening, then no operation is
95 : * performed, otherwise the \c mState is set to \c State::kListening and
96 : * the endpoint is prepared to received TCP messages, according to the
97 : * semantics of the platform.
98 : *
99 : * On some platforms, the \c backlog argument is not used (the depth of
100 : * the queue is fixed; only one connection may be accepted at a time).
101 : *
102 : * On LwIP systems, this method must not be called with the LwIP stack
103 : * lock already acquired
104 : */
105 : CHIP_ERROR Listen(uint16_t backlog);
106 :
107 : /**
108 : * @brief Initiate a TCP connection.
109 : *
110 : * @param[in] addr the destination IP address
111 : * @param[in] port the destination TCP port
112 : * @param[in] intfId an optional network interface indicator
113 : *
114 : * @retval CHIP_NO_ERROR success: \c msg is queued for transmit.
115 : * @retval CHIP_ERROR_NOT_IMPLEMENTED system implementation not complete.
116 : *
117 : * @retval INET_ERROR_WRONG_ADDRESS_TYPE
118 : * the destination address and the bound interface address do not
119 : * have matching protocol versions or address type, or the destination
120 : * address is an IPv6 link-local address and \c intfId is not specified.
121 : *
122 : * @retval other another system or platform error
123 : *
124 : * @details
125 : * If possible, then this method initiates a TCP connection to the
126 : * destination \c addr (with \c intfId used as the scope
127 : * identifier for IPv6 link-local destinations) and \c port.
128 : */
129 : CHIP_ERROR Connect(const IPAddress & addr, uint16_t port, InterfaceId intfId = InterfaceId::Null());
130 :
131 : /**
132 : * @brief Extract IP address and TCP port of remote endpoint.
133 : *
134 : * @param[out] retAddr IP address of remote endpoint.
135 : * @param[out] retPort TCP port of remote endpoint.
136 : *
137 : * @retval CHIP_NO_ERROR success: address and port extracted.
138 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
139 : * @retval CHIP_ERROR_CONNECTION_ABORTED TCP connection no longer open.
140 : *
141 : * @details
142 : * Do not use \c nullptr for either argument.
143 : */
144 : virtual CHIP_ERROR GetPeerInfo(IPAddress * retAddr, uint16_t * retPort) const = 0;
145 :
146 : /**
147 : * @brief Extract IP address and TCP port of local endpoint.
148 : *
149 : * @param[out] retAddr IP address of local endpoint.
150 : * @param[out] retPort TCP port of local endpoint.
151 : *
152 : * @retval CHIP_NO_ERROR success: address and port extracted.
153 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
154 : * @retval CHIP_ERROR_CONNECTION_ABORTED TCP connection no longer open.
155 : *
156 : * @details
157 : * Do not use \c nullptr for either argument.
158 : */
159 : virtual CHIP_ERROR GetLocalInfo(IPAddress * retAddr, uint16_t * retPort) const = 0;
160 :
161 : /**
162 : * @brief Extract the interface id of the TCP endpoint.
163 : *
164 : * @param[out] retInterface The interface id.
165 : *
166 : * @retval CHIP_NO_ERROR success: address and port extracted.
167 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
168 : * @retval CHIP_ERROR_CONNECTION_ABORTED TCP connection no longer open.
169 : */
170 : virtual CHIP_ERROR GetInterfaceId(InterfaceId * retInterface) = 0;
171 :
172 : /**
173 : * @brief Send message text on TCP connection.
174 : *
175 : * @param[out] data Message text to send.
176 : * @param[out] push If \c true, then send immediately, otherwise queue.
177 : *
178 : * @retval CHIP_NO_ERROR success: address and port extracted.
179 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
180 : */
181 : CHIP_ERROR Send(chip::System::PacketBufferHandle && data, bool push = true);
182 :
183 : /**
184 : * Disable reception.
185 : *
186 : * Disable all event handlers. Data sent to an endpoint that disables
187 : * reception will be acknowledged until the receive window is exhausted.
188 : */
189 : void DisableReceive() { mReceiveEnabled = false; }
190 :
191 : /**
192 : * Enable reception.
193 : *
194 : * Enable all event handlers. Data sent to an endpoint that disables
195 : * reception will be acknowledged until the receive window is exhausted.
196 : */
197 : void EnableReceive()
198 : {
199 : mReceiveEnabled = true;
200 : DriveReceiving();
201 : }
202 :
203 : /**
204 : * Switch off Nagle buffering algorithm.
205 : */
206 : virtual CHIP_ERROR EnableNoDelay() = 0;
207 :
208 : /**
209 : * @brief
210 : * Enable TCP keepalive probes on the associated TCP connection.
211 : *
212 : * @param[in] interval
213 : * The interval (in seconds) between keepalive probes. This value also controls
214 : * the time between last data packet sent and the transmission of the first keepalive
215 : * probe.
216 : *
217 : * @param[in] timeoutCount
218 : * The maximum number of unacknowledged probes before the connection will be deemed
219 : * to have failed.
220 : *
221 : * @retval CHIP_NO_ERROR success: address and port extracted.
222 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
223 : * @retval CHIP_ERROR_CONNECTION_ABORTED TCP connection no longer open.
224 : * @retval CHIP_ERROR_NOT_IMPLEMENTED system implementation not complete.
225 : *
226 : * @retval other another system or platform error
227 : *
228 : * @note
229 : * This method can only be called when the endpoint is in one of the connected states.
230 : *
231 : * This method can be called multiple times to adjust the keepalive interval or timeout
232 : * count.
233 : *
234 : * @details
235 : * Start automatically transmitting TCP "keep-alive" probe segments every
236 : * \c interval seconds. The connection will abort automatically after
237 : * receiving a negative response, or after sending \c timeoutCount
238 : * probe segments without receiving a positive response.
239 : *
240 : * See RFC 1122, section 4.2.3.6 for specification details.
241 : */
242 : virtual CHIP_ERROR EnableKeepAlive(uint16_t interval, uint16_t timeoutCount) = 0;
243 :
244 : /**
245 : * @brief Disable the TCP "keep-alive" option.
246 : *
247 : * This method can only be called when the endpoint is in one of the connected states.
248 : * This method does nothing if keepalives have not been enabled on the endpoint.
249 : *
250 : * @retval CHIP_NO_ERROR success: address and port extracted.
251 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
252 : * @retval CHIP_ERROR_CONNECTION_ABORTED TCP connection no longer open.
253 : * @retval CHIP_ERROR_NOT_IMPLEMENTED system implementation not complete.
254 : *
255 : * @retval other another system or platform error
256 : */
257 : virtual CHIP_ERROR DisableKeepAlive() = 0;
258 :
259 : /**
260 : * @brief Acknowledge receipt of message text.
261 : *
262 : * @param[in] len number of bytes to acknowledge.
263 : *
264 : * @retval CHIP_NO_ERROR success: reception acknowledged.
265 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
266 : * @retval CHIP_ERROR_CONNECTION_ABORTED TCP connection no longer open.
267 : *
268 : * @details
269 : * Use this method to acknowledge reception of all or part of the data
270 : * received. The operational semantics are undefined if \c len is larger
271 : * than the total outstanding unacknowledged received data.
272 : */
273 : virtual CHIP_ERROR AckReceive(size_t len) = 0;
274 :
275 : /**
276 : * @brief Set the receive queue, for testing.
277 : *
278 : * @param[out] data Message text to push.
279 : *
280 : * @retval CHIP_NO_ERROR success: reception acknowledged.
281 : * @retval CHIP_ERROR_INCORRECT_STATE TCP connection not established.
282 : *
283 : * @details
284 : * This method may only be called by data reception event handlers to
285 : * put data on the receive queue for unit test purposes.
286 : */
287 : CHIP_ERROR SetReceivedDataForTesting(chip::System::PacketBufferHandle && data);
288 :
289 : /**
290 : * @brief Extract the length of the data awaiting first transmit.
291 : *
292 : * @return Number of untransmitted bytes in the transmit queue.
293 : */
294 : size_t PendingSendLength();
295 :
296 : /**
297 : * @brief Extract the length of the unacknowledged receive data.
298 : *
299 : * @return Number of bytes in the receive queue that have not yet been
300 : * acknowledged with <tt>AckReceive(uint16_t len)</tt>.
301 : */
302 : size_t PendingReceiveLength();
303 :
304 : /**
305 : * @brief Initiate TCP half close, in other words, finished with sending.
306 : */
307 : void Shutdown();
308 :
309 : /**
310 : * @brief Initiate TCP full close, in other words, finished with both send and
311 : * receive.
312 : */
313 : void Close();
314 :
315 : /**
316 : * @brief Abortively close the endpoint, in other words, send RST packets.
317 : */
318 : void Abort();
319 :
320 : /**
321 : * @brief Initiate (or continue) TCP full close, ignoring errors.
322 : *
323 : * @details
324 : * The object is returned to the free pool, and all remaining user
325 : * references are subsequently invalid.
326 : */
327 : void Free();
328 :
329 : /**
330 : * @brief Extract whether TCP connection is established.
331 : */
332 180 : bool IsConnected() const { return IsConnected(mState); }
333 :
334 : /**
335 : * Set timeout for Connect to succeed or return an error.
336 : */
337 10 : void SetConnectTimeout(const uint32_t connTimeoutMsecs) { mConnectTimeoutMsecs = connTimeoutMsecs; }
338 :
339 : #if INET_TCP_IDLE_CHECK_INTERVAL > 0
340 : /**
341 : * @brief Set timer event for idle activity.
342 : *
343 : * @param[in] timeoutMS The timeout in milliseconds
344 : *
345 : * @details
346 : * Set the idle timer interval to \c timeoutMS milliseconds. A zero
347 : * time interval implies the idle timer is disabled.
348 : */
349 : void SetIdleTimeout(uint32_t timeoutMS);
350 : #endif // INET_TCP_IDLE_CHECK_INTERVAL > 0
351 :
352 : /**
353 : * @brief Note activity, in other words, reset the idle timer.
354 : *
355 : * @details
356 : * Reset the idle timer to zero.
357 : */
358 29 : void MarkActive()
359 : {
360 : #if INET_TCP_IDLE_CHECK_INTERVAL > 0
361 29 : mRemainingIdleTime = mIdleTimeout;
362 : #endif // INET_TCP_IDLE_CHECK_INTERVAL > 0
363 29 : }
364 :
365 : /**
366 : * @brief Set the TCP TCP_USER_TIMEOUT socket option.
367 : *
368 : * @param[in] userTimeoutMillis Tcp user timeout value in milliseconds.
369 : *
370 : * @retval CHIP_NO_ERROR success: address and port extracted.
371 : * @retval CHIP_ERROR_NOT_IMPLEMENTED system implementation not complete.
372 : *
373 : * @retval other another system or platform error
374 : *
375 : * @details
376 : * When the value is greater than 0, it specifies the maximum amount of
377 : * time in milliseconds that transmitted data may remain
378 : * unacknowledged before TCP will forcibly close the
379 : * corresponding connection. If the option value is specified as 0,
380 : * TCP will to use the system default.
381 : * See RFC 5482, for further details.
382 : *
383 : * @note
384 : * This method can only be called when the endpoint is in one of the connected states.
385 : *
386 : * This method can be called multiple times to adjust the keepalive interval or timeout
387 : * count.
388 : */
389 : CHIP_ERROR SetUserTimeout(uint32_t userTimeoutMillis);
390 :
391 : /**
392 : * @brief Type of connection establishment event handling function.
393 : *
394 : * @param[in] endPoint The TCP endpoint associated with the event.
395 : * @param[in] err \c CHIP_NO_ERROR if success, else another code.
396 : *
397 : * @details
398 : * Provide a function of this type to the \c OnConnectComplete delegate
399 : * member to process connection establishment events on \c endPoint. The
400 : * \c err argument distinguishes successful connections from failures.
401 : */
402 : typedef void (*OnConnectCompleteFunct)(TCPEndPoint * endPoint, CHIP_ERROR err);
403 :
404 : /**
405 : * The endpoint's connection establishment event handling function
406 : * delegate.
407 : */
408 : OnConnectCompleteFunct OnConnectComplete;
409 :
410 : /**
411 : * @brief Type of data reception event handling function.
412 : *
413 : * @param[in] endPoint The TCP endpoint associated with the event.
414 : * @param[in] data The data received.
415 : *
416 : * @retval CHIP_NO_ERROR If the received data can be handled by higher layers.
417 : * @retval other If the received data can not be used, and higher layers will not see it.
418 : *
419 : * @details
420 : * Provide a function of this type to the \c OnDataReceived delegate
421 : * member to process data reception events on \c endPoint where \c data
422 : * is the message text received.
423 : *
424 : * If this function returns an error, the connection will be closed, since higher layers
425 : * are not able to process the data for a better response.
426 : */
427 : typedef CHIP_ERROR (*OnDataReceivedFunct)(TCPEndPoint * endPoint, chip::System::PacketBufferHandle && data);
428 :
429 : /**
430 : * The endpoint's message text reception event handling function delegate.
431 : */
432 : OnDataReceivedFunct OnDataReceived;
433 :
434 : /**
435 : * @brief Type of data transmission event handling function.
436 : *
437 : * @param[in] endPoint The TCP endpoint associated with the event.
438 : * @param[in] len Number of bytes added to the transmit window.
439 : *
440 : * @details
441 : * Provide a function of this type to the \c OnDataSent delegate
442 : * member to process data transmission events on \c endPoint where \c len
443 : * is the length of the message text added to the TCP transmit window,
444 : * which are eligible for sending by the underlying network stack.
445 : */
446 : typedef void (*OnDataSentFunct)(TCPEndPoint * endPoint, size_t len);
447 :
448 : /**
449 : * The endpoint's message text transmission event handling function
450 : * delegate.
451 : */
452 : OnDataSentFunct OnDataSent;
453 :
454 : /**
455 : * @brief Type of connection establishment event handling function.
456 : *
457 : * @param[in] endPoint The TCP endpoint associated with the event.
458 : * @param[in] err \c CHIP_NO_ERROR if success, else another code.
459 : *
460 : * @details
461 : * Provide a function of this type to the \c OnConnectionClosed delegate
462 : * member to process connection termination events on \c endPoint. The
463 : * \c err argument distinguishes successful terminations from failures.
464 : */
465 : typedef void (*OnConnectionClosedFunct)(TCPEndPoint * endPoint, CHIP_ERROR err);
466 :
467 : /** The endpoint's close event handling function delegate. */
468 : OnConnectionClosedFunct OnConnectionClosed;
469 :
470 : /**
471 : * @brief Type of half-close reception event handling function.
472 : *
473 : * @param[in] endPoint The TCP endpoint associated with the event.
474 : *
475 : * @details
476 : * Provide a function of this type to the \c OnPeerClose delegate member
477 : * to process connection termination events on \c endPoint.
478 : */
479 : typedef void (*OnPeerCloseFunct)(TCPEndPoint * endPoint);
480 :
481 : /** The endpoint's half-close receive event handling function delegate. */
482 : OnPeerCloseFunct OnPeerClose;
483 :
484 : /**
485 : * @brief Type of connection received event handling function.
486 : *
487 : * @param[in] listeningEndPoint The listening TCP endpoint.
488 : * @param[in] conEndPoint The newly received TCP endpoint.
489 : * @param[in] peerAddr The IP address of the remote peer.
490 : * @param[in] peerPort The TCP port of the remote peer.
491 : *
492 : * @details
493 : * Provide a function of this type to the \c OnConnectionReceived delegate
494 : * member to process connection reception events on \c listeningEndPoint.
495 : * The newly received endpoint \c conEndPoint is located at IP address
496 : * \c peerAddr and TCP port \c peerPort.
497 : */
498 : typedef void (*OnConnectionReceivedFunct)(TCPEndPoint * listeningEndPoint, TCPEndPoint * conEndPoint,
499 : const IPAddress & peerAddr, uint16_t peerPort);
500 :
501 : /** The endpoint's connection receive event handling function delegate. */
502 : OnConnectionReceivedFunct OnConnectionReceived;
503 :
504 : /**
505 : * @brief Type of connection acceptance error event handling function.
506 : *
507 : * @param[in] endPoint The TCP endpoint associated with the event.
508 : * @param[in] err The reason for the error.
509 : *
510 : * @details
511 : * Provide a function of this type to the \c OnAcceptError delegate
512 : * member to process connection acceptance error events on \c endPoint. The
513 : * \c err argument provides specific detail about the type of the error.
514 : */
515 : typedef void (*OnAcceptErrorFunct)(TCPEndPoint * endPoint, CHIP_ERROR err);
516 :
517 : /**
518 : * The endpoint's connection acceptance event handling function delegate.
519 : */
520 : OnAcceptErrorFunct OnAcceptError;
521 :
522 : /**
523 : * Size of the largest TCP packet that can be received.
524 : */
525 : constexpr static size_t kMaxReceiveMessageSize = System::PacketBuffer::kMaxAllocSize;
526 :
527 : protected:
528 : friend class TCPTest;
529 :
530 : TCPEndPoint(EndPointManager<TCPEndPoint> & endPointManager) :
531 : EndPointBasis(endPointManager), OnConnectComplete(nullptr), OnDataReceived(nullptr), OnDataSent(nullptr),
532 : OnConnectionClosed(nullptr), OnPeerClose(nullptr), OnConnectionReceived(nullptr), OnAcceptError(nullptr),
533 : mState(State::kReady), mReceiveEnabled(true), mConnectTimeoutMsecs(0) // Initialize to zero for using system defaults.
534 : #if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
535 : ,
536 : mUserTimeoutMillis(INET_CONFIG_DEFAULT_TCP_USER_TIMEOUT_MSEC), mUserTimeoutTimerRunning(false)
537 : #endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
538 : {}
539 :
540 34 : virtual ~TCPEndPoint() = default;
541 :
542 : /**
543 : * Basic dynamic state of the underlying endpoint.
544 : *
545 : * Objects are initialized in the "ready" state, proceed to subsequent
546 : * states corresponding to a simplification of the states of the TCP
547 : * transport state machine.
548 : */
549 : enum class State : uint8_t
550 : {
551 : kReady = 0, /**< Endpoint initialized, but not bound. */
552 : kBound = 1, /**< Endpoint bound, but not listening. */
553 : kListening = 2, /**< Endpoint receiving connections. */
554 : kConnecting = 3, /**< Endpoint attempting to connect. */
555 : kConnected = 4, /**< Endpoint connected, ready for tx/rx. */
556 : kSendShutdown = 5, /**< Endpoint initiated its half-close. */
557 : kReceiveShutdown = 6, /**< Endpoint responded to half-close. */
558 : kClosing = 7, /**< Endpoint closing bidirectionally. */
559 : kClosed = 8 /**< Endpoint closed, ready for release. */
560 : } mState;
561 :
562 : /** Control switch indicating whether the application is receiving data. */
563 : bool mReceiveEnabled;
564 :
565 : chip::System::PacketBufferHandle mRcvQueue;
566 : chip::System::PacketBufferHandle mSendQueue;
567 : #if INET_TCP_IDLE_CHECK_INTERVAL > 0
568 : static void HandleIdleTimer(System::Layer * aSystemLayer, void * aAppState);
569 : static bool IsIdleTimerRunning(EndPointManager<TCPEndPoint> & endPointManager);
570 : uint16_t mIdleTimeout; // in units of INET_TCP_IDLE_CHECK_INTERVAL; zero means no timeout
571 : uint16_t mRemainingIdleTime; // in units of INET_TCP_IDLE_CHECK_INTERVAL
572 : #endif // INET_TCP_IDLE_CHECK_INTERVAL > 0
573 :
574 : uint32_t mConnectTimeoutMsecs; // This is the timeout to wait for a Connect call to succeed or
575 : // return an error; zero means use system defaults.
576 :
577 : #if INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
578 : uint32_t mUserTimeoutMillis; // The configured TCP user timeout value in milliseconds.
579 : // If 0, assume not set.
580 : bool mUserTimeoutTimerRunning; // Indicates whether the TCP UserTimeout timer has been started.
581 :
582 : static void TCPUserTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState);
583 : virtual void TCPUserTimeoutHandler() = 0;
584 :
585 : void StartTCPUserTimeoutTimer();
586 : void StopTCPUserTimeoutTimer();
587 : void RestartTCPUserTimeoutTimer();
588 : void ScheduleNextTCPUserTimeoutPoll(uint32_t aTimeOut);
589 : #endif // INET_CONFIG_OVERRIDE_SYSTEM_TCP_USER_TIMEOUT
590 :
591 : TCPEndPoint(const TCPEndPoint &) = delete;
592 :
593 : CHIP_ERROR DriveSending();
594 : void DriveReceiving();
595 : void HandleConnectComplete(CHIP_ERROR err);
596 : void HandleAcceptError(CHIP_ERROR err);
597 : void DoClose(CHIP_ERROR err, bool suppressCallback);
598 : static bool IsConnected(State state);
599 :
600 : static void TCPConnectTimeoutHandler(chip::System::Layer * aSystemLayer, void * aAppState);
601 :
602 : void StartConnectTimerIfSet();
603 : void StopConnectTimer();
604 :
605 : friend class TCPEndPointDeletor;
606 :
607 : /*
608 : * Implementation helpers for shared methods.
609 : */
610 : virtual CHIP_ERROR BindImpl(IPAddressType addrType, const IPAddress & addr, uint16_t port, bool reuseAddr) = 0;
611 : virtual CHIP_ERROR ListenImpl(uint16_t backlog) = 0;
612 : virtual CHIP_ERROR ConnectImpl(const IPAddress & addr, uint16_t port, InterfaceId intfId) = 0;
613 : virtual CHIP_ERROR SendQueuedImpl(bool queueWasEmpty) = 0;
614 : virtual CHIP_ERROR SetUserTimeoutImpl(uint32_t userTimeoutMillis) = 0;
615 : virtual CHIP_ERROR DriveSendingImpl() = 0;
616 : virtual void HandleConnectCompleteImpl() = 0;
617 : virtual void DoCloseImpl(CHIP_ERROR err, State oldState) = 0;
618 : };
619 :
620 : template <>
621 : struct EndPointProperties<TCPEndPoint>
622 : {
623 : static constexpr char kName[] = "TCP";
624 : static constexpr size_t kNumEndPoints = INET_CONFIG_NUM_TCP_ENDPOINTS;
625 : static constexpr int kSystemStatsKey = System::Stats::kInetLayer_NumTCPEps;
626 : };
627 :
628 : } // namespace Inet
629 : } // namespace chip
|