void connect2(TreeLinkNode* root) { if (root == NULL) return; TreeLinkNode* tmp = root->next; while (tmp != NULL) { if (tmp->left != NULL) { tmp = tmp->left; break; } if (tmp->right != NULL) { tmp = tmp->right; break; } tmp = tmp->next; } if (root->left != NULL) { if (root->right != NULL) root->left->next = root->right; else root->left->next = tmp; } if (root->right != NULL) root->right->next = tmp; connect2(root->right); connect2(root->left); }
void test_node5_03() { int rc; SETUP(); /* * active */ connect1(); rc = node_register(conn, GTM_NODE_DATANODE, 16666, "One zero zero one", "/tmp/pgxc/data/gtm"); _ASSERT( rc >= 0 ); system("killall -9 gtm"); system("./promote.sh"); sleep(1); GTMPQfinish(conn); connect2(); rc = node_unregister(conn, GTM_NODE_DATANODE, "One zero zero one"); _ASSERT( rc >= 0 ); GTMPQfinish(conn); TEARDOWN(); }
void test_node5_02() { int rc; SETUP(); /* * active */ connect1(); rc = node_register(conn, GTM_NODE_DATANODE, 16666, "One zero zero one", "/tmp/pgxc/data/gtm"); _ASSERT( rc >= 0 ); rc = node_unregister(conn, GTM_NODE_DATANODE, "One zero zero one"); _ASSERT( rc >= 0 ); GTMPQfinish(conn); sleep(3); /* * standby */ connect2(); rc = node_unregister(conn, GTM_NODE_DATANODE, "One zero zero one"); _ASSERT( rc<0 ); GTMPQfinish(conn); TEARDOWN(); }
void test_txn5_06() { GlobalTransactionId gxid; int rc; SETUP(); gxid = begin_transaction(conn, GTM_ISOLATION_SERIALIZABLE, timestamp); _ASSERT( gxid != InvalidGlobalTransactionId ); rc = prepare_transaction(conn, gxid); _ASSERT( rc>=0 ); rc = abort_transaction(conn, gxid); _ASSERT( rc>=0 ); system("./promote.sh"); GTMPQfinish(conn); connect2(); rc = abort_transaction(conn, gxid); _ASSERT( rc>=0 ); TEARDOWN(); }
int connect6(const char *host,int port) { return( connect2(host,port,AF_INET6) ); }
uint O2Agent:: LaunchThread(void) { for (uint i = 0; i < Services.size(); i++) { Services[i]->SetActive(true); Services[i]->OnServiceStart(); } Agent_GetGlobalIP->SetActive(true); Agent_GetGlobalIP->OnServiceStart(); if (Logger) Logger->AddLog(O2LT_INFO, MODULE, L"エージェント正常起動"); time_t prevconnecttime = time(NULL); uint index = 0; while (Active) { index %= Services.size(); /* * ウェイト処理 */ if (NodeDB->Count() == 0) { #if DEBUG_THREADLOOP && defined(_DEBUG) TRACEA("■Node 0\n"); #endif Sleep(1000); continue; } uint pasttime_ms = ((uint)time(NULL) - (uint)prevconnecttime) * 1000; if (pasttime_ms < Interval) { uint sleeptime_ms = Interval - pasttime_ms; #if DEBUG_THREADLOOP && defined(_DEBUG) TRACEA("Wait interval\n"); #endif if (Agent_GetGlobalIP->IsActive()) { ; //グローバルIP未確定のときは急ぐ } else { if (sleeptime_ms < 1000) Sleep(sleeptime_ms); else Sleep(1000); continue; } } /* * サービス起動 */ O2AgentService *service = Services[index]; if (Agent_GetGlobalIP->IsActive()) //グローバルIP未決定のとき service = Agent_GetGlobalIP; //強制的にAgent_GetGlobalIP起動 #if DEBUG_SESSION_COUNT && defined(_DEBUG) wchar_t abc[256]; swprintf(abc, L"● count:%d limit:%d %s\n", service->GetSessionCount(), service->GetSessionLimit(), service->GetName()); TRACEW(abc); #endif if (!service->IsActive()) { index++; continue; } if (service->GetSessionCount() >= service->GetSessionLimit()) { Sleep(500); index++; continue; } O2SocketSession *ss = new O2SocketSession(); ss->service = (void*)service; ulong ip; ushort port; wstring ipstr; //接続先ノード決定 //接続 TODO:クラスタリング if (service->HaveNodeDecision()) { service->OnLaunch(ss); if (!ss->IsActive()) { delete ss; index++; continue; } ip = ss->sin.sin_addr.S_un.S_addr; port = htons(ss->sin.sin_port); } else if (!NodeDB->GetNodeByPriority(ip, port)) { if (Logger) { Logger->AddLog(O2LT_WARNING, MODULE, L"有効なノード情報が無いので接続不可(%s)", service->GetName()); } delete ss; index++; continue; } #if !defined(_DEBUG) if (ip == Profile->GetIP() || ip == 0x0100007f) { #if 0 struct in_addr addr; addr.S_un.S_addr = ip; if (Logger) { Logger->AddLog(O2LT_WARNING, MODULE, "自ノード情報破棄 IP: %s Port: %d", inet_ntoa(addr), port); } #endif NodeDB->DeleteNode(ip); delete ss; index++; continue; } #endif #if defined(_DEBUG) ulong2ipstr(ip, ipstr); #else ip2e(ip, ipstr); #endif /* * Socket生成 */ ss->sock = socket(AF_INET, SOCK_STREAM, 0); if (ss->sock == INVALID_SOCKET) { if (Logger) Logger->AddLog(O2LT_ERROR, MODULE, L"ソケット生成に失敗"); delete ss; index++; continue; } ss->sin.sin_family = AF_INET; ss->sin.sin_port = htons(port); ss->sin.sin_addr.S_un.S_addr = ip; /* * Connect */ int timeout = service == Agent_GetGlobalIP ? GIP_CONNECT_TIMEOUT_MS : CONNECT_TIMEOUT_MS; if (connect2(ss->sock, (struct sockaddr*)&ss->sin, sizeof(ss->sin), timeout) != 0) { //NodeDB->DeleteNode(ip); NodeDB->IncrementErrorCount(ip, 1); if (Logger) { Logger->AddLog(O2LT_NET, MODULE, L"connect失敗(%s %s:%d)", service->GetName(), ipstr.c_str(), port); } closesocket(ss->sock); delete ss; index++; continue; } if (hwndSetIconCallback) { PostMessage(hwndSetIconCallback, msgSetIconCallback, 1, 0); } //launch if (!service->HaveNodeDecision()) { service->OnLaunch(ss); if (!ss->IsActive()) { closesocket(ss->sock); delete ss; index++; continue; } } ss->UpdateTimer(); service->IncrementCount(); Lock(); sss.push_back(ss); Unlock(); SetEvent(SessionAvailableEvent); NodeDB->AddStatusBit(ip, O2_NODESTATUS_LINKEDTO); prevconnecttime = time(NULL); index++; #if DEBUG_SESSION_COUNT && defined(_DEBUG) swprintf(abc, L"●● count:%d limit:%d %s\n", service->GetSessionCount(), service->GetSessionLimit(), service->GetName()); TRACEW(abc); #endif if (Logger) { Logger->AddLog(O2LT_NET, MODULE, L"connect成功 (%s %s:%d)", service->GetName(), ipstr.c_str(), port); } } //end Lock(); SetEvent(SessionAvailableEvent); Unlock(); for (uint i = 0; i < Services.size(); i++) { O2AgentService *service = Services[i]; if (service->IsActive()) { service->SetActive(false); service->OnServiceEnd(); } } if (Logger) Logger->AddLog(O2LT_INFO, MODULE, L"エージェント正常終了"); return (0); }
void O2Client:: ConnectionThread(O2SocketSession *ss) { // IP文字列 wstring ipstr; if (O2DEBUG) ulong2ipstr(ss->ip, ipstr); else ip2e(ss->ip, ipstr); // Create Socket SOCKET sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { if (Logger) { Logger->AddLog(O2LT_NETERR, ClientName.c_str(), 0, 0, L"ソケット生成に失敗"); } ss->error = true; ss->Finish(); return; } sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(ss->port); #ifdef _WIN32 sin.sin_addr.S_un.S_addr = ss->ip; #else sin.sin_addr.s_addr = ss->ip; #endif // Connect if (connect2(sock, (struct sockaddr*)&sin, sizeof(sin), (int)(ss->connect_timeout_s*1000)) != 0) { if (Logger) { Logger->AddLog(O2LT_NETERR, ClientName.c_str(), ss->ip, ss->port, L"connect失敗"); } #ifdef _WIN32 /** winsock */ closesocket(sock); #else /** bsd socket */ close(sock); #endif TotalConnectError++; ss->error = true; ss->Finish(); return; } if (hwndSetIconCallback) { #if defined(_WIN32) && !defined(__WXWINDOWS__) PostMessage(hwndSetIconCallback, msgSetIconCallback, 1, 0); #else #warning "TODO: implement wxWidgets event method here" #endif } ss->sock = sock; ss->SetConnectTime(); ss->UpdateTimer(); ss->Activate(); TotalSessionCount++; OnConnect(ss); // push to session list SessionListLock.Lock(); { sss.push_back(ss); if (sss.size() > SessionPeak) SessionPeak = sss.size(); } SessionListLock.Unlock(); SessionExistSignal.On(); if (Logger) { Logger->AddLog(O2LT_NET, ClientName.c_str(), ss->ip, ss->port, L"connect"); } }
int main(int argc, char *argv[]) { libflursch_init(); if (file_exists("images") < 0) { if (mkdir("images", 0700) < 0) { return EXIT_FAILURE; } } if (file_exists("images/iBSS.n72ap.RELEASE.dfu") < 0) { dprintf("File not found, downloading file from Apple."); if(download_file_from_zip("http://appldnld.apple.com/iPhone4/061-9855.20101122.Lrft6/iPod2,1_4.2.1_8C148_Restore.ipsw", "Firmware/dfu/iBSS.n72ap.RELEASE.dfu", "images/iBSS.n72ap.RELEASE.dfu", NULL) != EXIT_SUCCESS) { return EXIT_FAILURE; } } if (inject() != EXIT_SUCCESS) { return EXIT_FAILURE; } dprintf("Uploading %s.", "images/iBSS.n72ap.RELEASE.dfu."); if(send_file("images/iBSS.n72ap.RELEASE.dfu", kDFUMode) != EXIT_SUCCESS) { dprintf("Failed to upload %s.", "images/iBSS.n72ap.RELEASE.dfu."); return EXIT_FAILURE; } dprintf("Waiting 5 seconds..."); sleep(5); if (connect2(0x1281,10) != EXIT_SUCCESS) { dprintf("Cannot connect to device."); return EXIT_FAILURE; } if (send_buffer((unsigned char *)iBSS_n72ap, sizeof(iBSS_n72ap), RecoveryMode) != EXIT_SUCCESS) { dprintf("Failed to send payload."); return EXIT_FAILURE; } if(send_cmd("go") != EXIT_SUCCESS) { dprintf("Failed to send command."); return EXIT_FAILURE; } dprintf("Sending ramdisk."); if (send_buffer((unsigned char *)ramdisk, sizeof(ramdisk), RecoveryMode) != EXIT_SUCCESS) { dprintf("Failed to send payload."); return EXIT_FAILURE; } dprintf("Executing ramdisk."); if(send_cmd("ramdisk") != EXIT_SUCCESS) { dprintf("Failed to send command."); return EXIT_FAILURE; } dprintf("Setting kernel boot args."); if(send_cmd("go kernel bootargs -v serial=1 debug=0xa amfi_allow_any_signature=1") != EXIT_SUCCESS) { dprintf("Failed to send command."); return EXIT_FAILURE; } if (file_exists("images/kernelcache.release.n72") < 0) { dprintf("File not found, downloading file from Apple."); if(download_file_from_zip("http://appldnld.apple.com/iPhone4/061-9855.20101122.Lrft6/iPod2,1_4.2.1_8C148_Restore.ipsw", "kernelcache.release.n72", "images/kernelcache.release.n72", NULL) != EXIT_SUCCESS) { return EXIT_FAILURE; } } dprintf("Uploading %s.","images/kernelcache.release.n72."); if(send_file("images/kernelcache.release.n72", RecoveryMode) != EXIT_SUCCESS) { dprintf("Failed to upload %s.","images/kernelcache.release.n72."); return EXIT_FAILURE; } dprintf("Hooking jump_to function."); if(send_cmd("go rdboot") != EXIT_SUCCESS) { dprintf("Failed to send command."); return EXIT_FAILURE; } dprintf("Booting kernelcache."); if(send_cmd("bootx") != EXIT_SUCCESS) { dprintf("Failed to send command."); return EXIT_FAILURE; } libflursch_exit(); return EXIT_SUCCESS; }
void test_seq5_01() { int rc; GTM_SequenceKeyData seqkey; GTM_Sequence increment; GTM_Sequence minval; GTM_Sequence maxval; GTM_Sequence startval; bool cycle; GTM_Sequence cur; SETUP(); /* * open sequence */ seqkey.gsk_key = strdup("seq1"); seqkey.gsk_keylen = strlen(seqkey.gsk_key); seqkey.gsk_type = GTM_SEQ_FULL_NAME; increment = 1; minval = 0; maxval = 10000; startval = 0; cycle = true; rc = open_sequence(conn, &seqkey, increment, minval, maxval, startval, cycle); _ASSERT( rc>=0 ); _ASSERT( grep_count(LOG_ACTIVE, "Opening sequence seq1")==1 ); _ASSERT( grep_count(LOG_STANDBY, "Opening sequence seq1")==1 ); /* get current */ cur = get_current(conn, &seqkey); _ASSERT( cur==0 ); _ASSERT( grep_count(LOG_ACTIVE, "Getting current value 0 for sequence seq1")==1 ); _ASSERT( grep_count(LOG_STANDBY, "Getting current value 0 for sequence seq1")==1 ); /* get next */ cur = get_next(conn, &seqkey); _ASSERT( cur==1 ); _ASSERT( grep_count(LOG_ACTIVE, "Getting next value 1 for sequence seq1")==1 ); _ASSERT( grep_count(LOG_STANDBY, "Getting next value 1 for sequence seq1")==1 ); system("killall -9 gtm"); system("./promote.sh"); sleep(1); GTMPQfinish(conn); connect2(); /* get current */ cur = get_current(conn, &seqkey); _ASSERT( cur==1 ); _ASSERT( grep_count(LOG_STANDBY, "Getting current value 1 for sequence seq1")==1 ); /* get next */ cur = get_next(conn, &seqkey); _ASSERT( cur==2 ); _ASSERT( grep_count(LOG_STANDBY, "Getting next value 2 for sequence seq1")==1 ); /* * close */ rc = close_sequence(conn, &seqkey); _ASSERT( rc>=0 ); _ASSERT( grep_count(LOG_STANDBY, "Closing sequence seq1")==1 ); TEARDOWN(); }
int SerialPort::connect2() { //neu return connect2(L"COM21"); //neu } //neu