A better way to get the family

pull/14/head
Tom Early 7 years ago
parent f2851418d1
commit 7a5e049637

@ -53,7 +53,6 @@ const std::string IRCDDB_VERSION("QnetGateway-9.0");
extern void dstar_dv_init(); extern void dstar_dv_init();
extern int dstar_dv_decode(const unsigned char *d, int data[3]); extern int dstar_dv_decode(const unsigned char *d, int data[3]);
extern std::atomic<int> ircsocketfamily;
static std::atomic<bool> keep_running(true); static std::atomic<bool> keep_running(true);
@ -2424,7 +2423,7 @@ bool CQnetGateway::Init(char *cfgfile)
} }
rc = ii->getConnectionState(); rc = ii->getConnectionState();
} }
switch (ircsocketfamily) { switch (ii->GetFamily()) {
case AF_INET: case AF_INET:
printf("IRC server is using IPV4\n"); printf("IRC server is using IPV4\n");
af_family = AF_INET; af_family = AF_INET;
@ -2434,9 +2433,8 @@ bool CQnetGateway::Init(char *cfgfile)
af_family = AF_INET6; af_family = AF_INET6;
break; break;
default: default:
printf("IRC server is using unknown protocol!\n"); printf("IRC server is using unknown protocol! Shutting down...\n");
af_family = AF_UNSPEC; return true;
break;
} }
/* udp port 40000 must open first */ /* udp port 40000 must open first */

@ -3,13 +3,9 @@
#include <netdb.h> #include <netdb.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <atomic>
#include "IRCClient.h" #include "IRCClient.h"
#include "IRCutils.h" #include "IRCutils.h"
#include "../TCPReaderWriterClient.h"
std::atomic<int> ircsocketfamily;
IRCClient::IRCClient(IRCApplication *app, const std::string &update_channel, const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo) IRCClient::IRCClient(IRCApplication *app, const std::string &update_channel, const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo)
@ -58,7 +54,7 @@ void IRCClient::Entry()
int state = 0; int state = 0;
int timer = 0; int timer = 0;
socklen_t optlen = sizeof(int); socklen_t optlen;
while (true) { while (true) {
@ -85,8 +81,8 @@ void IRCClient::Entry()
case 4: case 4:
optlen = sizeof(int);
getsockopt(ircSock.GetFD(), SOL_SOCKET, SO_DOMAIN, &ircsocketfamily, &optlen); getsockopt(ircSock.GetFD(), SOL_SOCKET, SO_DOMAIN, &family, &optlen);
recvQ = new IRCMessageQueue(); recvQ = new IRCMessageQueue();
sendQ = new IRCMessageQueue(); sendQ = new IRCMessageQueue();
@ -174,3 +170,8 @@ void IRCClient::Entry()
} }
return; return;
} }
int IRCClient::GetFamily()
{
return family;
}

@ -1,6 +1,8 @@
#pragma once #pragma once
#include <future> #include <future>
#include <atomic>
#include "../TCPReaderWriterClient.h"
#include "IRCReceiver.h" #include "IRCReceiver.h"
#include "IRCMessageQueue.h" #include "IRCMessageQueue.h"
@ -15,11 +17,14 @@ public:
virtual ~IRCClient(); virtual ~IRCClient();
bool startWork(); bool startWork();
void stopWork(); void stopWork();
int GetFamily();
protected: protected:
virtual void Entry(); virtual void Entry();
private: private:
std::atomic<int> family;
std::future<void> client_thread;
char host_name[100]; char host_name[100];
char local_addr[100]; char local_addr[100];
unsigned int port; unsigned int port;
@ -32,7 +37,6 @@ private:
IRCMessageQueue *recvQ; IRCMessageQueue *recvQ;
IRCMessageQueue *sendQ; IRCMessageQueue *sendQ;
IRCProtocol *proto; IRCProtocol *proto;
std::future<void> client_thread;
IRCApplication *app; IRCApplication *app;
}; };

@ -27,6 +27,11 @@ CIRCDDB::~CIRCDDB()
delete d; delete d;
} }
int CIRCDDB::GetFamily()
{
return d->client->GetFamily();
}
// A false return implies a network error, or unable to log in // A false return implies a network error, or unable to log in
bool CIRCDDB::open() bool CIRCDDB::open()

@ -24,6 +24,8 @@ public:
CIRCDDB(const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo); CIRCDDB(const std::string &hostName, unsigned int port, const std::string &callsign, const std::string &password, const std::string &versionInfo);
~CIRCDDB(); ~CIRCDDB();
int GetFamily();
// A false return implies a network error, or unable to log in // A false return implies a network error, or unable to log in
bool open(); bool open();

Loading…
Cancel
Save

Powered by TurnKey Linux.