2 #ifndef ModbusTCPSession_H_
3 #define ModbusTCPSession_H_
7 #include <unordered_map>
9 #include "ModbusServerSlot.h"
10 #include "ModbusServer.h"
11 #include "PassiveTimer.h"
13 #include "UTCPStream.h"
39 ModbusTCPSession(
const Poco::Net::StreamSocket& s,
const std::unordered_set<ModbusRTU::ModbusAddr>& vmbaddr, timeout_t timeout );
42 void cleanInputStream();
44 virtual void cleanupChannel()
override;
45 virtual void terminate()
override;
47 typedef sigc::slot<void, const ModbusTCPSession*> FinalSlot;
49 void connectFinalSession( FinalSlot sl );
51 inline std::string getClientAddress()
const
56 void setSessionTimeout(
double t );
59 void run( ev::loop_ref& loop );
61 virtual bool isActive()
const override;
63 void iowait( timeout_t msec );
67 virtual ModbusRTU::mbErrCode
realReceive(
const std::unordered_set<ModbusRTU::ModbusAddr>& vmbaddr, timeout_t msecTimeout )
override;
69 void callback( ev::io& watcher,
int revents );
70 void onTimeout( ev::timer& watcher,
int revents );
71 virtual void readEvent( ev::io& watcher );
72 virtual void writeEvent( ev::io& watcher );
75 virtual size_t getNextData(
unsigned char* buf,
int len )
override;
77 virtual ModbusRTU::mbErrCode sendData(
unsigned char* buf,
int len )
override;
125 std::queue<unsigned char> qrecv;
126 std::unordered_set<ModbusRTU::ModbusAddr> vaddr;
129 timeout_t timeout = { 0 };
135 std::shared_ptr<UTCPStream> sock;
136 std::queue<UTCPCore::Buffer*> qsend;
137 double sessTimeout = { 10.0 };
139 bool ignoreAddr = {
false };
140 std::string peername = {
"" };
142 std::string caddr = {
"" };
146 std::atomic_bool cancelled = {
false };
153 #endif // ModbusTCPSession_H_