| 6 |
| 7 | #ifndef LIBTGVOIP_NETWORKSOCKETWINSOCK_H |
| 8 | #define LIBTGVOIP_NETWORKSOCKETWINSOCK_H |
| 9 |
| 10 | #include "../../NetworkSocket.h" |
| 11 | #include <stdint.h> |
| 12 | #include <vector> |
| 13 |
| 14 | namespace tgvoip { |
| 15 | class Buffer; |
| 16 |
| 17 | class SocketSelectCancellerWin32 : public SocketSelectCanceller{ |
| 18 | friend class NetworkSocketWinsock; |
| 19 | public: |
| 20 | SocketSelectCancellerWin32(); |
| 21 | virtual ~SocketSelectCancellerWin32(); |
| 22 | virtual void CancelSelect(); |
| 23 | private: |
| 24 | bool canceled; |
| 25 | }; |
| 26 |
| 27 | class NetworkSocketWinsock : public NetworkSocket{ |
| 28 | public: |
| 29 | NetworkSocketWinsock(NetworkProtocol protocol); |
| 30 | virtual ~NetworkSocketWinsock(); |
| 31 | virtual void Send(NetworkPacket* packet); |
| 32 | virtual void Receive(NetworkPacket* packet); |
| 33 | virtual void Open(); |
| 34 | virtual void Close(); |
| 35 | virtual std::string GetLocalInterfaceInfo(IPv4Address* v4addr, IPv6Address* v6addr); |
| 36 | virtual void OnActiveInterfaceChanged(); |
| 37 | virtual uint16_t GetLocalPort(); |
| 38 | virtual void Connect(const NetworkAddress* address, uint16_t port); |
| 39 |
| 40 | static std::string V4AddressToString(uint32_t address); |
| 41 | static std::string V6AddressToString(const unsigned char address[16]); |
| 42 | static uint32_t StringToV4Address(std::string address); |
| 43 | static void StringToV6Address(std::string address, unsigned char* out); |
| 44 | static IPv4Address* ResolveDomainName(std::string name); |
| 45 | static bool Select(std::vector<NetworkSocket*>& readFds, std::vector<NetworkSocket*>& writeFds, std::vector<NetworkSocket*>& errorFds, SocketSelectCanceller* canceller); |
| 46 | virtual NetworkAddress *GetConnectedAddress(); |
| 47 | virtual uint16_t GetConnectedPort(); |
| 48 | virtual void SetTimeouts(int sendTimeout, int recvTimeout); |
| 49 | virtual bool OnReadyToSend() override; |
| 50 |
| 51 | protected: |
| 52 | virtual void SetMaxPriority(); |
| 53 |
| 54 | private: |
| 55 | static int GetDescriptorFromSocket(NetworkSocket* socket); |
| 56 | uintptr_t fd; |
| 57 | bool needUpdateNat64Prefix; |
| 58 | bool nat64Present; |
| 59 | double switchToV6at; |
| 60 | bool isV4Available; |
| 61 | IPv4Address lastRecvdV4; |
| 62 | IPv6Address lastRecvdV6; |
| 63 | bool isAtLeastVista; |
| 64 | bool closing; |
| 65 | NetworkAddress* tcpConnectedAddress; |
| 66 | uint16_t tcpConnectedPort; |
| 67 | Buffer* pendingOutgoingPacket=NULL; |
| 68 | }; |
| 69 |
| 70 | } |
| 71 |
| 72 | #endif //LIBTGVOIP_NETWORKSOCKETWINSOCK_H |
| 73 |