PUBLIC int (CSCtimerStat) ( CSCtimerType const timer, double* const diffPtr ) { int statStat = CSC_ERROR; struct S_timerType* t = timer; ASSERT_RTN (timer != NULL, "CSCtimerStat: NULL timer", CSC_BADARG); ASSERT_RTN ( \ t->sig_lo == TIMER_SIG, \ "CSCtimerStat: timer blows", \ CSC_CORRUPT \ ); ASSERT_RTN ( \ t->sig_hi == TIMER_SIG, \ "CSCtimerStat: timer blows", \ CSC_CORRUPT \ ); if (t == NULL) return (CSC_BADARG); if ((timerisset(&t->mark)) && (timerisset(&t->diffMark))) { if (diffPtr != NULL) *diffPtr = t->diffStat; statStat = CSC_OK; } return (statStat); }
/* * The real-time timer, interrupting hz times per second. */ void hardclock(struct clockframe *frame) { struct proc *p; struct cpu_info *ci = curcpu(); p = curproc; if (p && ((p->p_flag & (P_SYSTEM | P_WEXIT)) == 0)) { struct process *pr = p->p_p; /* * Run current process's virtual and profile time, as needed. */ if (CLKF_USERMODE(frame) && timerisset(&pr->ps_timer[ITIMER_VIRTUAL].it_value) && itimerdecr(&pr->ps_timer[ITIMER_VIRTUAL], tick) == 0) { atomic_setbits_int(&p->p_flag, P_ALRMPEND); need_proftick(p); } if (timerisset(&pr->ps_timer[ITIMER_PROF].it_value) && itimerdecr(&pr->ps_timer[ITIMER_PROF], tick) == 0) { atomic_setbits_int(&p->p_flag, P_PROFPEND); need_proftick(p); } } /* * If no separate statistics clock is available, run it from here. */ if (stathz == 0) statclock(frame); if (--ci->ci_schedstate.spc_rrticks <= 0) roundrobin(ci); /* * If we are not the primary CPU, we're not allowed to do * any more work. */ if (CPU_IS_PRIMARY(ci) == 0) return; tc_ticktock(); ticks++; /* * Update real-time timeout queue. * Process callouts at a very low cpu priority, so we don't keep the * relatively high clock interrupt priority any longer than necessary. */ if (timeout_hardclock_update()) softintr_schedule(softclock_si); }
int time_stamp ( const char* description ) { int rc; if ( ! (timerisset (&st)) ) return -1; rc = gettimeofday ( &et, NULL ); if ( et.tv_usec >= st.tv_usec ) { fprintf ( stdout, "%s: %ld (%ld - %ld) seconds %ld (%ld - %ld) usec \n", description, (et.tv_sec - st.tv_sec), et.tv_sec, st.tv_sec, (et.tv_usec - st.tv_usec), et.tv_usec, st.tv_usec); } else { fprintf ( stdout, "%s: %ld (%ld - %ld) seconds %ld (%ld - %ld) usec \n", description, ( ( et.tv_sec - 1 ) - st.tv_sec), et.tv_sec, st.tv_sec, ( (et.tv_usec+1000000) - st.tv_usec), et.tv_usec, st.tv_usec ); } return rc; }
static ZEND_RESULT_CODE php_http_client_curl_event_wait(void *context, struct timeval *custom_timeout) { php_http_client_curl_event_context_t *ctx = context; struct timeval timeout; #if DBG_EVENTS fprintf(stderr, "W"); #endif if (!event_initialized(ctx->timeout)) { if (0 > event_assign(ctx->timeout, ctx->evbase, CURL_SOCKET_TIMEOUT, 0, php_http_client_curl_event_timeout_callback, ctx)) { return FAILURE; } } else if (custom_timeout && timerisset(custom_timeout)) { if (0 > event_add(ctx->timeout, custom_timeout)) { return FAILURE; } } else if (!event_pending(ctx->timeout, EV_TIMEOUT, NULL)) { php_http_client_curl_get_timeout(ctx->client->ctx, 1000, &timeout); if (0 > event_add(ctx->timeout, &timeout)) { return FAILURE; } } if (0 > event_base_loop(ctx->evbase, EVLOOP_ONCE)) { return FAILURE; } return SUCCESS; }
int main (int argc, char** argv) { struct timeval startTime; struct timeval timeDiff; struct timeval now; // read time in timeval structure gettimeofday(&startTime, NULL); // printing timeval printf("time now:%ld.%.6ld sec\n", startTime.tv_sec, startTime.tv_usec); sleep (8); gettimeofday(&now, NULL); // get the difference timersub(&now, &startTime, &timeDiff); // checking for non-zero timeval if (timerisset(&timeDiff) ){ printf("Process time:%ld.%.6ld sec\n", timeDiff.tv_sec, timeDiff.tv_usec); }else{ printf("no time elaplsed\n"); } }
/* * Handle NULL or uninitialized times. */ struct timeval *timeof(struct timeval *when) { static struct timeval now; if ((when == NULL && (when = &now)) || !timerisset(when)) gettimeofday(when, NULL); return when; }
static void rlb_token_settimeo(td_rlb_t *rlb, struct timeval **_tv, void *data) { td_rlb_token_t *token = data; struct timeval *tv = &token->timeo; long long us; if (list_empty(&rlb->wait)) { *_tv = NULL; return; } WARN_ON(token->cred >= 0); us = -token->cred; us *= 1000000; us /= token->rate; tv->tv_sec = us / 1000000; tv->tv_usec = us % 1000000; WARN_ON(!timerisset(tv)); *_tv = tv; }
/* * fork_create_child * * Description: Common operations associated with the creation of a child * process * * Parameters: parent_task parent task * child_proc child process * inherit_memory TRUE, if the parents address space is * to be inherited by the child * is64bit TRUE, if the child being created will * be associated with a 64 bit process * rather than a 32 bit process * * Note: This code is called in the fork() case, from the execve() call * graph, if implementing an execve() following a vfork(), from * the posix_spawn() call graph (which implicitly includes a * vfork() equivalent call, and in the system bootstrap case. * * It creates a new task and thread (and as a side effect of the * thread creation, a uthread), which is then associated with the * process 'child'. If the parent process address space is to * be inherited, then a flag indicates that the newly created * task should inherit this from the child task. * * As a special concession to bootstrapping the initial process * in the system, it's possible for 'parent_task' to be TASK_NULL; * in this case, 'inherit_memory' MUST be FALSE. */ thread_t fork_create_child(task_t parent_task, proc_t child_proc, int inherit_memory, int is64bit) { thread_t child_thread = NULL; task_t child_task; kern_return_t result; /* Create a new task for the child process */ result = task_create_internal(parent_task, inherit_memory, is64bit, &child_task); if (result != KERN_SUCCESS) { printf("execve: task_create_internal failed. Code: %d\n", result); goto bad; } /* Set the child process task to the new task */ child_proc->task = child_task; /* Set child task process to child proc */ set_bsdtask_info(child_task, child_proc); /* Propagate CPU limit timer from parent */ if (timerisset(&child_proc->p_rlim_cpu)) task_vtimer_set(child_task, TASK_VTIMER_RLIM); /* Set/clear 64 bit vm_map flag */ if (is64bit) vm_map_set_64bit(get_task_map(child_task)); else vm_map_set_32bit(get_task_map(child_task)); #if CONFIG_MACF /* Update task for MAC framework */ /* valid to use p_ucred as child is still not running ... */ mac_task_label_update_cred(child_proc->p_ucred, child_task); #endif /* * Set child process BSD visible scheduler priority if nice value * inherited from parent */ if (child_proc->p_nice != 0) resetpriority(child_proc); /* Create a new thread for the child process */ result = thread_create(child_task, &child_thread); if (result != KERN_SUCCESS) { printf("execve: thread_create failed. Code: %d\n", result); task_deallocate(child_task); child_task = NULL; } bad: thread_yield_internal(1); return(child_thread); }
void OCTACConfig_sleepKeyingTime(struct timeval keying_timeval) { struct timespec keying_timespec; if (timerisset(&keying_timeval)) { keying_timespec.tv_sec = keying_timeval.tv_sec; keying_timespec.tv_nsec = keying_timeval.tv_usec * 1000; nanosleep(&keying_timespec, NULL); } }
/* End timing, adding difference between start time and current time to elapsed time */ void end_timer(timer *t) { struct timeval end, diff; insistnot(gettimeofday(&end, NULL)); assert(timerisset(&t->start)); timersub(&end, &t->start, &diff); timeradd(&t->elapsed, &diff, &t->elapsed); timerclear(&t->start); }
/* * restoreTimers - restore timers from itimers struct. * * Restores the process interval timers stored in the itimers struct * by resetTimers. * * timers: a reference to the itimers struct passed to the resetTimers * function. * * Errors from setitimer are not expected and are handled using Assert (as in * PGSempahoreLockTimed). */ void restoreTimers(struct itimers *timers) { int err; if (timers == NULL) { /* Coding error! */ elog(FATAL, "Old timer values not provided"); } /* * Restore any active timers. */ if (timerisset(&timers->rtimer.it_interval) || timerisset(&timers->rtimer.it_value)) { err = setitimer(ITIMER_REAL, &timers->rtimer, NULL); Assert(err == 0); } if (timerisset(&timers->vtimer.it_interval) || timerisset(&timers->vtimer.it_value)) { err = setitimer(ITIMER_VIRTUAL, &timers->vtimer, NULL); Assert(err == 0); } if (timerisset(&timers->ptimer.it_interval) || timerisset(&timers->ptimer.it_value)) { err = setitimer(ITIMER_PROF, &timers->ptimer, NULL); Assert(err == 0); } }
/** * DtaRealTimeDiffMs */ int32_t DtaRealTimeDiffMs(void) { struct OsTimeval_t tv; if(!timerisset(&TimeValRef)) return -1; OsGetTime(&tv); timersub(&tv, &TimeValRef, &tv); timerclear(&TimeValRef); return (int32_t) timermsec(&tv); }
static lirc_t get_next_rec_buffer_internal(lirc_t maxusec) { if (rec_buffer.rptr < rec_buffer.wptr) { logprintf(3, "<%c%lu", rec_buffer.data[rec_buffer.rptr] & PULSE_BIT ? 'p' : 's', (__u32) rec_buffer.data[rec_buffer.rptr] & (PULSE_MASK)); rec_buffer.sum += rec_buffer.data[rec_buffer.rptr] & (PULSE_MASK); return (rec_buffer.data[rec_buffer.rptr++]); } else { if (rec_buffer.wptr < RBUF_SIZE) { lirc_t data = 0; unsigned long elapsed = 0; if (timerisset(&rec_buffer.last_signal_time)) { struct timeval current; gettimeofday(¤t, NULL); elapsed = time_elapsed(&rec_buffer.last_signal_time, ¤t); } if (elapsed < maxusec) { data = hw.readdata(maxusec - elapsed); } if (!data) { logprintf(3, "timeout: %u", maxusec); return 0; } if (LIRC_IS_TIMEOUT(data)) { logprintf(1, "timeout received: %lu", (__u32) LIRC_VALUE(data)); if (LIRC_VALUE(data) < maxusec) { return get_next_rec_buffer_internal(maxusec - LIRC_VALUE(data)); } return 0; } rec_buffer.data[rec_buffer.wptr] = data; if (rec_buffer.data[rec_buffer.wptr] == 0) return (0); rec_buffer.sum += rec_buffer.data[rec_buffer.rptr] & (PULSE_MASK); rec_buffer.wptr++; rec_buffer.rptr++; logprintf(3, "+%c%lu", rec_buffer.data[rec_buffer.rptr - 1] & PULSE_BIT ? 'p' : 's', (__u32) rec_buffer.data[rec_buffer.rptr - 1] & (PULSE_MASK)); return (rec_buffer.data[rec_buffer.rptr - 1]); } else { rec_buffer.too_long = 1; return (0); } } return (0); }
static void record_marshal(struct evbuffer *evbuf, struct record *record) { struct evbuffer *addr = evbuffer_new(); struct hash *hash; if (timerisset(&record->tv_start)) evtag_marshal_timeval(evbuf, REC_TV_START, &record->tv_start); if (timerisset(&record->tv_end)) evtag_marshal_timeval(evbuf, REC_TV_END, &record->tv_end); /* Encode an address */ addr_marshal(addr, &record->src); evtag_marshal_buffer(evbuf, REC_SRC, addr); evbuffer_drain(addr, evbuffer_get_length(addr)); addr_marshal(addr, &record->dst); evtag_marshal_buffer(evbuf, REC_DST, addr); evbuffer_drain(addr, evbuffer_get_length(addr)); evtag_marshal_int(evbuf, REC_SRC_PORT, record->src_port); evtag_marshal_int(evbuf, REC_DST_PORT, record->dst_port); evtag_marshal_int(evbuf, REC_PROTO, record->proto); evtag_marshal_int(evbuf, REC_STATE, record->state); if (record->os_fp != NULL) evtag_marshal_string(evbuf, REC_OS_FP, record->os_fp); TAILQ_FOREACH(hash, &record->hashes, next) evtag_marshal(evbuf, REC_HASH, hash->digest, sizeof(hash->digest)); if (record->bytes) evtag_marshal_int(evbuf, REC_BYTES, record->bytes); if (record->flags) evtag_marshal_int(evbuf, REC_FLAGS, record->flags); evbuffer_free(addr); }
void OCTACConfig_sleepThinkTime(struct timeval think_timeval) { long think_time_nsec; struct timespec think_timespec; if (timerisset(&think_timeval)) { think_time_nsec = timeval2usec(think_timeval) * 1000; think_time_nsec = - log(TARandom_drand()) * think_time_nsec; think_timespec.tv_sec = think_time_nsec / 1000000000; think_timespec.tv_nsec = think_time_nsec % 1000000000; nanosleep(&think_timespec, NULL); } }
PUBLIC int (CSCtimerDiff) ( CSCtimerType const timer, double* const diffPtr ) { int diffStat = CSC_ERROR; struct S_timerType* t = timer; ASSERT_RTN (timer != NULL, "CSCtimerDiff: NULL timer", CSC_BADARG); ASSERT_RTN ( \ t->sig_lo == TIMER_SIG, \ "CSCtimerDiff: timer blows", \ CSC_CORRUPT \ ); ASSERT_RTN ( \ t->sig_hi == TIMER_SIG, \ "CSCtimerDiff: timer blows", \ CSC_CORRUPT \ ); #define MARK1 (t->mark) #define MARK2 (t->diffMark) #define DIFF (t->diffStat) if (t == NULL) return (CSC_BADARG); if (timerisset(&MARK1)) { diffStat = gettimeofday (&MARK2, NULL); if (diffStat == 0) { double m1 = (double)MARK1.tv_sec + (double)MARK1.tv_usec / (1000*1000); double m2 = (double)MARK2.tv_sec + (double)MARK2.tv_usec / (1000*1000); DIFF = m2 - m1; if (diffPtr != NULL) *diffPtr = DIFF; diffStat = CSC_OK; } else { diffStat = CSC_ERROR; } } #undef MARK1 #undef MARK2 return (diffStat); }
static gboolean source_prepare(GSource *source, gint *timeout) { int r; struct timeval tv; r = fp_get_next_timeout(&tv); if (r == 0) { *timeout = -1; return FALSE; } if (!timerisset(&tv)) return TRUE; *timeout = (tv.tv_sec * 1000) + (tv.tv_usec / 1000); return FALSE; }
float GetElapsedTime() { static timeval lasttv; timeval tv; float fRet; gettimeofday(&tv, NULL); if (!timerisset(&lasttv)) memcpy(&lasttv, &tv, sizeof(timeval)); fRet = (float)((tv.tv_sec - lasttv.tv_sec) * 1000000) + (tv.tv_usec - lasttv.tv_usec); fRet /= 1000000.0f; memcpy(&lasttv,&tv,sizeof(timeval)); return fRet; }
void InnerConnection::statJobTime() { if (!timerisset(&m_jobBeginTime)) { return; } struct timeval& endTime = m_handleThread->getNowTime(); long long costTimeMs = ((long long)(endTime.tv_sec - m_jobBeginTime.tv_sec ) * 1000000 + (endTime.tv_usec - m_jobBeginTime.tv_usec)) / 1000; if (costTimeMs <= 10) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_10_MS); } else if (costTimeMs <= 30) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_30_MS); } else if (costTimeMs <= 50) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_50_MS); } else if (costTimeMs <= 100) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_100_MS); } else if (costTimeMs <= 300) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_300_MS); } else if (costTimeMs <= 500) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_500_MS); } else if (costTimeMs <= 1000) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_1_S); } else if (costTimeMs <= 3000) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_3_S); } else if (costTimeMs <= 5000) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_5_S); } else if (costTimeMs <= 10000) { EasyStat::Instance()->AddCount(STAT_JOB_TIME_10_S); } else { EasyStat::Instance()->AddCount(STAT_JOB_TIME_MORE); } timerclear(&m_jobBeginTime); }
int replay() { struct timeval tdiff; struct input_event event; int i, outputdev; timerclear(&tdiff); for(i = 0; i < num_events; i++) { struct timeval now, tevent, tsleep; if(read(in_fd, &outputdev, sizeof(outputdev)) != sizeof(outputdev)) { printf("Input read error\n"); return 1; } if(read(in_fd, &event, sizeof(event)) != sizeof(event)) { printf("Input read error\n"); return 2; } gettimeofday(&now, NULL); if (!timerisset(&tdiff)) { timersub(&now, &event.time, &tdiff); } timeradd(&event.time, &tdiff, &tevent); timersub(&tevent, &now, &tsleep); if (tsleep.tv_sec > 0 || tsleep.tv_usec > 100) select(0, NULL, NULL, NULL, &tsleep); event.time = tevent; if(write(out_fds[outputdev], &event, sizeof(event)) != sizeof(event)) { printf("Output write error\n"); return 2; } // printf("input %d, time %ld.%06ld, type %d, code %d, value %d\n", outputdev, // event.time.tv_sec, event.time.tv_usec, event.type, event.code, event.value); } return 0; }
int print_apply(void *d, struct pktq *pktq, struct rule **next_rule) { struct pkt *pkt; TAILQ_FOREACH(pkt, pktq, pkt_next) { uint16_t eth_type = htons(pkt->pkt_eth->eth_type); if (eth_type == ETH_TYPE_IP) _print_ip(pkt->pkt_eth_data, pkt->pkt_end - pkt->pkt_eth_data); else if (eth_type == ETH_TYPE_IPV6) _print_ip6(pkt->pkt_eth_data, pkt->pkt_end - pkt->pkt_eth_data); else _print_eth(pkt->pkt_eth, pkt->pkt_end - pkt->pkt_data); if (timerisset(&pkt->pkt_ts)) printf(" [delay %s]", timerntoa(&pkt->pkt_ts)); printf("\n"); }
static void adjclock(struct timeval *corr) { static int passes = 0; static int smoother = 0; long delta; /* adjustment in usec */ long ndelta; struct timeval now; struct timeval adj; if (!timerisset(corr)) return; adj = *corr; if (adj.tv_sec < MAXADJ && adj.tv_sec > - MAXADJ) { delta = adj.tv_sec*1000000 + adj.tv_usec; /* If the correction is less than the minimum round * trip time for an ICMP packet, and thus * less than the likely error in the measurement, * do not do the entire correction. Do half * or a quarter of it. */ if (delta > -MIN_ROUND*1000 && delta < MIN_ROUND*1000) { if (smoother <= 4) smoother++; ndelta = (unsigned long)delta >> smoother; if (delta < 0) { long mask = (long)~0 & ~((1 << ((sizeof(long) * NBBY) - smoother)) - 1); ndelta |= mask; } if (trace) fprintf(fd, "trimming delta %ld usec to %ld\n", delta, ndelta); adj.tv_usec = ndelta; adj.tv_sec = 0; } else if (smoother > 0) {
static gboolean source_check(GSource *source) { struct fdsource *_fdsource = (struct fdsource *) source; GSList *elem = _fdsource->pollfds; struct timeval tv; int r; if (!elem) return FALSE; do { GPollFD *pollfd = elem->data; if (pollfd->revents) return TRUE; } while ((elem = g_slist_next(elem))); r = fp_get_next_timeout(&tv); if (r == 1 && !timerisset(&tv)) return TRUE; return FALSE; }
/* * Returns 0 on timeout, -1 on error, #bytes read on success. */ ssize_t timed_read(int fd, void *buf, size_t siz, time_t timeout) { struct timeval tv, start, after, duration, tmp; int err, tot = 0, i, r; struct pollfd rfd[1]; char *p = buf; tv.tv_sec = timeout; tv.tv_usec = 0; while (1) { rfd[0].fd = fd; rfd[0].events = POLLIN; rfd[0].revents = 0; gettimeofday(&start, NULL); if ((err = poll(rfd, 1, tv.tv_sec * 1000 + tv.tv_usec / 1000)) <= 0) return err; r = read(fd, p, siz - tot); if (r == -1 || r == 0) return (r); for (i = 0; i < r; i++) if (p[i] == '\r' || p[i] == '\n') { tot += r; return (tot); } gettimeofday(&after, NULL); timersub(&start, &after, &duration); timersub(&tv, &duration, &tmp); tv = tmp; if (tv.tv_sec < 0 || !timerisset(&tv)) return (tot); tot += r; p += r; } }
static void _resend_outgoing(struct pkt *pkt) { if (timerisset(&pkt->pkt_ts)) { timeout_set(&pkt->pkt_ev, _timed_outgoing, pkt); timeout_add(&pkt->pkt_ev, &pkt->pkt_ts); } else { eth_pack_hdr(pkt->pkt_eth, ctx.dmac.addr_eth, ctx.smac.addr_eth, ETH_TYPE_IP); if(ctx.dfile) { struct pcap_pkthdr pkthdr; gettimeofday(&pkthdr.ts, NULL); pkthdr.caplen = pkthdr.len = pkt->pkt_end - pkt->pkt_data; pcap_dump((u_char*)ctx.dfile, &pkthdr, pkt->pkt_data); pcap_dump_flush(ctx.dfile); } else if (eth_send(ctx.eth, pkt->pkt_data, pkt->pkt_end - pkt->pkt_data) < 0) warn("eth_send"); pkt_free(pkt); } }
static void log_emit(int lev, const char *fmt, ...) { va_list va; char *msg = 0; va_start(va, fmt); if( vasprintf(&msg, fmt, va) < 0 ) msg = 0; va_end(va); #if ENABLE_DEBUG_LOGGING static struct timeval t0, t1; struct timeval t2, d0, d1; monotime(&t2); if( !timerisset(&t0) ) t0 = t1 = t0; timersub(&t2, &t1, &d1); timersub(&t2, &t0, &d0); if( d1.tv_sec >= 5 ) t0 = t1 = t2; else t1 = t2; fprintf(stderr, "%ld.%03ld %ld.%03ld %s: %s\n", (long)d0.tv_sec, (long)(d0.tv_usec / 1000), (long)d1.tv_sec, (long)(d1.tv_usec / 1000), log_level_repr(lev), msg ?: fmt); #else fprintf(stderr, "%s: %s\n", log_level_repr(lev), msg ?: fmt); #endif free(msg); }
static RADIUS_PACKET *fr_dhcp_recv_raw_loop(int lsockfd, #ifdef HAVE_LINUX_IF_PACKET_H struct sockaddr_ll *p_ll, #endif RADIUS_PACKET *request_p) { struct timeval tval; RADIUS_PACKET *reply_p = NULL; RADIUS_PACKET *cur_reply_p = NULL; int nb_reply = 0; int nb_offer = 0; dc_offer_t *offer_list = NULL; fd_set read_fd; int retval; memcpy(&tval, &tv_timeout, sizeof(struct timeval)); /* Loop waiting for DHCP replies until timer expires */ while (timerisset(&tval)) { if ((!reply_p) || (cur_reply_p)) { // only debug at start and each time we get a valid DHCP reply on raw socket DEBUG("Waiting for%sDHCP replies for: %d.%06d", (nb_reply>0)?" additional ":" ", (int)tval.tv_sec, (int)tval.tv_usec); } cur_reply_p = NULL; FD_ZERO(&read_fd); FD_SET(lsockfd, &read_fd); retval = select(lsockfd + 1, &read_fd, NULL, NULL, &tval); if (retval < 0) { fr_strerror_printf("Select on DHCP socket failed: %s", fr_syserror(errno)); return NULL; } if ( retval > 0 && FD_ISSET(lsockfd, &read_fd)) { /* There is something to read on our socket */ #ifdef HAVE_LINUX_IF_PACKET_H cur_reply_p = fr_dhcp_recv_raw_packet(lsockfd, p_ll, request_p); #else #ifdef HAVE_LIBPCAP cur_reply_p = fr_dhcp_recv_pcap(pcap); #else #error Need <if/packet.h> or <pcap.h> #endif #endif } else { // Not all implementations of select clear the timer timerclear(&tval); } if (cur_reply_p) { nb_reply ++; if (fr_debug_lvl) print_hex(cur_reply_p); if (fr_dhcp_decode(cur_reply_p) < 0) { fprintf(stderr, "dhcpclient: failed decoding reply\n"); return NULL; } if (!reply_p) reply_p = cur_reply_p; if (cur_reply_p->code == PW_DHCP_OFFER) { VALUE_PAIR *vp1 = fr_pair_find_by_num(cur_reply_p->vps, 54, DHCP_MAGIC_VENDOR, TAG_ANY); /* DHCP-DHCP-Server-Identifier */ VALUE_PAIR *vp2 = fr_pair_find_by_num(cur_reply_p->vps, 264, DHCP_MAGIC_VENDOR, TAG_ANY); /* DHCP-Your-IP-address */ if (vp1 && vp2) { nb_offer ++; offer_list = talloc_realloc(request_p, offer_list, dc_offer_t, nb_offer); offer_list[nb_offer-1].server_addr = vp1->vp_ipaddr; offer_list[nb_offer-1].offered_addr = vp2->vp_ipaddr; } } } } if (0 == nb_reply) { DEBUG("No valid DHCP reply received"); return NULL; } /* display offer(s) received */ if (nb_offer > 0 ) { DEBUG("Received %d DHCP Offer(s):\n", nb_offer); int i; for (i=0; i<nb_reply; i++) { char server_addr_buf[INET6_ADDRSTRLEN]; char offered_addr_buf[INET6_ADDRSTRLEN]; DEBUG("IP address: %s offered by DHCP server: %s\n", inet_ntop(AF_INET, &offer_list[i].offered_addr, offered_addr_buf, sizeof(offered_addr_buf)), inet_ntop(AF_INET, &offer_list[i].server_addr, server_addr_buf, sizeof(server_addr_buf)) ); } } return reply_p; }
/*Print timing stats after Simulation termination */ void print_stats(queue *q){ int ready_count = 0; int wait_count = 0; struct timeval time_total; struct timeval time_now; struct timeval ready_total; struct timeval ready_max_total; struct timeval ready_min_total; struct timeval wait_total; struct timeval wait_max_total; struct timeval wait_min_total; long long int ready_avg; long long int ready_min_avg; long long int ready_max_avg; long long int wait_avg; long long int wait_min_avg; long long int wait_max_avg; task_t *t; gettimeofday(&time_now, NULL); timerclear(&ready_total); timerclear(&ready_max_total); timerclear(&ready_min_total); timerclear(&wait_total); timerclear(&wait_max_total); timerclear(&wait_min_total); while(!empty(q)){ t = front(q); dequeue(q); timeradd(&t->ready_time, &ready_total, &ready_total); timeradd(&t->ready_min, &ready_min_total, &ready_min_total); timeradd(&t->ready_max, &ready_max_total, &ready_max_total); if(timerisset(&t->wait_time)){ timeradd(&t->wait_time, &wait_total, &wait_total); timeradd(&t->wait_min, &wait_min_total, &wait_min_total); timeradd(&t->wait_max, &wait_max_total, &wait_max_total); wait_count++; } ready_count++; } timersub(&time_now, &time_start, &time_total); ready_avg = ((ready_total.tv_sec * 1000000) + ready_total.tv_usec) / ready_count; ready_min_avg = ((ready_min_total.tv_sec * 1000000) + ready_min_total.tv_usec) / ready_count; ready_max_avg = ((ready_max_total.tv_sec * 1000000) + ready_max_total.tv_usec) / ready_count; wait_avg = ((wait_total.tv_sec * 1000000) + wait_total.tv_usec) / wait_count; wait_min_avg = ((wait_min_total.tv_sec * 1000000) + wait_min_total.tv_usec) / wait_count; wait_max_avg = ((wait_max_total.tv_sec * 1000000) + wait_max_total.tv_usec) / wait_count; printf("Total time: %ld.%06ld seconds. ", time_total.tv_sec, time_total.tv_usec); printf("Total overhead: %ld.%06ld seconds. \n", time_overhead.tv_sec, time_overhead.tv_usec); printf("READY | AVG: %llduS MIN AVG: %llduS MAX AVG: %llduS\n", ready_avg, ready_min_avg, ready_max_avg); printf("WAIT | AVG: %llduS MIN AVG: %llduS MAX AVG: %llduS\n", wait_avg, wait_min_avg, wait_max_avg); }
bool BaseTimeVal::IsSet() const { return timerisset(&m_tv); }
/** Allocate a new client from a config section * * @param ctx to allocate new clients in. * @param cs to process as a client. * @param in_server Whether the client should belong to a specific virtual server. * @param with_coa If true and coa_server or coa_pool aren't specified automatically, * create a coa home_server section and add it to the client CONF_SECTION. * @return new RADCLIENT struct. */ RADCLIENT *client_afrom_cs(TALLOC_CTX *ctx, CONF_SECTION *cs, bool in_server, bool with_coa) { RADCLIENT *c; char const *name2; name2 = cf_section_name2(cs); if (!name2) { cf_log_err_cs(cs, "Missing client name"); return NULL; } /* * The size is fine.. Let's create the buffer */ c = talloc_zero(ctx, RADCLIENT); c->cs = cs; memset(&cl_ipaddr, 0, sizeof(cl_ipaddr)); if (cf_section_parse(cs, c, client_config) < 0) { cf_log_err_cs(cs, "Error parsing client section"); error: client_free(c); #ifdef WITH_TCP hs_proto = NULL; cl_srcipaddr = NULL; #endif return NULL; } /* * Global clients can set servers to use, per-server clients cannot. */ if (in_server && c->server) { cf_log_err_cs(cs, "Clients inside of an server section cannot point to a server"); goto error; } /* * Newer style client definitions with either ipaddr or ipaddr6 * config items. */ if (cf_pair_find(cs, "ipaddr") || cf_pair_find(cs, "ipv4addr") || cf_pair_find(cs, "ipv6addr")) { char buffer[128]; /* * Sets ipv4/ipv6 address and prefix. */ c->ipaddr = cl_ipaddr; /* * Set the long name to be the result of a reverse lookup on the IP address. */ ip_ntoh(&c->ipaddr, buffer, sizeof(buffer)); c->longname = talloc_typed_strdup(c, buffer); /* * Set the short name to the name2. */ if (!c->shortname) c->shortname = talloc_typed_strdup(c, name2); /* * No "ipaddr" or "ipv6addr", use old-style "client <ipaddr> {" syntax. */ } else { cf_log_err_cs(cs, "No 'ipaddr' or 'ipv4addr' or 'ipv6addr' configuration " "directive found in client %s", name2); goto error; } c->proto = IPPROTO_UDP; if (hs_proto) { if (strcmp(hs_proto, "udp") == 0) { hs_proto = NULL; #ifdef WITH_TCP } else if (strcmp(hs_proto, "tcp") == 0) { hs_proto = NULL; c->proto = IPPROTO_TCP; # ifdef WITH_TLS } else if (strcmp(hs_proto, "tls") == 0) { hs_proto = NULL; c->proto = IPPROTO_TCP; c->tls_required = true; } else if (strcmp(hs_proto, "radsec") == 0) { hs_proto = NULL; c->proto = IPPROTO_TCP; c->tls_required = true; # endif } else if (strcmp(hs_proto, "*") == 0) { hs_proto = NULL; c->proto = IPPROTO_IP; /* fake for dual */ #endif } else { cf_log_err_cs(cs, "Unknown proto \"%s\".", hs_proto); goto error; } } /* * If a src_ipaddr is specified, when we send the return packet * we will use this address instead of the src from the * request. */ if (cl_srcipaddr) { #ifdef WITH_UDPFROMTO switch (c->ipaddr.af) { case AF_INET: if (fr_pton4(&c->src_ipaddr, cl_srcipaddr, -1, true, false) < 0) { cf_log_err_cs(cs, "Failed parsing src_ipaddr: %s", fr_strerror()); goto error; } break; case AF_INET6: if (fr_pton6(&c->src_ipaddr, cl_srcipaddr, -1, true, false) < 0) { cf_log_err_cs(cs, "Failed parsing src_ipaddr: %s", fr_strerror()); goto error; } break; default: rad_assert(0); } #else WARN("Server not built with udpfromto, ignoring client src_ipaddr"); #endif cl_srcipaddr = NULL; } /* * A response_window of zero is OK, and means that it's * ignored by the rest of the server timers. */ if (timerisset(&c->response_window)) { FR_TIMEVAL_BOUND_CHECK("response_window", &c->response_window, >=, 0, 1000); FR_TIMEVAL_BOUND_CHECK("response_window", &c->response_window, <=, 60, 0); FR_TIMEVAL_BOUND_CHECK("response_window", &c->response_window, <=, main_config.max_request_time, 0); }