Simplify the networking code a little.

This commit is contained in:
Jonathan Naylor 2020-11-04 12:14:31 +00:00
parent bfbdfea30b
commit 14da695e8e
6 changed files with 5 additions and 27 deletions

View File

@ -41,7 +41,6 @@ m_file(file),
m_callsign(), m_callsign(),
m_rptAddress(), m_rptAddress(),
m_rptPort(0U), m_rptPort(0U),
m_myAddress(),
m_myPort(0U), m_myPort(0U),
m_debug(false), m_debug(false),
m_daemon(false), m_daemon(false),
@ -143,8 +142,6 @@ bool CConf::read()
m_rptAddress = value; m_rptAddress = value;
else if (::strcmp(key, "RptPort") == 0) else if (::strcmp(key, "RptPort") == 0)
m_rptPort = (unsigned int)::atoi(value); m_rptPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "LocalAddress") == 0)
m_myAddress = value;
else if (::strcmp(key, "LocalPort") == 0) else if (::strcmp(key, "LocalPort") == 0)
m_myPort = (unsigned int)::atoi(value); m_myPort = (unsigned int)::atoi(value);
else if (::strcmp(key, "Debug") == 0) else if (::strcmp(key, "Debug") == 0)
@ -232,11 +229,6 @@ unsigned int CConf::getRptPort() const
return m_rptPort; return m_rptPort;
} }
std::string CConf::getMyAddress() const
{
return m_myAddress;
}
unsigned int CConf::getMyPort() const unsigned int CConf::getMyPort() const
{ {
return m_myPort; return m_myPort;

View File

@ -34,7 +34,6 @@ public:
std::string getCallsign() const; std::string getCallsign() const;
std::string getRptAddress() const; std::string getRptAddress() const;
unsigned int getRptPort() const; unsigned int getRptPort() const;
std::string getMyAddress() const;
unsigned int getMyPort() const; unsigned int getMyPort() const;
bool getDebug() const; bool getDebug() const;
bool getDaemon() const; bool getDaemon() const;
@ -78,7 +77,6 @@ private:
std::string m_callsign; std::string m_callsign;
std::string m_rptAddress; std::string m_rptAddress;
unsigned int m_rptPort; unsigned int m_rptPort;
std::string m_myAddress;
unsigned int m_myPort; unsigned int m_myPort;
bool m_debug; bool m_debug;
bool m_daemon; bool m_daemon;

View File

@ -189,7 +189,7 @@ void CP25Gateway::run()
return; return;
} }
CRptNetwork localNetwork(m_conf.getMyAddress(), m_conf.getMyPort(), rptAddr, rptAddrLen, m_conf.getCallsign(), m_conf.getDebug()); CRptNetwork localNetwork(m_conf.getMyPort(), rptAddr, rptAddrLen, m_conf.getCallsign(), m_conf.getDebug());
ret = localNetwork.open(); ret = localNetwork.open();
if (!ret) { if (!ret) {
::LogFinalise(); ::LogFinalise();

View File

@ -2,7 +2,6 @@
Callsign=G4KLX Callsign=G4KLX
RptAddress=127.0.0.1 RptAddress=127.0.0.1
RptPort=32010 RptPort=32010
LocalAddress=127.0.0.1
LocalPort=42020 LocalPort=42020
Debug=0 Debug=0
Daemon=1 Daemon=1

View File

@ -24,21 +24,17 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
CRptNetwork::CRptNetwork(const std::string& myAddr, unsigned int myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug) : CRptNetwork::CRptNetwork(unsigned int myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug) :
m_myAddr(),
m_myAddrLen(0U),
m_rptAddr(rptAddr), m_rptAddr(rptAddr),
m_rptAddrLen(rptAddrLen), m_rptAddrLen(rptAddrLen),
m_callsign(callsign), m_callsign(callsign),
m_socket(myAddr, myPort), m_socket(myPort),
m_debug(debug), m_debug(debug),
m_timer(1000U, 5U) m_timer(1000U, 5U)
{ {
assert(myPort > 0U); assert(myPort > 0U);
assert(rptAddrLen > 0U); assert(rptAddrLen > 0U);
CUDPSocket::lookup(myAddr, myPort, m_myAddr, m_myAddrLen);
m_callsign.resize(10U, ' '); m_callsign.resize(10U, ' ');
} }
@ -48,14 +44,9 @@ CRptNetwork::~CRptNetwork()
bool CRptNetwork::open() bool CRptNetwork::open()
{ {
if (m_myAddrLen == 0U) {
LogError("Unable to resolve the local address and port");
return false;
}
LogInfo("Opening Rpt network connection"); LogInfo("Opening Rpt network connection");
bool ret = m_socket.open(m_myAddr); bool ret = m_socket.open(m_rptAddr);
if (ret) { if (ret) {
m_timer.start(); m_timer.start();

View File

@ -27,7 +27,7 @@
class CRptNetwork { class CRptNetwork {
public: public:
CRptNetwork(const std::string& myAddr, unsigned int myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug); CRptNetwork(unsigned int myPort, const sockaddr_storage& rptAddr, unsigned int rptAddrLen, const std::string& callsign, bool debug);
~CRptNetwork(); ~CRptNetwork();
bool open(); bool open();
@ -41,8 +41,6 @@ public:
void close(); void close();
private: private:
sockaddr_storage m_myAddr;
unsigned int m_myAddrLen;
sockaddr_storage m_rptAddr; sockaddr_storage m_rptAddr;
unsigned int m_rptAddrLen; unsigned int m_rptAddrLen;
std::string m_callsign; std::string m_callsign;