TcpClientTransport.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * TcpClientTransport.h
8  *
9  * @author 2021 Slavey Karadzhov <slav@attachix.com>
10  *
11  *
12  ****/
13 
14 #pragma once
15 
16 #include <Network/TcpClient.h>
17 #include "TcpTransport.h"
18 #include "TcpClientStream.h"
19 
20 namespace Hosted
21 {
22 namespace Transport
23 {
25 {
26 public:
28  {
30  stream = new TcpClientStream(client);
31  }
32 
34  {
35  delete stream;
36  }
37 
38 protected:
39  bool process(TcpClient& client, char* data, int size) override
40  {
41  if(!stream.push(data, size)) {
42  return false;
43  }
44 
45  return handler(*stream);
46  }
47 
48 private:
49  TcpClientStream* stream = nullptr;
50 };
51 
52 } // namespace Transport
53 
54 } // namespace Hosted
void setReceiveDelegate(TcpClientDataDelegate receiveCb=nullptr)
Set or clear the callback for received data.
Definition: TcpClient.h:90
TcpClientTransport(TcpClient &client)
Definition: TcpClientTransport.h:27
~TcpClientTransport()
Definition: TcpClientTransport.h:33
Definition: Components/Hosted/include/Hosted/Client.h:31
DataHandler handler
Definition: BaseTransport.h:38
Definition: TcpClient.h:46
Definition: TcpTransport.h:23
bool push(const uint8_t *buffer, size_t size)
Definition: TcpClientStream.h:37
Definition: TcpClientTransport.h:24
Delegate< bool(TcpClient &client, char *data, int size)> TcpClientDataDelegate
Definition: TcpClient.h:27
bool process(TcpClient &client, char *data, int size) override
Definition: TcpClientTransport.h:39
Definition: TcpClientStream.h:23