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); } } } }
void Master::PrintSlaves(std::string& str) { uint32 i = 0; char buffer[1024]; SlaveConnTable::iterator it = m_slave_table.begin(); while (it != m_slave_table.end()) { const char* state = "ok"; SlaveConnection* slave = it->second; switch (slave->state) { case SLAVE_STATE_WAITING_DUMP_DATA: { state = "wait_bgsave"; break; } case SLAVE_STATE_SYNING_DUMP_DATA: { state = "send_bulk"; break; } case SLAVE_STATE_SYNING_CACHE_DATA: case SLAVE_STATE_SYNCED: { state = "online"; break; } default: { state = "invalid state"; break; } } Address* remote = const_cast<Address*>(slave->conn->GetRemoteAddress()); std::string address; if (InstanceOf<SocketUnixAddress>(remote).OK) { SocketUnixAddress* un = (SocketUnixAddress*) remote; address = "unix_socket="; address += un->GetPath(); } else if (InstanceOf<SocketHostAddress>(remote).OK) { SocketHostAddress* un = (SocketHostAddress*) remote; address = "ip="; address += un->GetHost(); address += ",port="; address += stringfromll(slave->port); } uint32 lag = time(NULL) - slave->acktime; sprintf(buffer, "slave%u:%s,state=%s," "offset=%"PRId64",lag=%u\r\n", i, address.c_str(), state, slave->sync_offset, lag); it++; i++; str.append(buffer); } }
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()); } } }
SocketUnixAddress(const SocketUnixAddress& other) : m_path(other.GetPath()) { }