From b2f8532e25d1c23c997c91e8f006676733519e54 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Wed, 17 Feb 2021 10:54:30 -0500 Subject: [PATCH] 2021-02-17 Fred Gleason * Removed the Q3SocketDevice dependency from 'RDCae'. Signed-off-by: Fred Gleason --- ChangeLog | 2 ++ lib/rdcae.cpp | 38 ++++++++++++++++++++++++++++---------- lib/rdcae.h | 4 +--- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 06ebf3ca..69973dfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21170,3 +21170,5 @@ * Removed the 'Q3Signal' dependency from 'RDCut'. 2021-02-17 Fred Gleason * Removed the Q3SocketDevice dependency for metering data 'RDCae'. +2021-02-17 Fred Gleason + * Removed the Q3SocketDevice dependency from 'RDCae'. diff --git a/lib/rdcae.cpp b/lib/rdcae.cpp index 30a951b8..9f05c15f 100644 --- a/lib/rdcae.cpp +++ b/lib/rdcae.cpp @@ -19,8 +19,11 @@ // #include +#include #include #include +#include +#include #include #include @@ -33,6 +36,8 @@ RDCae::RDCae(RDStation *station,RDConfig *config,QObject *parent) : QObject(parent) { + int flags=-1; + cae_station=station; cae_config=config; cae_connected=false; @@ -42,8 +47,17 @@ RDCae::RDCae(RDStation *station,RDConfig *config,QObject *parent) // // TCP Connection // - cae_socket=new Q3SocketDevice(Q3SocketDevice::Stream); - cae_socket->setBlocking(false); + if((cae_socket=socket(AF_INET,SOCK_STREAM,0))<0) { + rda->syslog(LOG_WARNING,"unable to allocate TCP socket [%s]", + strerror(errno)); + } + if((flags=fcntl(cae_socket,F_GETFL,NULL))>=0) { + flags=flags|O_NONBLOCK; + if(fcntl(cae_socket,F_SETFL,flags)<0) { + rda->syslog(LOG_WARNING,"unable to set TCP socket to non-blocking [%s]", + strerror(errno)); + } + } // // Meter Connection @@ -86,20 +100,24 @@ RDCae::RDCae(RDStation *station,RDConfig *config,QObject *parent) RDCae::~RDCae() { - delete cae_socket; + close(cae_socket); } void RDCae::connectHost() { int count=10; - // QHostAddress addr; - QTimer *timer=new QTimer(this,"read_timer"); + QTimer *timer=new QTimer(this); + struct sockaddr_in sa; connect(timer,SIGNAL(timeout()),this,SLOT(readyData())); timer->start(CAE_POLL_INTERVAL); - while((!cae_socket->connect(cae_station->caeAddress(cae_config), - CAED_TCP_PORT))&&(--count>0)) { + memset(&sa,0,sizeof(sa)); + sa.sin_family=AF_INET; + sa.sin_port=htons(CAED_TCP_PORT); + sa.sin_addr.s_addr=htonl(cae_station->caeAddress(cae_config).toIPv4Address()); + while((::connect(cae_socket,(struct sockaddr *)(&sa),sizeof(sa))!=0)&& + (--count>0)) { usleep(100000); } usleep(100000); @@ -389,7 +407,7 @@ void RDCae::readyData(int *stream,int *handle,QString name) delayed_cmds.clear(); } - while((c=cae_socket->readBlock(buf,256))>0) { + while((c=read(cae_socket,buf,256))>0) { buf[c]=0; for(int i=0;iwriteBlock((const char *)cmd,cmd.length()); + write(cae_socket,cmd.toUtf8(),cmd.toUtf8().length()); } diff --git a/lib/rdcae.h b/lib/rdcae.h index 697b2f5e..58876387 100644 --- a/lib/rdcae.h +++ b/lib/rdcae.h @@ -21,8 +21,6 @@ #ifndef RDCAE_H #define RDCAE_H -#include - #include #include #include @@ -103,7 +101,7 @@ class RDCae : public QObject int StreamNumber(const char *arg); int GetHandle(const char *arg); void UpdateMeters(); - Q3SocketDevice *cae_socket; + int cae_socket; bool debug; char args[CAE_MAX_ARGS][CAE_MAX_LENGTH]; int argnum;