// choose a key static void pick_key(int screen) { KeyCode kc; unsigned int mods; char buf[512]; if (wait_key(screen, &kc, &mods)) printf("%s\n", format_key(kc, mods, buf)); }
int CNetProc::SendMsg(const char* ip, const int port, const char* msg, const int msg_len, char* reply_data, int& reply_len) { std::string key = format_key(ip, port); CBoostGuard lock(&m_clientLock); int nHandle = GetClientHandle(key); if (-1 == nHandle) { return -1; } return lt_client_send(nHandle, msg, msg_len, reply_data, reply_len); }
// 与服务器断开连接 bool CNetProc::Close(const char* ip, const int port) { std::string key = format_key(ip, port); CBoostGuard lock(&m_clientLock); if (-1 == GetClientHandle(key)) { return true; } lt_client_disconnect(GetClientHandle(key)); RemoveClient(key); return true; }
static int do_last( struct chronos_handle * handle, int argc, char** argv ){ struct index_entry entry; int rc = chronos_entry( handle, -1, & entry ); if( rc != 0 ){ if( rc != C_NO_MORE_ELEMENTS ){ perror("chronos_entry"); } return rc; } char buffer[1024]; format_key( buffer, sizeof(buffer), & entry.key ); printf( "%s\n", buffer ); return 0; }
// 连接服务器 bool CNetProc::Connect(const char* ip, const int port) { std::string key = format_key(ip, port); CBoostGuard lock(&m_clientLock); if (-1 != GetClientHandle(key)) { return true; } int handle = lt_client_connect(ip, port, PROTOCOL_TCP); if (-1 == handle) { return false; } CClient c(ip, port, handle); m_lsClient.push_back(c); return true; }