Commit 589f752d authored by Pavel Vainerman's avatar Pavel Vainerman

[Переход на libPoco]: рефакторинг: чистка от лишних функций

parent 2d036c4c
......@@ -24,18 +24,10 @@ class UTCPSocket:
// return true if OK
bool setKeepAliveParams( timeout_t timeout_sec = 5, int conn_keepcnt = 1, int keepintvl = 2 );
/*!
* Enable/disable delaying packets (Nagle algorithm)
*
* @return true on success.
* @param enable disable Nagle algorithm when set to true.
*/
bool setNoDelay( bool enable );
int getSocket();
protected:
void init( bool throwflag = false );
void init();
private:
......
......@@ -45,23 +45,7 @@ class UTCPStream:
bool isSetLinger() const;
void forceDisconnect(); // disconnect() без ожидания (с отключением SO_LINGER)
/*!
* Enable/disable delaying packets (Nagle algorithm)
*
* @return true on success.
* @param enable disable Nagle algorithm when set to true.
*/
bool setNoDelay(bool enable);
// --------------------------------------------------------------------
// Пришлось вынести эти функции read/write[Data] в public
// т.к. они сразу "посылают" данные в канал, в отличие от operator<<
// который у TCPStream (или std::iostream?) буферизует их и из-за этого
// не позволяет работать с отправкой коротких сообщений
// --------------------------------------------------------------------
ssize_t writeData( const void* buf, size_t len, timeout_t t = 0 );
ssize_t readData( void* buf, size_t len, char separator = 0, timeout_t t = 0 );
int getSocket() const;
timeout_t getTimeout() const;
......
......@@ -12,9 +12,9 @@ namespace ModbusTCPCore
// Если соединение закрыто (другой стороной), функции выкидывают исключение UniSetTypes::CommFailed
// t - msec (сколько ждать)
size_t readNextData( UTCPStream* tcp, std::queue<unsigned char>& qrecv, size_t max = 100, timeout_t t = 50 );
size_t getNextData( UTCPStream* tcp, std::queue<unsigned char>& qrecv, unsigned char* buf, size_t len, timeout_t t = 50 );
ModbusRTU::mbErrCode sendData(UTCPStream* tcp, unsigned char* buf, size_t len, timeout_t t = 50 );
size_t readNextData(UTCPStream* tcp, std::queue<unsigned char>& qrecv, size_t max = 100);
size_t getNextData( UTCPStream* tcp, std::queue<unsigned char>& qrecv, unsigned char* buf, size_t len );
ModbusRTU::mbErrCode sendData(UTCPStream* tcp, unsigned char* buf, size_t len );
// работа напрямую с сокетом
size_t readDataFD(int fd, std::queue<unsigned char>& qrecv, size_t max = 100, size_t attempts = 1 );
......
......@@ -25,7 +25,7 @@ using namespace ModbusRTU;
#define DEFAULT_BUFFER_SIZE_FOR_READ 255
// -------------------------------------------------------------------------
size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
std::queue<unsigned char>& qrecv, size_t max, timeout_t t )
std::queue<unsigned char>& qrecv, size_t max )
{
if( !tcp ) // || !tcp->available() )
return 0;
......@@ -44,7 +44,7 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
try
{
ssize_t l = tcp->readData(buf, max, 0, t);
ssize_t l = tcp->receiveBytes(buf, max);
if( l > 0 )
{
......@@ -101,7 +101,7 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
// ------------------------------------------------------------------------
size_t ModbusTCPCore::getNextData(UTCPStream* tcp,
std::queue<unsigned char>& qrecv,
unsigned char* buf, size_t len, timeout_t t )
unsigned char* buf, size_t len)
{
if( qrecv.empty() || qrecv.size() < len )
{
......@@ -111,7 +111,7 @@ size_t ModbusTCPCore::getNextData(UTCPStream* tcp,
if( len <= 0 )
len = 7;
size_t ret = ModbusTCPCore::readNextData(tcp, qrecv, len, t);
size_t ret = ModbusTCPCore::readNextData(tcp, qrecv, len);
if( ret == 0 )
return 0;
......@@ -223,14 +223,14 @@ size_t ModbusTCPCore::getDataFD( int fd, std::queue<unsigned char>& qrecv,
return i;
}
// -------------------------------------------------------------------------
mbErrCode ModbusTCPCore::sendData( UTCPStream* tcp, unsigned char* buf, size_t len, timeout_t t )
mbErrCode ModbusTCPCore::sendData(UTCPStream* tcp, unsigned char* buf, size_t len )
{
if( !tcp ) // || !tcp->available() )
return erTimeOut;
try
{
ssize_t l = tcp->writeData(buf, len, t);
ssize_t l = tcp->sendBytes(buf, len);
if( l == len )
return erNoError;
......
......@@ -50,7 +50,7 @@ ModbusTCPMaster::~ModbusTCPMaster()
// -------------------------------------------------------------------------
size_t ModbusTCPMaster::getNextData( unsigned char* buf, size_t len )
{
return ModbusTCPCore::getNextData(tcp.get(), qrecv, buf, len, readTimeout );
return ModbusTCPCore::getNextData(tcp.get(), qrecv, buf, len );
}
// -------------------------------------------------------------------------
void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
......
......@@ -49,7 +49,7 @@ ModbusTCPServer::ModbusTCPServer( const std::string& ia, int _port ):
ModbusTCPServer::~ModbusTCPServer()
{
}
// --------------------w-----------------------------------------------------
// -------------------------------------------------------------------------
void ModbusTCPServer::setMaxSessions( size_t num )
{
if( num < sessCount )
......
......@@ -23,21 +23,6 @@ UTCPSocket::UTCPSocket()
UTCPSocket::UTCPSocket( int sock ):
Poco::Net::ServerSocket(sock)
{
/*
struct sockaddr_in client_addr;
socklen_t client_len = sizeof(client_addr);
so = accept(sock, (struct sockaddr*)&client_addr, &client_len);
if( so < 0 )
{
endServerServerSocket();
error(errConnectRejected);
return;
}
ServerServerSocket::state = CONNECTED;
*/
init();
}
// -------------------------------------------------------------------------
......@@ -52,20 +37,13 @@ bool UTCPSocket::setKeepAliveParams(timeout_t timeout_sec, int keepcnt, int keep
return UTCPCore::setKeepAliveParams(Poco::Net::ServerSocket::sockfd() , timeout_sec, keepcnt, keepintvl);
}
// -------------------------------------------------------------------------
bool UTCPSocket::setNoDelay(bool enable)
{
Poco::Net::ServerSocket::setNoDelay(enable);
return ( Poco::Net::ServerSocket::getNoDelay() == enable );
}
// -------------------------------------------------------------------------
int UTCPSocket::getSocket()
{
return Poco::Net::ServerSocket::sockfd();
}
// -------------------------------------------------------------------------
void UTCPSocket::init( bool throwflag )
void UTCPSocket::init()
{
// setError(throwflag);
Poco::Net::ServerSocket::setKeepAlive(true);
Poco::Net::ServerSocket::setLinger(true,1);
setKeepAliveParams();
......
......@@ -73,22 +73,6 @@ void UTCPStream::forceDisconnect()
}
}
// -------------------------------------------------------------------------
bool UTCPStream::setNoDelay(bool enable)
{
Poco::Net::StreamSocket::setNoDelay(enable);
return (Poco::Net::StreamSocket::getNoDelay() == enable);
}
// -------------------------------------------------------------------------
ssize_t UTCPStream::writeData(const void* buf, size_t len, timeout_t t)
{
return Poco::Net::StreamSocket::sendBytes(buf, len);
}
// -------------------------------------------------------------------------
ssize_t UTCPStream::readData(void* buf, size_t len, char separator, timeout_t t)
{
return Poco::Net::StreamSocket::receiveBytes(buf, len);
}
// -------------------------------------------------------------------------
int UTCPStream::getSocket() const
{
return Poco::Net::StreamSocket::sockfd();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment