X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/46b0747592074017ff0ea4b33d4a7194235886e5..HEAD:/libs/srvconf/netunit.h?ds=inline diff --git a/libs/srvconf/netunit.h b/libs/srvconf/netunit.h index 34d730e1..b9980abe 100644 --- a/libs/srvconf/netunit.h +++ b/libs/srvconf/netunit.h @@ -18,58 +18,56 @@ * Author : Boris Mikhailenko */ -#ifndef NetUnitH -#define NetUnitH - -#include +#pragma once #include +#include namespace STG { -class NETTRANSACT +class NetTransact { -public: - typedef bool (* CALLBACK)(const std::string &, bool, void *); + public: + using Callback = bool (*)(const std::string&, bool, void *); - NETTRANSACT(const std::string & server, uint16_t port, - const std::string & login, const std::string & password); - NETTRANSACT(const std::string & server, uint16_t port, - const std::string & localAddress, uint16_t localPort, - const std::string & login, const std::string & password); - ~NETTRANSACT(); - int Transact(const std::string & request, CALLBACK f, void * data); - const std::string & GetError() const { return errorMsg; } + NetTransact(const std::string& server, uint16_t port, + const std::string& login, const std::string& password); + NetTransact(const std::string& server, uint16_t port, + const std::string& localAddress, uint16_t localPort, + const std::string& login, const std::string& password); + ~NetTransact(); - int Connect(); - void Disconnect(); -private: - int TxHeader(); - int RxHeaderAnswer(); + int Transact(const std::string& request, Callback f, void* data); + const std::string & GetError() const { return m_errorMsg; } - int TxLogin(); - int RxLoginAnswer(); + int Connect(); + void Disconnect(); - int TxLoginS(); - int RxLoginSAnswer(); + private: + int TxHeader(); + int RxHeaderAnswer(); - int TxData(const std::string & text); - int RxDataAnswer(CALLBACK f, void * data); + int TxLogin(); + int RxLoginAnswer(); - std::string server; - uint16_t port; - std::string localAddress; - uint16_t localPort; - std::string login; - std::string password; - int sock; - std::string errorMsg; + int TxLoginS(); + int RxLoginSAnswer(); - static bool TxCrypto(const void * block, size_t size, void * data); - static bool RxCrypto(const void * block, size_t size, void * data); + int TxData(const std::string& text); + int RxDataAnswer(Callback f, void* data); + + std::string m_server; + uint16_t m_port; + std::string m_localAddress; + uint16_t m_localPort; + std::string m_login; + std::string m_password; + int m_sock; + std::string m_errorMsg; + + static bool TxCrypto(const void * block, size_t size, void * data); + static bool RxCrypto(const void * block, size_t size, void * data); }; } // namespace STG - -#endif