![]() |
ExtSocket.cppGo to the documentation of this file.00001 #include <Utility.h> 00002 00003 #include "ExtSocket.h" 00004 #include "MHandler.h" 00005 #include "MasterSocket.h" 00006 00007 00008 00009 ExtSocket::ExtSocket(ISocketHandler& h) 00010 :TcpSocket(h) 00011 ,m_parent(static_cast<MHandler&>(Handler()).GetMasterSocket()) 00012 ,m_id(static_cast<MHandler&>(h).GetUniqueID()) 00013 { 00014 } 00015 00016 00017 ExtSocket::~ExtSocket() 00018 { 00019 } 00020 00021 00022 void ExtSocket::OnAccept() 00023 { 00024 MHandler::service_v& ref = static_cast<MHandler&>(Handler()).GetServices(); 00025 for (MHandler::service_v::iterator it = ref.begin(); it != ref.end(); it++) 00026 { 00027 MHandler::SERVICE *p = *it; 00028 if (p -> port == GetParent() -> GetPort()) 00029 { 00030 if (Handler().Valid(m_parent)) 00031 { 00032 std::string tmp = p -> remote_host + ":" + Utility::l2string(p -> remote_port); 00033 m_parent -> SendCmd(m_id, M2S_OPEN, tmp.size()); 00034 m_parent -> Send(tmp); 00035 } 00036 } 00037 } 00038 } 00039 00040 00041 void ExtSocket::OnDelete() 00042 { 00043 if (Handler().Valid(m_parent)) 00044 { 00045 m_parent -> SendCmd(m_id, M2S_CLOSE); 00046 } 00047 } 00048 00049 00050 void ExtSocket::OnRawData(const char *buf,size_t len) 00051 { 00052 if (Handler().Valid(m_parent)) 00053 { 00054 m_parent -> SendCmd(m_id, M2S_DATA, len); 00055 m_parent -> SendBuf(buf, len); 00056 } 00057 ibuf.Remove(ibuf.GetLength()); 00058 } 00059 00060 |