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