2017-04-17 20:57:07 +02:00
|
|
|
//
|
2017-06-06 03:44:16 +02:00
|
|
|
// libtgvoip is free and unencumbered public domain software.
|
|
|
|
// For more information, see http://unlicense.org or the UNLICENSE file
|
|
|
|
// you should have received with this source code distribution.
|
2017-04-17 20:57:07 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef LIBTGVOIP_NETWORKSOCKETPOSIX_H
|
|
|
|
#define LIBTGVOIP_NETWORKSOCKETPOSIX_H
|
|
|
|
|
|
|
|
#include "../../NetworkSocket.h"
|
2017-06-06 03:44:16 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <pthread.h>
|
2017-04-17 20:57:07 +02:00
|
|
|
|
|
|
|
namespace tgvoip {
|
|
|
|
|
2017-07-03 03:42:49 +02:00
|
|
|
class SocketSelectCancellerPosix : public SocketSelectCanceller{
|
|
|
|
friend class NetworkSocketPosix;
|
|
|
|
public:
|
|
|
|
SocketSelectCancellerPosix();
|
|
|
|
virtual ~SocketSelectCancellerPosix();
|
|
|
|
virtual void CancelSelect();
|
|
|
|
private:
|
|
|
|
int pipeRead;
|
|
|
|
int pipeWrite;
|
2017-06-06 03:44:16 +02:00
|
|
|
};
|
|
|
|
|
2017-04-17 20:57:07 +02:00
|
|
|
class NetworkSocketPosix : public NetworkSocket{
|
|
|
|
public:
|
2017-07-03 03:42:49 +02:00
|
|
|
NetworkSocketPosix(NetworkProtocol protocol);
|
2017-04-17 20:57:07 +02:00
|
|
|
virtual ~NetworkSocketPosix();
|
|
|
|
virtual void Send(NetworkPacket* packet);
|
|
|
|
virtual void Receive(NetworkPacket* packet);
|
|
|
|
virtual void Open();
|
|
|
|
virtual void Close();
|
2017-07-03 03:42:49 +02:00
|
|
|
virtual void Connect(NetworkAddress* address, uint16_t port);
|
2017-04-17 20:57:07 +02:00
|
|
|
virtual std::string GetLocalInterfaceInfo(IPv4Address* v4addr, IPv6Address* v6addr);
|
|
|
|
virtual void OnActiveInterfaceChanged();
|
|
|
|
virtual uint16_t GetLocalPort();
|
|
|
|
|
|
|
|
static std::string V4AddressToString(uint32_t address);
|
|
|
|
static std::string V6AddressToString(unsigned char address[16]);
|
|
|
|
static uint32_t StringToV4Address(std::string address);
|
|
|
|
static void StringToV6Address(std::string address, unsigned char* out);
|
2017-07-03 03:42:49 +02:00
|
|
|
static IPv4Address* ResolveDomainName(std::string name);
|
|
|
|
static bool Select(std::vector<NetworkSocket*>& readFds, std::vector<NetworkSocket*>& errorFds, SocketSelectCanceller* canceller);
|
|
|
|
|
|
|
|
virtual NetworkAddress *GetConnectedAddress();
|
|
|
|
|
|
|
|
virtual uint16_t GetConnectedPort();
|
|
|
|
|
|
|
|
virtual void SetTimeouts(int sendTimeout, int recvTimeout);
|
2017-04-17 20:57:07 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void SetMaxPriority();
|
|
|
|
|
|
|
|
private:
|
2017-07-03 03:42:49 +02:00
|
|
|
static int GetDescriptorFromSocket(NetworkSocket* socket);
|
2017-04-17 20:57:07 +02:00
|
|
|
int fd;
|
|
|
|
bool needUpdateNat64Prefix;
|
|
|
|
bool nat64Present;
|
|
|
|
double switchToV6at;
|
|
|
|
bool isV4Available;
|
2017-06-06 03:44:16 +02:00
|
|
|
bool useTCP;
|
|
|
|
bool closing;
|
2017-04-17 20:57:07 +02:00
|
|
|
IPv4Address lastRecvdV4;
|
2017-05-04 23:44:23 +02:00
|
|
|
IPv6Address lastRecvdV6;
|
2017-07-03 03:42:49 +02:00
|
|
|
NetworkAddress* tcpConnectedAddress;
|
|
|
|
uint16_t tcpConnectedPort;
|
2017-04-17 20:57:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //LIBTGVOIP_NETWORKSOCKETPOSIX_H
|