Esempio n. 1
0
	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);
		}
	}
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 SocketHostAddress(const SocketHostAddress& other) :
     m_host(other.GetHost()), m_port(other.GetPort())
 {
 }