本文整理汇总了C++中Csock类的典型用法代码示例。如果您正苦于以下问题:C++ Csock类的具体用法?C++ Csock怎么用?C++ Csock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Csock类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnWebRequest
bool OnWebRequest(CWebSock& WebSock, const CString& sPageName,
CTemplate& Tmpl) override {
if (sPageName == "index") {
if (CZNC::Get().GetManager().empty()) {
return false;
}
std::priority_queue<CSocketSorter> socks = GetSockets();
while (!socks.empty()) {
Csock* pSocket = socks.top().GetSock();
socks.pop();
CTemplate& Row = Tmpl.AddRow("SocketsLoop");
Row["Name"] = pSocket->GetSockName();
Row["Created"] = GetCreatedTime(pSocket);
Row["State"] = GetSocketState(pSocket);
Row["SSL"] = pSocket->GetSSL() ? "Yes" : "No";
Row["Local"] = GetLocalHost(pSocket, true);
Row["Remote"] = GetRemoteHost(pSocket, true);
Row["In"] = CString::ToByteStr(pSocket->GetBytesRead());
Row["Out"] = CString::ToByteStr(pSocket->GetBytesWritten());
}
return true;
}
return false;
}
示例2: ReadLine
void CIncomingConnection::ReadLine(const CString& sLine) {
bool bIsHTTP = (sLine.WildCmp("GET * HTTP/1.?\r\n") ||
sLine.WildCmp("POST * HTTP/1.?\r\n"));
bool bAcceptHTTP = (m_eAcceptType == CListener::ACCEPT_ALL) ||
(m_eAcceptType == CListener::ACCEPT_HTTP);
bool bAcceptIRC = (m_eAcceptType == CListener::ACCEPT_ALL) ||
(m_eAcceptType == CListener::ACCEPT_IRC);
Csock* pSock = nullptr;
if (!bIsHTTP) {
// Let's assume it's an IRC connection
if (!bAcceptIRC) {
Write("ERROR :We don't take kindly to your types around here!\r\n");
Close(CLT_AFTERWRITE);
DEBUG("Refused IRC connection to non IRC port");
return;
}
pSock = new CClient();
CZNC::Get().GetManager().SwapSockByAddr(pSock, this);
// And don't forget to give it some sane name / timeout
pSock->SetSockName("USR::???");
} else {
// This is a HTTP request, let the webmods handle it
if (!bAcceptHTTP) {
Write(
"HTTP/1.0 403 Access Denied\r\n\r\nWeb Access is not "
"enabled.\r\n");
Close(CLT_AFTERWRITE);
DEBUG("Refused HTTP connection to non HTTP port");
return;
}
pSock = new CWebSock(m_sURIPrefix);
CZNC::Get().GetManager().SwapSockByAddr(pSock, this);
// And don't forget to give it some sane name / timeout
pSock->SetSockName("WebMod::Client");
}
// TODO can we somehow get rid of this?
pSock->ReadLine(sLine);
pSock->PushBuff("", 0, true);
}
示例3: GetSockets
std::priority_queue<CSocketSorter> GetSockets() {
CSockManager& m = CZNC::Get().GetManager();
std::priority_queue<CSocketSorter> ret;
for (unsigned int a = 0; a < m.size(); a++) {
Csock* pSock = m[a];
// These sockets went through SwapSockByAddr. That means
// another socket took over the connection from this
// socket. So ignore this to avoid listing the
// connection twice.
if (pSock->GetCloseType() == Csock::CLT_DEREFERENCE) continue;
ret.push(pSock);
}
return ret;
}
示例4: GetAnonConnectionCount
unsigned int CSockManager::GetAnonConnectionCount(const CString &sIP) const {
const_iterator it;
unsigned int ret = 0;
for (it = begin(); it != end(); ++it) {
Csock *pSock = *it;
// Logged in CClients have "USR::<username>" as their sockname
if (pSock->GetType() == Csock::INBOUND && pSock->GetRemoteIP() == sIP
&& !pSock->GetSockName().StartsWith("USR::")) {
ret++;
}
}
DEBUG("There are [" << ret << "] clients from [" << sIP << "]");
return ret;
}
示例5: ShowSocks
void ShowSocks(bool bShowHosts) {
if (CZNC::Get().GetManager().empty()) {
PutStatus("You have no open sockets.");
return;
}
std::priority_queue<CSocketSorter> socks = GetSockets();
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Created");
Table.AddColumn("State");
#ifdef HAVE_LIBSSL
Table.AddColumn("SSL");
#endif
Table.AddColumn("Local");
Table.AddColumn("Remote");
Table.AddColumn("In");
Table.AddColumn("Out");
while (!socks.empty()) {
Csock* pSocket = socks.top().GetSock();
socks.pop();
Table.AddRow();
Table.SetCell("Name", pSocket->GetSockName());
Table.SetCell("Created", GetCreatedTime(pSocket));
Table.SetCell("State", GetSocketState(pSocket));
#ifdef HAVE_LIBSSL
Table.SetCell("SSL", pSocket->GetSSL() ? "Yes" : "No");
#endif
Table.SetCell("Local", GetLocalHost(pSocket, bShowHosts));
Table.SetCell("Remote", GetRemoteHost(pSocket, bShowHosts));
Table.SetCell("In", CString::ToByteStr(pSocket->GetBytesRead()));
Table.SetCell("Out",
CString::ToByteStr(pSocket->GetBytesWritten()));
}
PutModule(Table);
return;
}
示例6: ShowSocks
void ShowSocks(bool bShowHosts) {
CSockManager& m = CZNC::Get().GetManager();
if (!m.size()) {
PutStatus("You have no open sockets.");
return;
}
std::priority_queue<CSocketSorter> socks;
for (unsigned int a = 0; a < m.size(); a++) {
socks.push(m[a]);
}
CTable Table;
Table.AddColumn("Name");
Table.AddColumn("Created");
Table.AddColumn("State");
#ifdef HAVE_LIBSSL
Table.AddColumn("SSL");
#endif
Table.AddColumn("Local");
Table.AddColumn("Remote");
while (!socks.empty()) {
Csock* pSocket = socks.top().GetSock();
socks.pop();
Table.AddRow();
switch (pSocket->GetType()) {
case Csock::LISTENER:
Table.SetCell("State", "Listen");
break;
case Csock::INBOUND:
Table.SetCell("State", "Inbound");
break;
case Csock::OUTBOUND:
if (pSocket->IsConnected())
Table.SetCell("State", "Outbound");
else
Table.SetCell("State", "Connecting");
break;
default:
Table.SetCell("State", "UNKNOWN");
break;
}
unsigned long long iStartTime = pSocket->GetStartTime();
time_t iTime = iStartTime / 1000;
Table.SetCell("Created", FormatTime("%Y-%m-%d %H:%M:%S", iTime));
#ifdef HAVE_LIBSSL
if (pSocket->GetSSL()) {
Table.SetCell("SSL", "Yes");
} else {
Table.SetCell("SSL", "No");
}
#endif
Table.SetCell("Name", pSocket->GetSockName());
CString sVHost;
if (bShowHosts) {
sVHost = pSocket->GetBindHost();
}
if (sVHost.empty()) {
sVHost = pSocket->GetLocalIP();
}
Table.SetCell("Local", sVHost + " " + CString(pSocket->GetLocalPort()));
CString sHost;
if (!bShowHosts) {
sHost = pSocket->GetRemoteIP();
}
// While connecting, there might be no ip available
if (sHost.empty()) {
sHost = pSocket->GetHostName();
}
u_short uPort;
// While connecting, GetRemotePort() would return 0
if (pSocket->GetType() == Csock::OUTBOUND) {
uPort = pSocket->GetPort();
} else {
uPort = pSocket->GetRemotePort();
}
if (uPort != 0) {
Table.SetCell("Remote", sHost + " " + CString(uPort));
} else {
Table.SetCell("Remote", sHost);
}
}
PutModule(Table);
return;
}
示例7: OnModCommand
//.........这里部分代码省略.........
Table.SetCell("Created", sTime);
}
if (pSock->GetType() != CSChatSock::LISTENER) {
Table.SetCell("Status", "Established");
Table.SetCell("Host", pSock->GetRemoteIP());
Table.SetCell("Port", CString(pSock->GetRemotePort()));
SSL_SESSION *pSession = pSock->GetSSLSession();
if (pSession && pSession->cipher && pSession->cipher->name)
Table.SetCell("Cipher", pSession->cipher->name);
} else {
Table.SetCell("Status", "Waiting");
Table.SetCell("Port", CString(pSock->GetLocalPort()));
}
}
if (Table.size()) {
PutModule(Table);
} else
PutModule("No SDCCs currently in session");
} else if (sCom.Equals("close")) {
if (!sArgs.Equals("(s)", false, 3))
sArgs = "(s)" + sArgs;
set<CSocket*>::const_iterator it;
for (it = BeginSockets(); it != EndSockets(); ++it) {
CSChatSock *pSock = (CSChatSock*) *it;
if (sArgs.Equals(pSock->GetChatNick())) {
pSock->Close();
return;
}
}
PutModule("No Such Chat [" + sArgs + "]");
} else if (sCom.Equals("showsocks") && m_pUser->IsAdmin()) {
CTable Table;
Table.AddColumn("SockName");
Table.AddColumn("Created");
Table.AddColumn("LocalIP:Port");
Table.AddColumn("RemoteIP:Port");
Table.AddColumn("Type");
Table.AddColumn("Cipher");
set<CSocket*>::const_iterator it;
for (it = BeginSockets(); it != EndSockets(); ++it) {
Table.AddRow();
Csock *pSock = *it;
Table.SetCell("SockName", pSock->GetSockName());
unsigned long long iStartTime = pSock->GetStartTime();
time_t iTime = iStartTime / 1000;
char *pTime = ctime(&iTime);
if (pTime) {
CString sTime = pTime;
sTime.Trim();
Table.SetCell("Created", sTime);
}
if (pSock->GetType() != Csock::LISTENER) {
if (pSock->GetType() == Csock::OUTBOUND)
Table.SetCell("Type", "Outbound");
else
Table.SetCell("Type", "Inbound");
Table.SetCell("LocalIP:Port", pSock->GetLocalIP() + ":" +
CString(pSock->GetLocalPort()));
Table.SetCell("RemoteIP:Port", pSock->GetRemoteIP() + ":" +
CString(pSock->GetRemotePort()));
SSL_SESSION *pSession = pSock->GetSSLSession();
if (pSession && pSession->cipher && pSession->cipher->name)
Table.SetCell("Cipher", pSession->cipher->name);
else
Table.SetCell("Cipher", "None");
} else {
Table.SetCell("Type", "Listener");
Table.SetCell("LocalIP:Port", pSock->GetLocalIP() +
":" + CString(pSock->GetLocalPort()));
Table.SetCell("RemoteIP:Port", "0.0.0.0:0");
}
}
if (Table.size())
PutModule(Table);
else
PutModule("Error Finding Sockets");
} else if (sCom.Equals("help")) {
PutModule("Commands are:");
PutModule(" help - This text.");
PutModule(" chat <nick> - Chat a nick.");
PutModule(" list - List current chats.");
PutModule(" close <nick> - Close a chat to a nick.");
PutModule(" timers - Shows related timers.");
if (m_pUser->IsAdmin()) {
PutModule(" showsocks - Shows all socket connections.");
}
} else if (sCom.Equals("timers"))
ListTimers();
else
PutModule("Unknown command [" + sCom + "] [" + sArgs + "]");
}
示例8: NETWORKMODULECALL
//.........这里部分代码省略.........
}
if(!CZNC::Get().WriteConfig() && !bForce) {
PutStatus("ERROR: Writing config file to disk failed! Aborting. Use " +
sCommand.AsUpper() + " FORCE to ignore.");
} else {
CZNC::Get().Broadcast(sMessage);
throw CException(bRestart ? CException::EX_Restart : CException::EX_Shutdown);
}
} else if (sCommand.Equals("JUMP") || sCommand.Equals("CONNECT")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
if (!m_pNetwork->HasServers()) {
PutStatus("You don't have any servers added.");
return;
}
CString sArgs = sLine.Token(1, true);
CServer *pServer = NULL;
if (!sArgs.empty()) {
pServer = m_pNetwork->FindServer(sArgs);
if (!pServer) {
PutStatus("Server [" + sArgs + "] not found");
return;
}
m_pNetwork->SetNextServer(pServer);
// If we are already connecting to some server,
// we have to abort that attempt
Csock *pIRCSock = GetIRCSock();
if (pIRCSock && !pIRCSock->IsConnected()) {
pIRCSock->Close();
}
}
if (GetIRCSock()) {
GetIRCSock()->Quit();
if (pServer)
PutStatus("Connecting to [" + pServer->GetName() + "]...");
else
PutStatus("Jumping to the next server in the list...");
} else {
if (pServer)
PutStatus("Connecting to [" + pServer->GetName() + "]...");
else
PutStatus("Connecting...");
}
m_pNetwork->SetIRCConnectEnabled(true);
return;
} else if (sCommand.Equals("DISCONNECT")) {
if (!m_pNetwork) {
PutStatus("You must be connected with a network to use this command");
return;
}
if (GetIRCSock()) {
CString sQuitMsg = sLine.Token(1, true);
GetIRCSock()->Quit(sQuitMsg);
}
m_pNetwork->SetIRCConnectEnabled(false);