HRESULT CTryData4Dlg::OnMouseOverOnce(IHTMLElement *phtmlElement) { if(m_State == RUNNING) return S_OK; if(m_sDataSel.Find("测量结果") < 0) return S_OK; CString sel = this->GetAttribute(phtmlElement,m_elemTypes[2]); if(sel.IsEmpty() || sel[0] != 'Z') return S_OK; m_sDataUrl = this->GetAttribute(phtmlElement,m_elemTypes[4]); // if(m_sDataUrl.FindOneOf("0123456789") < 0) return S_OK; IHTMLStyle *phtmlStyle; phtmlElement->get_style(&phtmlStyle); if (phtmlStyle) { CString retest("单击测量"); phtmlElement->put_innerText(retest.AllocSysString()); VARIANT varColor; varColor.vt = VT_I4; varColor.lVal = 0x990033; phtmlStyle->put_backgroundColor(varColor); phtmlStyle->put_textDecorationUnderline(VARIANT_TRUE); // phtmlStyle->put_color(varColor); phtmlStyle->put_cursor(L"hand"); phtmlStyle->Release(); } m_spCurrElement = phtmlElement; return S_OK; }
/* * Test called by the dns query handlers to handle interval=onquery cases. */ void test_onquery() { int i,n,signal_test; pthread_mutex_lock(&servers_lock); schm[0] = '\0'; signal_test=0; n=DA_NEL(servers); for (i=0;i<n;++i) { servparm_t *sp=&DA_INDEX(servers,i); if (sp->interval==-1) { if(sp->rootserver<=1) retest(i,-1); else { /* We leave root-server discovery to the server status thread */ int j,m=DA_NEL(sp->atup_a); for(j=0;j<m;++j) DA_INDEX(sp->atup_a,j).i_ts=0; signal_test=1; } } } if(signal_test) { int rv; if(pthread_equal(servstat_thrid,main_thrid)) start_servstat_thread(); else { retest_flag=1; if((rv=pthread_cond_signal(&server_test_cond))) { DEBUG_MSG("test_onquery(): couldn't signal server status thread: %s\n",strerror(rv)); } } } pthread_mutex_unlock(&servers_lock); }
/* each server has two connections open to it. Each connection has two file descriptors open on the file - 8 file descriptors in total we then do random locking ops in tamdem on the 4 fnums from each server and ensure that the results match */ static int test_locks(struct tevent_context *ev, struct loadparm_context *lp_ctx, TALLOC_CTX *mem_ctx, char *share[NSERVERS]) { struct smbcli_state *cli[NSERVERS][NCONNECTIONS]; int fnum[NSERVERS][NCONNECTIONS][NFILES]; int n, i, n1, skip, r1, r2; ZERO_STRUCT(fnum); ZERO_STRUCT(cli); recorded = malloc_array_p(struct record, numops); for (n=0; n<numops; n++) { #if PRESETS if (n < sizeof(preset) / sizeof(preset[0])) { recorded[n] = preset[n]; } else { #endif recorded[n].conn = random() % NCONNECTIONS; recorded[n].f = random() % NFILES; recorded[n].start = lock_base + ((unsigned int)random() % (lock_range-1)); recorded[n].len = min_length + random() % (lock_range-(recorded[n].start-lock_base)); recorded[n].start *= RANGE_MULTIPLE; recorded[n].len *= RANGE_MULTIPLE; recorded[n].pid = random()%3; if (recorded[n].pid == 2) { recorded[n].pid = 0xFFFF; /* see if its magic */ } r1 = random() % 100; r2 = random() % 100; if (r1 < READ_PCT) { recorded[n].lock_type = READ_LOCK; } else { recorded[n].lock_type = WRITE_LOCK; } if (r2 < LOCK_PCT) { recorded[n].lock_op = OP_LOCK; } else if (r2 < UNLOCK_PCT) { recorded[n].lock_op = OP_UNLOCK; } else { recorded[n].lock_op = OP_REOPEN; } recorded[n].needed = true; if (!zero_zero && recorded[n].start==0 && recorded[n].len==0) { recorded[n].len = 1; } #if PRESETS } #endif } reconnect(ev, lp_ctx, mem_ctx, cli, fnum, share); open_files(cli, fnum); n = retest(cli, fnum, numops); if (n == numops || !analyze) { if (n != numops) { return 1; } return 0; } n++; skip = n/2; while (1) { n1 = n; close_files(cli, fnum); reconnect(ev, lp_ctx, mem_ctx, cli, fnum, share); open_files(cli, fnum); for (i=0;i<n-skip;i+=skip) { int m, j; printf("excluding %d-%d\n", i, i+skip-1); for (j=i;j<i+skip;j++) { recorded[j].needed = false; } close_files(cli, fnum); open_files(cli, fnum); m = retest(cli, fnum, n); if (m == n) { for (j=i;j<i+skip;j++) { recorded[j].needed = true; } } else { if (i+(skip-1) < m) { memmove(&recorded[i], &recorded[i+skip], (m-(i+skip-1))*sizeof(recorded[0])); } n = m-(skip-1); i--; } } if (skip > 1) { skip = skip/2; printf("skip=%d\n", skip); continue; } if (n1 == n) break; } close_files(cli, fnum); reconnect(ev, lp_ctx, mem_ctx, cli, fnum, share); open_files(cli, fnum); showall = true; n1 = retest(cli, fnum, n); if (n1 != n-1) { printf("ERROR - inconsistent result (%u %u)\n", n1, n); } close_files(cli, fnum); for (i=0;i<n;i++) { printf("{%d, %d, %u, %u, %.0f, %.0f, %u},\n", recorded[i].lock_op, recorded[i].lock_type, recorded[i].conn, recorded[i].f, (double)recorded[i].start, (double)recorded[i].len, recorded[i].needed); } return 1; }
/* each server has two connections open to it. Each connection has two file descriptors open on the file - 8 file descriptors in total we then do random locking ops in tamdem on the 4 fnums from each server and ensure that the results match */ static void test_locks(char *share1, char *share2, char *nfspath1, char *nfspath2) { struct smbcli_state *cli[NSERVERS][NCONNECTIONS]; char *nfs[NSERVERS]; int fnum[NSERVERS][NUMFSTYPES][NCONNECTIONS][NFILES]; int n, i, n1; nfs[0] = nfspath1; nfs[1] = nfspath2; ZERO_STRUCT(fnum); ZERO_STRUCT(cli); recorded = malloc_array_p(struct record, numops); for (n=0; n<numops; n++) { recorded[n].conn = random() % NCONNECTIONS; recorded[n].fstype = random() % NUMFSTYPES; recorded[n].f = random() % NFILES; recorded[n].start = LOCKBASE + ((uint_t)random() % (LOCKRANGE-1)); recorded[n].len = 1 + random() % (LOCKRANGE-(recorded[n].start-LOCKBASE)); recorded[n].start *= RANGE_MULTIPLE; recorded[n].len *= RANGE_MULTIPLE; recorded[n].r1 = random() % 100; recorded[n].r2 = random() % 100; recorded[n].needed = True; } reconnect(cli, nfs, fnum, share1, share2); open_files(cli, nfs, fnum); n = retest(cli, nfs, fnum, numops); if (n == numops || !analyze) return; n++; while (1) { n1 = n; close_files(cli, nfs, fnum); reconnect(cli, nfs, fnum, share1, share2); open_files(cli, nfs, fnum); for (i=0;i<n-1;i++) { int m; recorded[i].needed = False; close_files(cli, nfs, fnum); open_files(cli, nfs, fnum); m = retest(cli, nfs, fnum, n); if (m == n) { recorded[i].needed = True; } else { if (i < m) { memmove(&recorded[i], &recorded[i+1], (m-i)*sizeof(recorded[0])); } n = m; i--; } } if (n1 == n) break; } close_files(cli, nfs, fnum); reconnect(cli, nfs, fnum, share1, share2); open_files(cli, nfs, fnum); showall = True; n1 = retest(cli, nfs, fnum, n); if (n1 != n-1) { printf("ERROR - inconsistent result (%u %u)\n", n1, n); } close_files(cli, nfs, fnum); for (i=0;i<n;i++) { printf("{%u, %u, %u, %u, %u, %u, %u, %u},\n", recorded[i].r1, recorded[i].r2, recorded[i].conn, recorded[i].fstype, recorded[i].f, recorded[i].start, recorded[i].len, recorded[i].needed); } }
/* * Refresh the server status by pinging or testing the interface in the given interval. * Note that you may get inaccuracies in the dimension of the ping timeout or the runtime * of your uptest command if you have uptest=ping or uptest=exec for at least one server. * This happens when all the uptests for the first n servers take more time than the inteval * of n+1 (or 0 when n+1>servnum). I do not think that these delays are critical, so I did * not to anything about that (because that may also be costly). */ void *servstat_thread(void *p) { struct sigaction action; int keep_testing; /* (void)p; */ /* To inhibit "unused variable" warning */ THREAD_SIGINIT; pthread_mutex_lock(&servers_lock); /* servstat_thrid=pthread_self(); */ signal_interrupt=0; action.sa_handler = sigint_handler; sigemptyset(&action.sa_mask); action.sa_flags = 0; if(sigaction(statusintsig, &action, NULL) == 0) { sigset_t smask; sigemptyset(&smask); sigaddset(&smask, statusintsig); pthread_sigmask(SIG_UNBLOCK,&smask,NULL); } else { log_warn("Cannot install signal handler for server status thread: %s\n",strerror(errno)); } for(;;) { do { int i,n; keep_testing=0; retest_flag=0; schm[0] = '\0'; n=DA_NEL(servers); for (i=0;i<n;++i) { servparm_t *sp=&DA_INDEX(servers,i); int j,m; if(sp->rootserver==2) { /* First get addresses of root servers. */ addr2_array adrs; int l, one_up=0; if(!scheme_ok(sp)) { time_t now=time(NULL); m=DA_NEL(sp->atup_a); for(j=0;j<m;++j) DA_INDEX(sp->atup_a,j).i_ts=now; } else if(sp->uptest==C_PING || sp->uptest==C_QUERY) { /* Skip ping or query tests until after discovery. */ if(sp->interval>0) one_up= DA_NEL(sp->atup_a); else { time_t now=time(NULL); m=DA_NEL(sp->atup_a); for(j=0;j<m;++j) { atup_t *at=&DA_INDEX(sp->atup_a,j); if(at->is_up || at->i_ts==0) one_up=1; at->i_ts=now; } } } else { retest(i,-1); m=DA_NEL(sp->atup_a); for(j=0;j<m;++j) { if(DA_INDEX(sp->atup_a,j).is_up) { one_up=1; break; } } } if(!one_up) { if (needs_intermittent_testing(sp)) keep_testing=1; continue; } DEBUG_MSG("Attempting to discover root servers for server section #%d.\n",i); adrs=resolv_rootserver_addrs(sp->atup_a,sp->port,sp->timeout); l= DA_NEL(adrs); if(l>0) { struct timeval now; struct timespec timeout; atup_array ata; DEBUG_MSG("Filling server section #%d with %d root server addresses.\n",i,l); gettimeofday(&now,NULL); timeout.tv_sec = now.tv_sec + 60; /* time out after 60 seconds */ timeout.tv_nsec = now.tv_usec * 1000; while (server_data_users>0) { if(pthread_cond_timedwait(&server_data_cond, &servers_lock, &timeout) == ETIMEDOUT) { DEBUG_MSG("Timed out while waiting for exclusive access to server data" " to set root server addresses of server section #%d\n",i); da_free(adrs); keep_testing=1; continue; } } ata = DA_CREATE(atup_array, l); if(!ata) { log_warn("Out of memory in servstat_thread() while discovering root servers."); da_free(adrs); keep_testing=1; continue; } for(j=0; j<l; ++j) { atup_t *at = &DA_INDEX(ata,j); at->a = DA_INDEX(adrs,j); at->is_up=sp->preset; at->i_ts= sp->interval<0 ? time(NULL): 0; } da_free(sp->atup_a); sp->atup_a=ata; da_free(adrs); /* Successfully set IP addresses for this server section. */ sp->rootserver=1; } else { DEBUG_MSG("Failed to discover root servers in servstat_thread() (server section #%d).\n",i); if(adrs) da_free(adrs); if(DA_NEL(sp->atup_a)) keep_testing=1; continue; } } if (needs_testing(sp)) keep_testing=1; m=DA_NEL(sp->atup_a); for(j=0;j<m;++j) if(DA_INDEX(sp->atup_a,j).i_ts) goto individual_tests; /* Test collectively */ if(!signal_interrupt) retest(i,-1); continue; individual_tests: for(j=0; !signal_interrupt && j<m; ++j) { time_t ts=DA_INDEX(sp->atup_a,j).i_ts, now; if (ts==0 /* Always test servers with timestamp 0 */ || (needs_intermittent_testing(sp) && ((now=time(NULL))-ts>sp->interval || ts>now /* kluge for clock skew */))) { retest(i,j); } } } } while(!signal_interrupt && retest_flag); signal_interrupt=0; /* Break the loop and exit the thread if it is no longer needed. */ if(!keep_testing) break; { struct timeval now; struct timespec timeout; time_t minwait; int i,n,retval; gettimeofday(&now,NULL); minwait=3600; /* Check at least once every hour. */ n=DA_NEL(servers); for (i=0;i<n;++i) { servparm_t *sp=&DA_INDEX(servers,i); int j,m=DA_NEL(sp->atup_a); for(j=0;j<m;++j) { time_t ts= DA_INDEX(sp->atup_a,j).i_ts; if(ts==0) { /* Test servers with timestamp 0 without delay */ if(minwait > 0) minwait=0; } else if(needs_intermittent_testing(sp)) { time_t wait= ts + sp->interval - now.tv_sec; if(wait < minwait) minwait=wait; } } } timeout.tv_sec = now.tv_sec; if(minwait>0) timeout.tv_sec += minwait; timeout.tv_nsec = now.tv_usec * 1000 + 500000000; /* wait at least half a second. */ if(timeout.tv_nsec>=1000000000) { timeout.tv_nsec -= 1000000000; ++timeout.tv_sec; } /* While we wait for a server_test_cond condition or a timeout the servers_lock mutex is unlocked, so other threads can access server data */ retval=pthread_cond_timedwait(&server_test_cond, &servers_lock, &timeout); DEBUG_MSG("Server status thread woke up (%s signal).\n", retval==0?"test condition":retval==ETIMEDOUT?"timer":retval==EINTR?"interrupt":"error"); } } /* server status thread no longer needed. */ servstat_thrid=main_thrid; pthread_mutex_unlock(&servers_lock); DEBUG_MSG("Server status thread exiting.\n"); return NULL; }
/* each server has two connections open to it. Each connection has two file descriptors open on the file - 8 file descriptors in total we then do random locking ops in tamdem on the 4 fnums from each server and ensure that the results match */ static void test_locks(char *share[NSERVERS]) { struct cli_state *cli[NSERVERS][NCONNECTIONS]; uint16_t fnum[NSERVERS][NCONNECTIONS][NFILES]; int n, i, n1, skip, r1, r2; ZERO_STRUCT(fnum); ZERO_STRUCT(cli); recorded = SMB_MALLOC_ARRAY(struct record, numops); for (n=0; n<numops; n++) { #if PRESETS if (n < sizeof(preset) / sizeof(preset[0])) { recorded[n] = preset[n]; } else { #endif recorded[n].conn = random() % NCONNECTIONS; recorded[n].f = random() % NFILES; recorded[n].start = lock_base + ((unsigned)random() % (lock_range-1)); recorded[n].len = min_length + random() % (lock_range-(recorded[n].start-lock_base)); recorded[n].start *= RANGE_MULTIPLE; recorded[n].len *= RANGE_MULTIPLE; r1 = random() % 100; r2 = random() % 100; if (r1 < READ_PCT) { recorded[n].lock_type = READ_LOCK; } else { recorded[n].lock_type = WRITE_LOCK; } if (r2 < LOCK_PCT) { recorded[n].lock_op = OP_LOCK; } else if (r2 < UNLOCK_PCT) { recorded[n].lock_op = OP_UNLOCK; } else { recorded[n].lock_op = OP_REOPEN; } recorded[n].needed = True; if (!zero_zero && recorded[n].start==0 && recorded[n].len==0) { recorded[n].len = 1; } #if PRESETS } #endif } reconnect(cli, fnum, share); open_files(cli, fnum); n = retest(cli, fnum, numops); if (n == numops || !analyze) return; n++; skip = n/2; while (1) { n1 = n; close_files(cli, fnum); reconnect(cli, fnum, share); open_files(cli, fnum); for (i=0;i<n-skip;i+=skip) { int m, j; printf("excluding %d-%d\n", i, i+skip-1); for (j=i;j<i+skip;j++) { recorded[j].needed = False; } close_files(cli, fnum); open_files(cli, fnum); m = retest(cli, fnum, n); if (m == n) { for (j=i;j<i+skip;j++) { recorded[j].needed = True; } } else { if (i+(skip-1) < m) { memmove(&recorded[i], &recorded[i+skip], (m-(i+skip-1))*sizeof(recorded[0])); } n = m-(skip-1); i--; } } if (skip > 1) { skip = skip/2; printf("skip=%d\n", skip); continue; } if (n1 == n) break; } close_files(cli, fnum); reconnect(cli, fnum, share); open_files(cli, fnum); showall = True; n1 = retest(cli, fnum, n); if (n1 != n-1) { printf("ERROR - inconsistent result (%u %u)\n", n1, n); } close_files(cli, fnum); for (i=0;i<n;i++) { printf("{%s, %s, conn = %u, file = %u, start = %.0f, len = %.0f, %u},\n", lock_op_name(recorded[i].lock_op), lock_op_type(recorded[i].lock_type), recorded[i].conn, recorded[i].f, (double)recorded[i].start, (double)recorded[i].len, recorded[i].needed); } }