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

@ -3,13 +3,9 @@
#include <netdb.h>
#include <unistd.h>
#include <string.h>
#include <atomic>
#include "IRCClient.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)
@ -58,7 +54,7 @@ void IRCClient::Entry()
int state = 0;
int timer = 0;
socklen_t optlen = sizeof(int);
socklen_t optlen;
while (true) {
@ -85,8 +81,8 @@ void IRCClient::Entry()
case 4:
getsockopt(ircSock.GetFD(), SOL_SOCKET, SO_DOMAIN, &ircsocketfamily, &optlen);
optlen = sizeof(int);
getsockopt(ircSock.GetFD(), SOL_SOCKET, SO_DOMAIN, &family, &optlen);
recvQ = new IRCMessageQueue();
sendQ = new IRCMessageQueue();
@ -174,3 +170,8 @@ void IRCClient::Entry()
}
return;
}
int IRCClient::GetFamily()
{
return family;
}

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

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

Loading…
Cancel
Save

Powered by TurnKey Linux.