6 #ifndef NET_TCP_SOCKET_HPP_
7 #define NET_TCP_SOCKET_HPP_
10 #include "LibLinkedList.hpp"
11 #include "LibStreamOut.hpp"
12 #include "LibStreamIn.hpp"
13 #include "RtosSemaphore.hpp"
14 #include "RtosMsgBox.hpp"
15 #include "LibStringFormat.hpp"
17 class NetTcpSocket:
public LIB_LINKED_LIST_ITERABLE<NetTcpSocket>,
public LibStreamIn,
public LibStreamOut {
21 static uint32_t sStartSequenceCounter;
22 static uint16_t sAutomaticPort;
43 }__attribute__((packed)) RX_SEGMENT_HEADER;
46 RX_SEGMENT_HEADER hdr;
47 uint8_t data[NetDefs::TCP_MAX_DATA_LEN];
48 }__attribute__((packed)) RX_SEGMENT;
52 uint32_t dataChecksum;
61 typedef struct tagTX_SEGMENT {
63 TX_SEGMENT_HEADER hdr;
65 }__attribute__((packed)) TX_SEGMENT;
69 virtual ~NetTcpSocket();
71 bool connect(NetDefs::IP_ADDR& remoteIpAddr, uint16_t remotePort, uint16_t localPort = 0);
72 void listen(NetDefs::TCP_PORT localPort);
73 bool accept(
Rtos::TICK timeout);
74 void autoListenAndAccept(NetDefs::TCP_PORT localPort);
77 void setWindowSize(uint16_t windowsSize);
78 void setMaxTxSegmentDataLen(uint16_t maxTxSegmentDataLen);
80 void discardAllTxSegments();
81 void discardAllRxSegments();
83 virtual
int read(
void* buffer,
int len,
Rtos::TICK timeout =
Rtos::TICK_INFINITE);
84 virtual
int skip(
int len,
Rtos::TICK timeout =
Rtos::TICK_INFINITE);
85 virtual
int write(const
void* buffer,
int len,
Rtos::TICK timeout =
Rtos::TICK_INFINITE);
87 static const
int MAX_QUEUED_TX_SEGMENTS = 8;
88 static const
size_t MAX_TX_FRAGMENT_DATA_SIZE = 512;
89 NetDefs::TCP_PORT mLocalPort;
90 NetDefs::TCP_PORT mRemotePort;
91 NetDefs::IP_ADDR mRemoteIpAddr;
92 NetDefs::MAC_ADDR mRemoteMacAddr;
96 uint16_t mMaxTxSegmentDataLen;
98 RX_SEGMENT* mRxCurrentSegment;
99 TX_SEGMENT* mTxFirstSegment;
100 TX_SEGMENT* mTxCurrentSegment;
109 bool mIsRxDataFinished;
110 bool mIsAutoListenAndAccept;