mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
This removes all of znc's c-ares code and instead enables Csocket's built-in version. That code is newer than ZNC's, but should hopefully work just as good. Let's wait for the bug reports.... git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1704 726aef4b-f618-498e-8847-2d620e286838
87 lines
2.5 KiB
C++
87 lines
2.5 KiB
C++
/*
|
|
* Copyright (C) 2004-2010 See the AUTHORS file for details.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published
|
|
* by the Free Software Foundation.
|
|
*/
|
|
|
|
#ifndef SOCKET_H
|
|
#define SOCKET_H
|
|
|
|
#include "Csocket.h"
|
|
|
|
class CZNCSock : public Csock {
|
|
public:
|
|
CZNCSock(int timeout = 60) : Csock(timeout) {}
|
|
CZNCSock(const CString& sHost, u_short port, int timeout = 60) : Csock(sHost, port, timeout) {}
|
|
~CZNCSock() {}
|
|
};
|
|
|
|
class CSockManager : public TSocketManager<CZNCSock> {
|
|
public:
|
|
CSockManager() {}
|
|
virtual ~CSockManager() {}
|
|
|
|
bool ListenHost(u_short iPort, const CString& sSockName, const CString& sBindHost, bool bSSL = false, int iMaxConns = SOMAXCONN, CZNCSock *pcSock = NULL, u_int iTimeout = 0, bool bIsIPv6 = false) {
|
|
CSListener L(iPort, sBindHost);
|
|
|
|
L.SetSockName(sSockName);
|
|
L.SetIsSSL(bSSL);
|
|
L.SetTimeout(iTimeout);
|
|
L.SetMaxConns(iMaxConns);
|
|
|
|
#ifdef HAVE_IPV6
|
|
if (bIsIPv6) {
|
|
L.SetAFRequire(CSSockAddr::RAF_INET6);
|
|
}
|
|
#endif
|
|
|
|
return Listen(L, pcSock);
|
|
}
|
|
|
|
bool ListenAll(u_short iPort, const CString& sSockName, bool bSSL = false, int iMaxConns = SOMAXCONN, CZNCSock *pcSock = NULL, u_int iTimeout = 0, bool bIsIPv6 = false) {
|
|
return ListenHost(iPort, sSockName, "", bSSL, iMaxConns, pcSock, iTimeout, bIsIPv6);
|
|
}
|
|
|
|
u_short ListenRand(const CString& sSockName, const CString& sBindHost, bool bSSL = false, int iMaxConns = SOMAXCONN, CZNCSock *pcSock = NULL, u_int iTimeout = 0, bool bIsIPv6 = false) {
|
|
unsigned short uPort = 0;
|
|
CSListener L(0, sBindHost);
|
|
|
|
L.SetSockName(sSockName);
|
|
L.SetIsSSL(bSSL);
|
|
L.SetTimeout(iTimeout);
|
|
L.SetMaxConns(iMaxConns);
|
|
|
|
#ifdef HAVE_IPV6
|
|
if (bIsIPv6) {
|
|
L.SetAFRequire(CSSockAddr::RAF_INET6);
|
|
}
|
|
#endif
|
|
|
|
Listen(L, pcSock, &uPort);
|
|
|
|
return uPort;
|
|
}
|
|
|
|
u_short ListenAllRand(const CString& sSockName, bool bSSL = false, int iMaxConns = SOMAXCONN, CZNCSock *pcSock = NULL, u_int iTimeout = 0, bool bIsIPv6 = false) {
|
|
return(ListenRand(sSockName, "", bSSL, iMaxConns, pcSock, iTimeout, bIsIPv6));
|
|
}
|
|
|
|
bool Connect(const CString& sHostname, u_short iPort , const CString& sSockName, int iTimeout = 60, bool bSSL = false, const CString& sBindHost = "", CZNCSock *pcSock = NULL) {
|
|
CSConnection C(sHostname, iPort, iTimeout);
|
|
|
|
C.SetSockName(sSockName);
|
|
C.SetIsSSL(bSSL);
|
|
C.SetBindHost(sBindHost);
|
|
|
|
return TSocketManager<CZNCSock>::Connect(C, pcSock);
|
|
}
|
|
|
|
unsigned int GetAnonConnectionCount(const CString &sIP) const;
|
|
private:
|
|
protected:
|
|
};
|
|
|
|
#endif /* SOCKET_H */
|