mirror of
https://github.com/znc/znc.git
synced 2026-07-30 21:43:49 +02:00
Moved CSocket to Socket.cpp/h
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1733 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
-102
@@ -102,108 +102,6 @@ CModule* CTimer::GetModule() const { return m_pModule; }
|
||||
const CString& CTimer::GetDescription() const { return m_sDescription; }
|
||||
/////////////////// !Timer ///////////////////
|
||||
|
||||
/////////////////// Socket ///////////////////
|
||||
CSocket::CSocket(CModule* pModule) : CZNCSock() {
|
||||
m_pModule = pModule;
|
||||
m_pModule->AddSocket(this);
|
||||
EnableReadLine();
|
||||
SetMaxBufferThreshold(10240);
|
||||
}
|
||||
|
||||
CSocket::CSocket(CModule* pModule, const CString& sHostname, unsigned short uPort, int iTimeout) : CZNCSock(sHostname, uPort, iTimeout) {
|
||||
m_pModule = pModule;
|
||||
m_pModule->AddSocket(this);
|
||||
EnableReadLine();
|
||||
SetMaxBufferThreshold(10240);
|
||||
}
|
||||
|
||||
CSocket::~CSocket() {
|
||||
CUser *pUser = m_pModule->GetUser();
|
||||
|
||||
m_pModule->UnlinkSocket(this);
|
||||
|
||||
if (!m_pModule->IsGlobal() && pUser) {
|
||||
pUser->AddBytesWritten(GetBytesWritten());
|
||||
pUser->AddBytesRead(GetBytesRead());
|
||||
} else {
|
||||
CZNC::Get().AddBytesWritten(GetBytesWritten());
|
||||
CZNC::Get().AddBytesRead(GetBytesRead());
|
||||
}
|
||||
}
|
||||
|
||||
void CSocket::ReachedMaxBuffer() {
|
||||
DEBUG(GetSockName() << " == ReachedMaxBuffer()");
|
||||
PutModule("Some socket reached its max buffer limit and was closed!");
|
||||
Close();
|
||||
}
|
||||
|
||||
void CSocket::SockError(int iErrno) {
|
||||
DEBUG(GetSockName() << " == SockError(" << strerror(iErrno) << ")");
|
||||
if (iErrno == EMFILE) {
|
||||
// We have too many open fds, this can cause a busy loop.
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSocket::ConnectionFrom(const CString& sHost, unsigned short uPort) {
|
||||
return CZNC::Get().AllowConnectionFrom(sHost);
|
||||
}
|
||||
|
||||
bool CSocket::Connect(const CString& sHostname, unsigned short uPort, bool bSSL, unsigned int uTimeout) {
|
||||
CUser* pUser = m_pModule->GetUser();
|
||||
CString sSockName = "MOD::C::" + m_pModule->GetModName();
|
||||
CString sVHost;
|
||||
|
||||
if (pUser) {
|
||||
sSockName += "::" + pUser->GetUserName();
|
||||
sVHost = m_pModule->GetUser()->GetVHost();
|
||||
}
|
||||
|
||||
// Don't overwrite the socket name if one is already set
|
||||
if (!GetSockName().empty()) {
|
||||
sSockName = GetSockName();
|
||||
}
|
||||
|
||||
return m_pModule->GetManager()->Connect(sHostname, uPort, sSockName, uTimeout, bSSL, sVHost, this);
|
||||
}
|
||||
|
||||
bool CSocket::Listen(unsigned short uPort, bool bSSL, unsigned int uTimeout) {
|
||||
CUser* pUser = m_pModule->GetUser();
|
||||
CString sSockName = "MOD::L::" + m_pModule->GetModName();
|
||||
|
||||
if (pUser) {
|
||||
sSockName += "::" + pUser->GetUserName();
|
||||
}
|
||||
// Don't overwrite the socket name if one is already set
|
||||
if (!GetSockName().empty()) {
|
||||
sSockName = GetSockName();
|
||||
}
|
||||
|
||||
return m_pModule->GetManager()->ListenAll(uPort, sSockName, bSSL, SOMAXCONN, this);
|
||||
}
|
||||
|
||||
bool CSocket::PutIRC(const CString& sLine) {
|
||||
return (m_pModule) ? m_pModule->PutIRC(sLine) : false;
|
||||
}
|
||||
|
||||
bool CSocket::PutUser(const CString& sLine) {
|
||||
return (m_pModule) ? m_pModule->PutUser(sLine) : false;
|
||||
}
|
||||
|
||||
bool CSocket::PutStatus(const CString& sLine) {
|
||||
return (m_pModule) ? m_pModule->PutStatus(sLine) : false;
|
||||
}
|
||||
|
||||
bool CSocket::PutModule(const CString& sLine, const CString& sIdent, const CString& sHost) {
|
||||
return (m_pModule) ? m_pModule->PutModule(sLine, sIdent, sHost) : false;
|
||||
}
|
||||
bool CSocket::PutModNotice(const CString& sLine, const CString& sIdent, const CString& sHost) {
|
||||
return (m_pModule) ? m_pModule->PutModNotice(sLine, sIdent, sHost) : false;
|
||||
}
|
||||
|
||||
void CSocket::SetModule(CModule* p) { m_pModule = p; }
|
||||
CModule* CSocket::GetModule() const { return m_pModule; }
|
||||
/////////////////// !Socket ///////////////////
|
||||
|
||||
CModule::CModule(ModHandle pDLL, CUser* pUser, const CString& sModName, const CString& sDataDir) {
|
||||
m_bFake = false;
|
||||
|
||||
Reference in New Issue
Block a user