Files
znc/Socket.h
psychon 442aee2baf Add and use CZNCSock instead of Csock everywhere
This class will be used to implement async DNS in a later commit.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1550 726aef4b-f618-498e-8847-2d620e286838
2009-06-29 11:26:19 +00:00

85 lines
2.4 KiB
C++

/*
* Copyright (C) 2004-2009 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);
}
private:
protected:
};
#endif /* SOCKET_H */