1 /* 2 * Copyright (c) 2022, The OpenThread Authors. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the copyright holder nor the 13 * names of its contributors may be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @file 31 * This file includes definitions for TCP/IPv6 socket extensions. 32 */ 33 34 #ifndef TCP6_EXT_HPP_ 35 #define TCP6_EXT_HPP_ 36 37 #include "openthread-core-config.h" 38 39 #include <openthread/tcp_ext.h> 40 41 #include "net/tcp6.hpp" 42 43 namespace ot { 44 namespace Ip6 { 45 46 /** 47 * @addtogroup core-tcp-ext 48 * 49 * @brief 50 * This module includes definitions for TCP/IPv6 socket extensions. 51 * 52 * @{ 53 */ 54 55 /** 56 * Represents a TCP circular send buffer. 57 */ 58 class TcpCircularSendBuffer : public otTcpCircularSendBuffer 59 { 60 public: 61 /** 62 * Initializes a TCP circular send buffer. 63 * 64 * @sa otTcpCircularSendBufferInitialize 65 * 66 * @param[in] aDataBuffer A pointer to memory to use to store data in the TCP circular send buffer. 67 * @param[in] aCapacity The capacity, in bytes, of the TCP circular send buffer, which must equal the size 68 * of the memory pointed to by @p aDataBuffer . 69 */ 70 void Initialize(void *aDataBuffer, size_t aCapacity); 71 72 /** 73 * Sends out data on a TCP endpoint, using this TCP circular send buffer to manage buffering. 74 * 75 * @sa otTcpCircularSendBufferWrite, particularly for guidance on how @p aEndpoint must be chosen. 76 * 77 * @param[in] aEndpoint The TCP endpoint on which to send out data. 78 * @param[in] aData A pointer to data to copy into the TCP circular send buffer. 79 * @param[in] aLength The length of the data pointed to by @p aData to copy into the TCP circular send buffer. 80 * @param[out] aWritten Populated with the amount of data copied into the send buffer, which might be less than 81 * @p aLength if the send buffer reaches capacity. 82 * @param[in] aFlags Flags specifying options for this operation. 83 * 84 * @retval kErrorNone on success, or the error returned by the TCP endpoint on failure. 85 */ 86 Error Write(Tcp::Endpoint &aEndpoint, const void *aData, size_t aLength, size_t &aWritten, uint32_t aFlags); 87 88 /** 89 * Performs circular-send-buffer-specific handling in the otTcpForwardProgress callback. 90 * 91 * @sa otTcpCircularSendBufferHandleForwardProgress 92 * 93 * @param[in] aInSendBuffer Value of @p aInSendBuffer passed to the otTcpForwardProgress() callback. 94 */ 95 void HandleForwardProgress(size_t aInSendBuffer); 96 97 /** 98 * Returns the amount of free space in this TCP circular send buffer. 99 * 100 * @sa otTcpCircularSendBufferFreeSpace 101 * 102 * @return The amount of free space in the send buffer. 103 */ 104 size_t GetFreeSpace(void) const; 105 106 /** 107 * Forcibly discards all data in this TCP circular send buffer. 108 * 109 * @sa otTcpCircularSendBufferForceDiscardAll 110 */ 111 void ForceDiscardAll(void); 112 113 /** 114 * Deinitializes this TCP circular send buffer. 115 * 116 * @sa otTcpCircularSendBufferDeinitialize 117 * 118 * @retval kErrorNone Successfully deinitialized this TCP circular send buffer. 119 * @retval kErrorFailed Failed to deinitialize the TCP circular send buffer. 120 */ 121 Error Deinitialize(void); 122 123 private: 124 size_t GetIndex(size_t aStart, size_t aOffsetFromStart) const; 125 }; 126 127 } // namespace Ip6 128 129 DefineCoreType(otTcpCircularSendBuffer, Ip6::TcpCircularSendBuffer); 130 131 } // namespace ot 132 133 #endif // TCP6_HPP_ 134