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 #include <memory>
20 
21 namespace Hosted::Transport
22 {
24 {
25 public:
26  TcpClientTransport(TcpClient& client) : stream(std::make_unique<TcpClientStream>(client))
27  {
29  }
30 
31 protected:
32  bool process(TcpClient& client, char* data, int size) override
33  {
34  if(!stream.push(data, size)) {
35  return false;
36  }
37 
38  return handler(*stream);
39  }
40 
41 private:
42  std::unique_ptr<TcpClientStream> stream;
43 };
44 
45 } // namespace Hosted::Transport
DataHandler handler
Definition: BaseTransport.h:36
Definition: TcpClientStream.h:22
Definition: TcpClientTransport.h:24
bool process(TcpClient &client, char *data, int size) override
Definition: TcpClientTransport.h:32
TcpClientTransport(TcpClient &client)
Definition: TcpClientTransport.h:26
Definition: TcpTransport.h:22
Definition: TcpClient.h:46
void setReceiveDelegate(TcpClientDataDelegate receiveCb=nullptr)
Set or clear the callback for received data.
Definition: TcpClient.h:89
Delegate< bool(TcpClient &client, char *data, int size)> TcpClientDataDelegate
Definition: TcpClient.h:26
Definition: BaseTransport.h:20