friendev EtherDune TCP/IP library
/home/jander/temp/etherdune/TCPSocket.h
Go to the documentation of this file.
1 // EtherDune TCP implementation as a NetworkService
2 // Author: Javier Peletier <jm@friendev.com>
3 // Summary: Implements the TCP protocol
4 //
5 // Copyright (c) 2015 All Rights Reserved, http://friendev.com
6 //
7 // This source is subject to the GPLv2 license.
8 // Please see the License.txt file for more information.
9 // All other rights reserved.
10 //
11 // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
12 // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13 // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
14 // PARTICULAR PURPOSE.
15 
34 #ifndef _TCPSOCKET_H_
35 #define _TCPSOCKET_H_
36 
37 #include <ACross.h>
38 
39 #include "Socket.h"
40 #include "Stateful.h"
41 
42 class TCPSocket;
43 
44 
45 class TCPSocket : public Socket, public Stateful
46 {
47 
48 private:
49 
50  uint32_t sequenceNumber;
51  uint32_t ackNumber;
52  TCPFlags nextFlags;
53 
54  bool onPacketReceived();
55  void processOutgoingBuffer();
56  void prepareTCPPacket(bool options, uint16_t dataLength);
57  void releaseWindow(int32_t& bytesAck);
58  void tick();
59  void sendSYN(bool ack);
60  __FlashStringHelper* getStateString();
61 
62 public:
63 
64  TCPSocket();
65 
66  void connect();
67  void close();
68  void terminate();
69  void listen();
70  void accept();
71  void accept(TCPSocket& listener);
72  void push();
73 
74  virtual void onConnect();
75  virtual void onConnectRequest();
76  virtual void onClose();
77  virtual void onReceive(uint16_t len, const byte* data);
78  virtual void onTerminate();
79 
80 };
81 
82 
83 
84 #endif
virtual void onConnectRequest()
Called when a listening socket receives a connection request.
Definition: TCPSocket.cpp:44
virtual void onConnect()
Fires when the socket connection is established.
Definition: TCPSocket.cpp:39
void push()
Sets the PSH TCP flag and also sends data in the outgoing buffer immediately.
Definition: TCPSocket.cpp:498
void listen()
Starts listening on the local port indicated by the localPort property.
Definition: TCPSocket.cpp:91
void connect()
Initiates a TCP connection to remoteIP and remotePort.
Definition: TCPSocket.cpp:71
Maintains a state variable and allows to pull out a state string representation for debugging...
Definition: Stateful.h:31
Implements the TCP protocol.
Definition: TCPSocket.h:45
Base class for TCP and UDP sockets.
Definition: Socket.h:37
TCP flags data structure.
Definition: inet.h:328
void terminate()
Immediately shuts down the socket and makes it available for a new task.
Definition: TCPSocket.cpp:183
virtual void onTerminate()
Called when the socket is ready to be reused.
Definition: TCPSocket.cpp:54
void close()
Attempts to gracefully close a connection.
Definition: TCPSocket.cpp:194
void accept()
Accepts a connection request that has been received on the port this instance was listening on ...
Definition: TCPSocket.cpp:101
virtual void onReceive(uint16_t len, const byte *data)
Called for each data packet received
Definition: TCPSocket.cpp:50
virtual void onClose()
Fires when the other party closed the incoming end of the connection because it has no more data to s...
Definition: TCPSocket.cpp:31