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 {
26 {
27 public:
28  TcpClientTransport(TcpClient& client) : stream(new TcpClientStream(client))
29  {
31  }
32 
33 protected:
34  bool process(TcpClient& client, char* data, int size) override
35  {
36  if(!stream.push(data, size)) {
37  return false;
38  }
39 
40  return handler(*stream);
41  }
42 
43 private:
44  std::unique_ptr<TcpClientStream> stream;
45 };
46 
47 } // namespace Transport
48 
49 } // namespace Hosted
DataHandler handler
Definition: BaseTransport.h:38
Definition: TcpClientStream.h:24
Definition: TcpClientTransport.h:26
bool process(TcpClient &client, char *data, int size) override
Definition: TcpClientTransport.h:34
TcpClientTransport(TcpClient &client)
Definition: TcpClientTransport.h:28
Definition: TcpTransport.h:24
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: Components/Hosted/include/Hosted/Client.h:32