void ServiceIPCEventHandler::ChannelClosed(ChannelHandlerContext& ctx, ChannelStateEvent& e) { Channel* ch = ctx.GetChannel(); Address* addr = const_cast<Address*>(ch->GetRemoteAddress()); Address* localaddr = const_cast<Address*>(ch->GetLocalAddress()); if (NULL != addr && InstanceOf<SocketUnixAddress>(addr).OK) { SocketUnixAddress* un = (SocketUnixAddress*) addr; SocketUnixAddress* un1 = (SocketUnixAddress*) localaddr; DEBUG_LOG( "Local %s Closed %s", un1->GetPath().c_str(), un->GetPath().c_str()); if (m_service->GetManagerProcess()->IsManagerIPCUnixSocketServer( un->GetPath())) { m_service->SetIPCUnixSocket(NULL); } else if (m_service->GetManagerProcess()->IsManagerCtrlUnixSocketServer( un->GetPath())) { m_service->SetCtrlChannel(NULL); } else { GetServiceProcess()->AddClosedDispatcherIPCChannel(ch); VirtualChannelHelper::ClearTable(ch); } } }
void DispatcerIPCEventHandler::ChannelConnected(ChannelHandlerContext& ctx, ChannelStateEvent& e) { DEBUG_LOG("Dispatcher(%s_%u) accept a client.", g_service_proc->GetServiceName().c_str(), g_service_proc->GetProcessIndex()); Channel* ch = ctx.GetChannel(); Address* remote = const_cast<Address*> (ch->GetRemoteAddress()); if (NULL != remote) { if (InstanceOf<SocketUnixAddress> (remote).OK) { SocketUnixAddress* un = (SocketUnixAddress*) remote; const std::string& path = un->GetPath(); ProcessAddress proc_addr; g_service_proc->GetManagerProcess()->ParseDispatcherClientUnixSocketAddress(path, proc_addr); DEBUG_LOG("Parsed process address %u_%u", proc_addr.proc_type, proc_addr.proc_idx); IPCChannelTable::iterator tit = m_ipc_channel_table.find(proc_addr); if (tit == m_ipc_channel_table.end()) { AddServiceIPCChannel(proc_addr, ch); } } } }
std::string GetAddress() { std::string address; Address* remote = const_cast<Address*>(conn->GetRemoteAddress()); if (InstanceOf<SocketHostAddress>(remote).OK) { SocketHostAddress* un = (SocketHostAddress*) remote; address = "ip="; address += un->GetHost(); address += ",port="; address += stringfromll(port); } return address; }
void ServiceIPCEventHandler::ChannelConnected(ChannelHandlerContext& ctx, ChannelStateEvent& e) { Channel* ch = ctx.GetChannel(); Address* addr = const_cast<Address*>(ch->GetRemoteAddress()); Address* localaddr = const_cast<Address*>(ch->GetLocalAddress()); if (NULL != addr && InstanceOf<SocketUnixAddress>(addr).OK) { SocketUnixAddress* un = (SocketUnixAddress*) addr; SocketUnixAddress* un1 = (SocketUnixAddress*) localaddr; DEBUG_LOG( "Local %s Connected %s", un1->GetPath().c_str(), un->GetPath().c_str()); if (m_service->GetManagerProcess()->IsManagerCtrlUnixSocketServer( un->GetPath())) { ch->DetachFD(); ch->SetIOEventCallback( VirtualChannelHelper::CtrlChannelIOEventCallback, AE_READABLE, ch); // make_fd_blocking(ch->GetReadFD()); } } }