コード例 #1
0
ファイル: loops.c プロジェクト: rkrajnc/regulacija
static void loop_handler(void * arg)
{
  uint8_t i = (uint16_t)arg;
  loop_t l; memcpy_P(&l, &loops[i], sizeof(loop_t));
  timer_t prev = loop_next[i];
  
  sch_add(l.func);

  timer_t next = prev + l.period;
  timer_add_cmp(next, (sch_t){ loop_handler, arg, (typeof(l.func.level))-1 });
  assert(in_range(prev, timer_now(), next));
  loop_next[i] = next;
}
コード例 #2
0
ファイル: vrrp_parser.c プロジェクト: jadderbao/keepalived
static void
vrrp_preempt_delay_handler(vector_t *strvec)
{
	vrrp_t *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp);
	vrrp->preempt_delay = atoi(vector_slot(strvec, 1));

	if (VRRP_IS_BAD_PREEMPT_DELAY(vrrp->preempt_delay)) {
		log_message(LOG_INFO, "(%s): Preempt_delay not valid! must be between 0-%d", vrrp->iname, TIMER_MAX_SEC);
		vrrp->preempt_delay = 0;
	}
	vrrp->preempt_delay *= TIMER_HZ;
	vrrp->preempt_time = timer_add_long(timer_now(), vrrp->preempt_delay);
}
コード例 #3
0
ファイル: l2tp_client.c プロジェクト: wuzui03/tunneldigger
int is_timeout(time_t *timer, time_t period)
{
  if (*timer < 0)
    return 0;

  time_t now = timer_now();
  if (now - *timer > period) {
    *timer = now;
    return 1;
  }

  return 0;
}
コード例 #4
0
ファイル: basic.c プロジェクト: codeb2cc/httperf
static void
recv_start(Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg) {
    Call *c = (Call *) obj;
    Time now;

    assert(et == EV_CALL_RECV_START && object_is_call(c));

    now = timer_now();

    basic.call_response_sum += now - c->basic.time_send_start;
    c->basic.time_recv_start = now;
    ++basic.num_responses;
}
コード例 #5
0
ファイル: basic.c プロジェクト: pganti/httperf
static void
recv_start (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg)
{
  Call *c = (Call *) obj;
  Time now;

  assert (et == EV_CALL_RECV_START && object_is_call (c));

  now = timer_now ();

  updatestats(&es_response, now - c->basic.time_send_start);
  c->basic.time_recv_start = now;

}
コード例 #6
0
static void
vrrp_preempt_delay_handler(vector strvec)
{
	vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp);
	vrrp->preempt_delay = atoi(VECTOR_SLOT(strvec, 1));

	if (VRRP_IS_BAD_PREEMPT_DELAY(vrrp->preempt_delay)) {
		log_message(LOG_INFO, "VRRP Error : Preempt_delay not valid !\n");
		log_message(LOG_INFO, "             must be between 0-%d\n",
		       TIMER_MAX_SEC);
		vrrp->preempt_delay = 0;
	}
	vrrp->preempt_delay *= TIMER_HZ;
	vrrp->preempt_time = timer_add_long(timer_now(), vrrp->preempt_delay);
}
コード例 #7
0
ファイル: mcp_call.c プロジェクト: AsamQi/twemperf
static rstatus_t
call_start_timer(struct context *ctx, struct call *call)
{
    struct opt *opt = &ctx->opt;
    struct conn *conn = call->conn;
    double timeout;

    ASSERT(!STAILQ_EMPTY(&conn->call_recvq));

    if (opt->timeout == 0.0) {
        return MCP_OK;
    }

    if (call != STAILQ_FIRST(&conn->call_recvq)) {
        /*
         * Watcdog timer has already been scheduled by a previous call
         * which is still outstanding on this connection.
         */
        ASSERT(conn->watchdog != NULL);
        return MCP_OK;
    }

    ASSERT(conn->watchdog == NULL);
    ASSERT(call->req.send_stop > 0.0);
    ASSERT(timer_now() >= call->req.send_stop);
    ASSERT(opt->timeout > (timer_now() - call->req.send_stop));

    timeout = opt->timeout;
    timeout -= timer_now() - call->req.send_stop;
    conn->watchdog = timer_schedule(core_timeout, conn, timeout);
    if (conn->watchdog == NULL) {
        return MCP_ENOMEM;
    }

    return MCP_OK;
}
コード例 #8
0
ファイル: wsessreq.c プロジェクト: inevity/autodtma
static void
sess_destroyed (Event_Type et, Object *obj, Any_Type regarg, Any_Type callarg)
{
  Sess_Private_Data *priv;
  Sess *sess;
  Time now;
  
  assert (et == EV_SESS_DESTROYED && object_is_sess (obj));
  sess = (Sess *) obj;

  priv = SESS_PRIVATE_DATA (sess);
 
  now=timer_now();
  if(now>=end)core_exit();
  if (++num_sessions_destroyed >= param.wsessreq.num_sessions) core_exit ();
}
コード例 #9
0
ファイル: sess_stat.c プロジェクト: pganti/httperf
static void
sess_destroyed (Event_Type et, Object *obj, Any_Type regarg, Any_Type callarg)
{
  size_t old_size, new_size;
  Sess_Private_Data *priv;
  Sess *sess;
  Time delta, now = timer_now ();

  assert (et == EV_SESS_DESTROYED && object_is_sess (obj));
  sess = (Sess *) obj;
  priv = SESS_PRIVATE_DATA (sess);

  delta = (now - priv->birth_time);
  if (sess->failed)
    {
      ++st.num_failed;
      st.failtime_sum += delta;
    }
  else
    {
      st.num_conns += priv->num_conns;
      ++st.num_completed_since_last_sample;
      ++st.num_completed;
      st.lifetime_sum += delta;
    }

  if (priv->num_calls_completed > st.longest_session)
    {
      st.longest_session = priv->num_calls_completed;

      if (st.longest_session >= st.len_hist_alloced)
	{
	  old_size = st.len_hist_alloced*sizeof (st.len_hist[0]);
	  st.len_hist_alloced = st.longest_session + 16;
	  new_size = st.len_hist_alloced*sizeof (st.len_hist[0]);

	  st.len_hist = realloc (st.len_hist, new_size);
	  if (!st.len_hist)
	    {
	      fprintf (stderr, "%s.sess_stat: Out of memory\n", prog_name);
	      exit (1);
	    }
	  memset ((char *) st.len_hist + old_size, 0, new_size - old_size);
	}
    }
  ++st.len_hist[priv->num_calls_completed];
}
コード例 #10
0
uint32_t handle_storage_info_set(uint16_t handle, handle_info_t* p_info)
{
    if (p_info == NULL)
    {
        return NRF_ERROR_NULL;
    }
    if (handle == RBC_MESH_INVALID_HANDLE)
    {
        return NRF_ERROR_INVALID_ADDR;
    }

    uint16_t handle_index = handle_entry_get(handle, true);
    if (handle_index == HANDLE_CACHE_ENTRY_INVALID)
    {
        /* couldn't find an existing entry, allocate one */
        handle_index = handle_entry_to_head(handle);
        if (handle_index == HANDLE_CACHE_ENTRY_INVALID)
        {
            return NRF_ERROR_NO_MEM;
        }
    }

    uint16_t data_index = m_handle_cache[handle_index].data_entry;

    if (data_index == DATA_CACHE_ENTRY_INVALID)
    {
        data_index = data_entry_allocate();
        if (data_index == DATA_CACHE_ENTRY_INVALID)
        {
            return NRF_ERROR_NO_MEM;
        }
        m_handle_cache[handle_index].data_entry = data_index;
    }
    trickle_timer_reset(&m_data_cache[data_index].trickle, timer_now());

    m_handle_cache[handle_index].version = p_info->version;
    if (m_data_cache[data_index].p_packet != NULL)
    {
        mesh_packet_ref_count_dec(m_data_cache[data_index].p_packet);
    }

    /* reference for the cache */
    mesh_packet_ref_count_inc(p_info->p_packet);
    m_data_cache[m_handle_cache[handle_index].data_entry].p_packet = p_info->p_packet;
    return NRF_SUCCESS;
}
コード例 #11
0
ファイル: service.c プロジェクト: zhoukk/service
static FILE *log_open(uint32_t handle) {
	char tmp[128];
	FILE *f;
	sprintf(tmp, "%u.log", handle);
	f = fopen(tmp, "ab");
	if (f) {
		uint32_t starttime = timer_starttime();
		uint32_t curtime = timer_now();
		time_t ti = starttime + curtime/100;
		service_log(handle, "open log file %s\n", tmp);
		fprintf(f, "open time:%u %s", curtime, ctime(&ti));
		fflush(f);
	} else {
		service_log(handle, "open log file %s failed\n", tmp);
	}
	return f;
}
コード例 #12
0
ファイル: timer.c プロジェクト: cpatni/httperf
/*
 * Checks whether a timer has expired
 */
static bool
timer_has_expired(Any_Type a)
{
	struct Timer   *t = a.vp;

	/*
	 * Only expire currently processing timers 
	 */
	if (t->has_expired == false) {
		if (t->time_started + t->timeout_delay < timer_now()) {
			t->has_expired = true;
			(*t->timeout_callback) (t, t->timer_subject);
			return true;
		}
	}

	return false;
}
コード例 #13
0
ファイル: http.c プロジェクト: dencorpos/keepalived
/* free allocated pieces */
static void
free_all(thread_t * thread)
{
	SOCK *sock_obj = THREAD_ARG(thread);

	DBG("Total read size read = %d Bytes, fd:%d\n",
	    sock_obj->total_size, sock_obj->fd);

	if (sock_obj->buffer)
		FREE(sock_obj->buffer);

	/*
	 * Decrement the current global get number.
	 * => free the reserved thread
	 */
	req->response_time = timer_tol(timer_now());
	thread_add_terminate_event(thread->master);
}
コード例 #14
0
ファイル: rate.c プロジェクト: codeb2cc/httperf
static void
tick(struct Timer *t, Any_Type arg) {
    Time delay, now = timer_now();
    Rate_Generator *rg = arg.vp;

    rg->timer = 0;
    if (rg->done)
        return;

    while (now > rg->next_time) {
        delay = (*rg->next_interarrival_time)(rg);
        if (verbose > 2)
            fprintf(stderr, "next arrival delay = %.4f\n", delay);
        rg->next_time += delay;
        rg->done = ((*rg->tick)(rg->arg) < 0);
        if (rg->done)
            return;
    }
    rg->timer = timer_schedule((Timer_Callback) tick, arg, rg->next_time - now);
}
コード例 #15
0
ファイル: basic.c プロジェクト: codeb2cc/httperf
static void
recv_stop(Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg) {
    Call *c = (Call *) obj;
    int index;

    assert(et == EV_CALL_RECV_STOP && object_is_call(c));
    assert(c->basic.time_recv_start > 0);

    basic.call_xfer_sum += timer_now() - c->basic.time_recv_start;

    basic.hdr_bytes_received += c->reply.header_bytes;
    basic.reply_bytes_received += c->reply.content_bytes;
    basic.footer_bytes_received += c->reply.footer_bytes;

    index = (c->reply.status / 100);
    assert((unsigned) index < NELEMS(basic.num_replies));
    ++basic.num_replies[index];
    ++num_replies;

    ++c->conn->basic.num_calls_completed;
}
コード例 #16
0
ファイル: timer.c プロジェクト: cpatni/httperf
/*
 * Schedules a timer into the active_timer list.  Usually the timer is 
 * requisitioned from the passive_timer list to avoid making extra calls
 * to malloc, but will allocate memory for a new counter if there are no
 * inactive timers available
 */
struct Timer   *
timer_schedule(void (*timeout) (struct Timer * t, Any_Type arg),
	       Any_Type subject, Time delay)
{
	struct Timer   *t;

	if (!is_list_empty(passive_timers)) {
		Any_Type        a = list_pop(passive_timers);
		t = (struct Timer *) a.vp;
	} else if ((t = malloc(sizeof(struct Timer))) == NULL)
		return NULL;

	memset(t, 0, sizeof(struct Timer));
	t->timeout_callback = timeout;
	t->has_expired = false;
	t->timer_subject = subject;
	t->time_started = timer_now();
	t->timeout_delay = delay;

	if (delay > 0)
	{
		Any_Type temp;
		temp.vp = (void *)t;
		list_push(active_timers, temp);
	}
	else
	{
		Any_Type temp;
		temp.vp = (void *)t;
		list_push(persistent_timers, temp);
	}

	if (DBG > 2)
		fprintf(stderr,
			"timer_schedule: t=%p, delay=%gs, subject=%lx\n", t,
			delay, subject.l);

	return t;
}
コード例 #17
0
ファイル: basic.c プロジェクト: inevity/autodtma
static void
init (void)
{
  Any_Type arg;

  basic.conn_lifetime_min = DBL_MAX;
  basic.reply_rate_min = DBL_MAX;
  arg.l = 0;
  #ifdef EXTENDED_STATS
	start=timer_now();
  #endif
  event_register_handler (EV_PERF_SAMPLE, perf_sample, arg);
  event_register_handler (EV_CONN_FAILED, conn_fail, arg);
  event_register_handler (EV_CONN_TIMEOUT, conn_timeout, arg);
  event_register_handler (EV_CONN_NEW, conn_created, arg);
  event_register_handler (EV_CONN_CONNECTING, conn_connecting, arg);
  event_register_handler (EV_CONN_CONNECTED, conn_connected, arg);
  event_register_handler (EV_CONN_DESTROYED, conn_destroyed, arg);
  event_register_handler (EV_CALL_SEND_START, send_start, arg);
  event_register_handler (EV_CALL_SEND_STOP, send_stop, arg);
  event_register_handler (EV_CALL_RECV_START, recv_start, arg);
  event_register_handler (EV_CALL_RECV_STOP, recv_stop, arg);
}
コード例 #18
0
ファイル: timer_q.c プロジェクト: rkrajnc/regulacija
void timer_int()
{
  slot_t c = slot[first];
  slot[first].next = MAX_TIMERS;

#ifndef NDEBUG
  timer_t now = timer_now();
  if (in_range(timer_tracked_get(), c.cmp, now)) {
    DBG static timer_t timer_late_max;
    timer_late_max = MAX(timer_late_max, now - c.cmp);
  }
#endif

  if (c.next == first) {
    first = MAX_TIMERS;
    timer_unset();
  } else {
    timer_tracked = c.cmp;
    first = c.next;
    timer_set(slot[first].cmp);
  }
  
  sch_add(c.func);
}
コード例 #19
0
ファイル: basic.c プロジェクト: inevity/autodtma
static void
recv_stop (Event_Type et, Object *obj, Any_Type reg_arg, Any_Type call_arg)
{
  Call *c = (Call *) obj;
  int index;
  Time transfer_time;
  assert (et == EV_CALL_RECV_STOP && object_is_call (c));
  assert (c->basic.time_recv_start > 0);
  transfer_time=timer_now () - c->basic.time_recv_start;
  basic.call_xfer_sum += transfer_time;
 basic.hdr_bytes_received += c->reply.header_bytes;
  basic.reply_bytes_received += c->reply.content_bytes;
  basic.footer_bytes_received += c->reply.footer_bytes;

  index = (c->reply.status / 100);
  assert ((unsigned) index < NELEMS (basic.num_replies));
  ++basic.num_replies[index];
  ++num_replies;
#ifdef EXTENDED_STATS
  	basic.measurement[measure_index].connect=c->conn->basic.connect;
        basic.measurement[measure_index].reply=c->basic.reply;
  	basic.measurement[measure_index].xfer=transfer_time;
	basic.measurement[measure_index].response_size = c->reply.header_bytes + c->reply.content_bytes + c->reply.footer_bytes;
        basic.measurement[measure_index].id = c->sess_id;
	if(c->conn->basic.connect!=-1)		
		basic.measurement[measure_index].start=c->conn->basic.time_connect_start-start;
  	else		
		basic.measurement[measure_index].start=c->basic.time_send_start-start;
  	basic.measurement[measure_index].num_active_conns=num_active_conns;
  	measure_index++;
  	if(measure_index==MAX_LOG_SIZE)
		measure_index=0;
#endif
  c->conn->basic.connect=-1;
  ++c->conn->basic.num_calls_completed;
}
コード例 #20
0
ファイル: vrrp_daemon.c プロジェクト: vrit/keepalived
/* Daemon init sequence */
static void
start_vrrp(void)
{
	/* Initialize sub-system */
	init_interface_queue();
	kernel_netlink_init();
	gratuitous_arp_init();
	ndisc_init();

	/* Parse configuration file */
	global_data = alloc_global_data();
	vrrp_data = alloc_vrrp_data();
	init_data(conf_file, vrrp_init_keywords);
	if (!vrrp_data) {
		stop_vrrp();
		return;
	}
	init_global_data(global_data);

#ifdef _WITH_SNMP_
	if (!reload && (global_data->enable_snmp_keepalived || global_data->enable_snmp_rfc)) {
		vrrp_snmp_agent_init(global_data->snmp_socket);
#ifdef _WITH_SNMP_RFC_
		vrrp_start_time = timer_now();
#endif
	}
#endif

#ifdef _WITH_LVS_
	if (vrrp_ipvs_needed()) {
		/* Initialize ipvs related */
		if (ipvs_start() != IPVS_SUCCESS) {
			stop_vrrp();
			return;
		}
	}
#endif

	if (reload) {
		clear_diff_saddresses();
		clear_diff_srules();
		clear_diff_sroutes();
		clear_diff_vrrp();
		clear_diff_script();
	}

	/* Complete VRRP initialization */
	if (!vrrp_complete_init()) {
		if (vrrp_ipvs_needed()) {
			stop_vrrp();
		}
		return;
	}

#ifdef _HAVE_LIBIPTC_
	iptables_init();
#endif

	/* Post initializations */
#ifdef _DEBUG_
	log_message(LOG_INFO, "Configuration is using : %lu Bytes", mem_allocated);
#endif

	/* Set static entries */
	netlink_iplist(vrrp_data->static_addresses, IPADDRESS_ADD);
	netlink_rulelist(vrrp_data->static_rules, IPRULE_ADD);
	netlink_rtlist(vrrp_data->static_routes, IPROUTE_ADD);

	/* Dump configuration */
	if (__test_bit(DUMP_CONF_BIT, &debug)) {
		dump_global_data(global_data);
		dump_vrrp_data(vrrp_data);
	}

	/* Initialize linkbeat */
	init_interface_linkbeat();

	/* Init & start the VRRP packet dispatcher */
	thread_add_event(master, vrrp_dispatcher_init, NULL,
			 VRRP_DISPATCHER);
}
コード例 #21
0
//-----------------------------------------------------------------
// usb_control_send: Perform a transfer via IN
//-----------------------------------------------------------------
int usb_control_send(unsigned char *buf, int size)
{
	t_time tS;
	int send;
	int remain;
	int count = 0;
    int err = 0;

    log_printf(USBLOG_SETUP_IN, "USB: usb_control_send %d\n", size);

    // Loop until partial packet sent
    do
	{
		remain = size - count;
		send = MIN(remain, EP0_MAX_PACKET_SIZE);

        log_printf(USBLOG_SETUP_IN_DBG, " Remain %d, Send %d\n", remain, send);

		usbhw_load_tx_buffer(ENDPOINT_CONTROL, buf, (unsigned char) send);

		buf += send;
		count += send;

        log_printf(USBLOG_SETUP_IN_DBG, " Sent %d, Remain %d\n", send, (size - count));

		tS = timer_now();
		while ( !usbhw_has_tx_space( ENDPOINT_CONTROL ) )
		{
            if (timer_diff(timer_now(), tS) > USB_CTRL_TX_TIMEOUT)
			{
                log_printf(USBLOG_ERR, "USB: Timeout sending IN data\n");
                err = 1;
				break;
			}            
		}
	}
    while (send >= EP0_MAX_PACKET_SIZE);

    if (!err)
    {
        log_printf(USBLOG_SETUP_IN, "USB: Sent total %d\n", count);

	    // Wait for ACK from host
	    tS = timer_now();
	    do
        {
            if (timer_diff(timer_now(), tS) > USB_CTRL_TX_TIMEOUT)
		    {
			    log_printf(USBLOG_ERR, "USB: ACK not received\n");
                err = 1;
			    break;
		    }
	    } 
        while (!usbhw_is_rx_ready(ENDPOINT_CONTROL));

        usbhw_clear_rx_ready(ENDPOINT_CONTROL);

        if (!err)
        {
            log_printf(USBLOG_SETUP_IN, "USB: ACK received\n");
        }
    }

    return !err;
}
コード例 #22
0
uint32_t dfu_evt_handler(bl_evt_t* p_evt)
{
    __LOG("BL EVT (0x%x)\n", p_evt->type);
    switch (p_evt->type)
    {
        case BL_EVT_TYPE_ECHO:
            __LOG("\tEcho: %s\n", p_evt->params.echo.str);
            break;
        case BL_EVT_TYPE_DFU_ABORT:
            {
                __LOG("\tAbort event. Reason: 0x%x\n", p_evt->params.dfu.abort.reason);
                rbc_mesh_event_t evt;
                evt.type = RBC_MESH_EVENT_TYPE_DFU_END;
                evt.params.dfu.end.dfu_type = m_transfer_state.type;
                evt.params.dfu.end.role = m_transfer_state.role;
                evt.params.dfu.end.fwid = m_transfer_state.fwid;
                evt.params.dfu.end.end_reason = p_evt->params.dfu.abort.reason;
                memset(&m_transfer_state, 0, sizeof(dfu_transfer_state_t));
                rbc_mesh_event_push(&evt);
            }
            break;

        case BL_EVT_TYPE_DFU_NEW_FW:
            {
                __LOG("\tNew firmware!\n");
                rbc_mesh_event_t evt;
                evt.type = RBC_MESH_EVENT_TYPE_DFU_NEW_FW_AVAILABLE;
                evt.params.dfu.new_fw.dfu_type = p_evt->params.dfu.new_fw.fw_type;
                evt.params.dfu.new_fw.new_fwid = p_evt->params.dfu.new_fw.fwid;
                if (get_curr_fwid(
                            p_evt->params.dfu.new_fw.fw_type,
                            &evt.params.dfu.new_fw.current_fwid) == NRF_SUCCESS)
                {
                    rbc_mesh_event_push(&evt);
                }
            }
            break;

        case BL_EVT_TYPE_DFU_REQ:
            {
                __LOG("\tSource/relay request!\n");
                /* Forward to application */
                rbc_mesh_event_t evt;
                switch (p_evt->params.dfu.req.role)
                {
                    case DFU_ROLE_RELAY:
                        evt.type = RBC_MESH_EVENT_TYPE_DFU_RELAY_REQ;
                        evt.params.dfu.relay_req.dfu_type = p_evt->params.dfu.req.dfu_type;
                        evt.params.dfu.relay_req.fwid = p_evt->params.dfu.req.fwid;
                        evt.params.dfu.relay_req.authority = p_evt->params.dfu.req.dfu_type;
                        break;
                    case DFU_ROLE_SOURCE:
                        evt.type = RBC_MESH_EVENT_TYPE_DFU_SOURCE_REQ;
                        evt.params.dfu.source_req.dfu_type = p_evt->params.dfu.req.dfu_type;
                        break;
                    default:
                        return NRF_ERROR_NOT_SUPPORTED;
                }
                rbc_mesh_event_push(&evt);
            }
            break;

        case BL_EVT_TYPE_DFU_START:
            {
                __LOG("\tDFU start\n");
                if (p_evt->params.dfu.start.role == DFU_ROLE_TARGET)
                {
                    m_transfer_state.state = DFU_STATE_TARGET;
                }
                else if (p_evt->params.dfu.start.role == DFU_ROLE_RELAY)
                {
                    m_transfer_state.state = DFU_STATE_RELAY;
                }
                rbc_mesh_event_t evt;
                evt.type = RBC_MESH_EVENT_TYPE_DFU_START;
                evt.params.dfu.start.dfu_type = p_evt->params.dfu.start.dfu_type;
                evt.params.dfu.start.fwid = p_evt->params.dfu.start.fwid;
                evt.params.dfu.start.role = p_evt->params.dfu.start.role;
                rbc_mesh_event_push(&evt);
                m_timer_evt.cb = abort_timeout;
                return timer_sch_reschedule(&m_timer_evt, timer_now() + TIMER_START_TIMEOUT);
            }


        case BL_EVT_TYPE_DFU_DATA_SEGMENT_RX:
            m_transfer_state.data_progress = (uint8_t) (
                    ((uint32_t) p_evt->params.dfu.data_segment.received_segment * 100) /
                    ((uint32_t) p_evt->params.dfu.data_segment.total_segments));
            m_timer_evt.cb = abort_timeout;
            return timer_sch_reschedule(&m_timer_evt, timer_now() + TIMER_DATA_TIMEOUT);

        case BL_EVT_TYPE_DFU_END:
            {
                __LOG("\tDFU END!\n");
                rbc_mesh_event_t evt;
                evt.type = RBC_MESH_EVENT_TYPE_DFU_END;
                evt.params.dfu.end.dfu_type = p_evt->params.dfu.end.dfu_type;
                evt.params.dfu.end.fwid = p_evt->params.dfu.end.fwid;
                evt.params.dfu.end.end_reason = DFU_END_SUCCESS;
                evt.params.dfu.end.role = p_evt->params.dfu.end.role;
                rbc_mesh_event_push(&evt);
                timer_sch_abort(&m_timer_evt);
            }
            break;

        case BL_EVT_TYPE_BANK_AVAILABLE:
            {
                __LOG("\tDFU BANK AVAILABLE\n");
                rbc_mesh_event_t evt;
                evt.type = RBC_MESH_EVENT_TYPE_DFU_BANK_AVAILABLE;
                evt.params.dfu.bank.dfu_type     = p_evt->params.bank_available.bank_dfu_type;
                evt.params.dfu.bank.fwid         = p_evt->params.bank_available.bank_fwid;
                evt.params.dfu.bank.is_signed    = p_evt->params.bank_available.is_signed;
                evt.params.dfu.bank.p_start_addr = p_evt->params.bank_available.p_bank_addr;
                rbc_mesh_event_push(&evt);
            }
            break;

        case BL_EVT_TYPE_FLASH_ERASE:
            {

                if (p_evt->params.flash.erase.start_addr & (NRF_FICR->CODEPAGESIZE - 1))
                {
                    return NRF_ERROR_INVALID_ADDR;
                }
                if (p_evt->params.flash.erase.length & (NRF_FICR->CODEPAGESIZE - 1))
                {
                    return NRF_ERROR_INVALID_LENGTH;
                }

                uint32_t error_code = mesh_flash_op_push(FLASH_OP_TYPE_ERASE, &p_evt->params.flash);
                if (error_code == NRF_SUCCESS)
                {
                    __LOG("\tErase flash at: 0x%x (length %d)\n", p_evt->params.flash.erase.start_addr, p_evt->params.flash.erase.length);
                }
                return error_code;
            }

        case BL_EVT_TYPE_FLASH_WRITE:
            {
                if (!IS_WORD_ALIGNED(p_evt->params.flash.write.start_addr))
                {
                    return NRF_ERROR_INVALID_ADDR;
                }
                if (!IS_WORD_ALIGNED(p_evt->params.flash.write.length))
                {
                    return NRF_ERROR_INVALID_LENGTH;
                }
                uint32_t error_code = mesh_flash_op_push(FLASH_OP_TYPE_WRITE, &p_evt->params.flash);
                if (error_code == NRF_SUCCESS)
                {
                    __LOG("\tWrite flash at: 0x%x (length %d)\n", p_evt->params.flash.write.start_addr, p_evt->params.flash.write.length);
                }
                return error_code;
            }

        case BL_EVT_TYPE_TX_RADIO:
            __LOG("\tRADIO TX! SLOT %d, count %d, interval: %s, handle: %x\n",
                p_evt->params.tx.radio.tx_slot,
                p_evt->params.tx.radio.tx_count,
                p_evt->params.tx.radio.interval_type == BL_RADIO_INTERVAL_TYPE_EXPONENTIAL ? "exponential" : "periodic",
                p_evt->params.tx.radio.p_dfu_packet->packet_type
            );

            if (m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet)
            {
                mesh_packet_ref_count_dec(m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet);
                m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet = NULL;
            }
            if (mesh_packet_acquire(&m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet))
            {
                uint32_t time_now = timer_now();
                /* build packet */
                mesh_packet_set_local_addr(m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet);
                m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->header.type = BLE_PACKET_TYPE_ADV_NONCONN_IND;
                m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->header.length = DFU_PACKET_OVERHEAD + p_evt->params.tx.radio.length;
                ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->adv_data_type = MESH_ADV_DATA_TYPE;
                ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->data[0] = (MESH_UUID & 0xFF);
                ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->data[1] = (MESH_UUID >> 8) & 0xFF;
                ((ble_ad_t*) m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload)->adv_data_length = DFU_PACKET_ADV_OVERHEAD + p_evt->params.tx.radio.length;
                memcpy(&m_tx_slots[p_evt->params.tx.radio.tx_slot].p_packet->payload[4], p_evt->params.tx.radio.p_dfu_packet, p_evt->params.tx.radio.length);

                /* fill other fields in the TX slot. */
                m_tx_slots[p_evt->params.tx.radio.tx_slot].interval_type = p_evt->params.tx.radio.interval_type;
                m_tx_slots[p_evt->params.tx.radio.tx_slot].repeats = p_evt->params.tx.radio.tx_count;
                m_tx_slots[p_evt->params.tx.radio.tx_slot].tx_count = 0;
                m_tx_slots[p_evt->params.tx.radio.tx_slot].order_time = time_now + DFU_TX_TIMER_MARGIN_US + (rand_prng_get(&m_prng) & (DFU_TX_START_DELAY_MASK_US));

                /* Fire away */
                if (!m_tx_scheduled || TIMER_DIFF(m_tx_slots[p_evt->params.tx.radio.tx_slot].order_time, time_now) < TIMER_DIFF(m_tx_timer_evt.timestamp, time_now))
                {
                    m_tx_scheduled = true;
                    timer_sch_reschedule(&m_tx_timer_evt,
                            m_tx_slots[p_evt->params.tx.radio.tx_slot].order_time);
                }
            }
            else
            {
                return NRF_ERROR_NO_MEM;
コード例 #23
0
ファイル: vrrp_scheduler.c プロジェクト: ex3cv/keepalived
/*
 * Initialize state handling
 * --rfc2338.6.4.1
 */
static void
vrrp_init_state(list l)
{
	vrrp_t *vrrp;
	vrrp_sgroup_t *vgroup;
	element e;

	for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) {
		vrrp = ELEMENT_DATA(e);

		/* In case of VRRP SYNC, we have to carefully check that we are
		 * not running floating priorities on any VRRP instance.
		 */
		if (vrrp->sync && !vrrp->sync->global_tracking) {
			element e2;
			tracked_sc_t *sc;
			tracked_if_t *tip;
			int warning = 0;

			if (!LIST_ISEMPTY(vrrp->track_ifp)) {
				for (e2 = LIST_HEAD(vrrp->track_ifp); e2; ELEMENT_NEXT(e2)) {
					tip = ELEMENT_DATA(e2);
					if (tip->weight) {
						tip->weight = 0;
						warning++;
					}
				}
			}

			if (!LIST_ISEMPTY(vrrp->track_script)) {
				for (e2 = LIST_HEAD(vrrp->track_script); e2; ELEMENT_NEXT(e2)) {
					sc = ELEMENT_DATA(e2);
					if (sc->weight) {
						sc->scr->inuse--;
						warning++;
					}
				}
			}

			if (warning > 0) {
				log_message(LOG_INFO, "VRRP_Instance(%s) : ignoring "
						 "tracked script with weights due to SYNC group",
				       vrrp->iname);
			}
		} else {
			/* Register new priority update thread */
			thread_add_timer(master, vrrp_update_priority,
					 vrrp, vrrp->adver_int);
		}

		if (vrrp->wantstate == VRRP_STATE_MAST) {
#ifdef _HAVE_IPVS_SYNCD_
			/* Check if sync daemon handling is needed */
			if (vrrp->lvs_syncd_if)
				ipvs_syncd_cmd(IPVS_STARTDAEMON,
					       vrrp->lvs_syncd_if, IPVS_MASTER,
					       vrrp->vrid);
#endif
			vrrp->state = VRRP_STATE_GOTO_MASTER;
		} else {
			vrrp->ms_down_timer = 3 * vrrp->adver_int
			    + VRRP_TIMER_SKEW(vrrp);
#ifdef _HAVE_IPVS_SYNCD_
			/* Check if sync daemon handling is needed */
			if (vrrp->lvs_syncd_if)
				ipvs_syncd_cmd(IPVS_STARTDAEMON,
					       vrrp->lvs_syncd_if, IPVS_BACKUP,
					       vrrp->vrid);
#endif
			log_message(LOG_INFO, "VRRP_Instance(%s) Entering BACKUP STATE",
			       vrrp->iname);

			/* Set BACKUP state */
			vrrp_restore_interface(vrrp, 0);
			vrrp->state = VRRP_STATE_BACK;
			vrrp_smtp_notifier(vrrp);
			notify_instance_exec(vrrp, VRRP_STATE_BACK);
#ifdef _WITH_SNMP_
			vrrp_snmp_instance_trap(vrrp);
#endif
			vrrp->last_transition = timer_now();

			/* Init group if needed  */
			if ((vgroup = vrrp->sync)) {
				if (GROUP_STATE(vgroup) != VRRP_STATE_BACK) {
					vgroup->state = VRRP_STATE_BACK;
					vrrp_sync_smtp_notifier(vgroup);
					notify_group_exec(vgroup, VRRP_STATE_BACK);
#ifdef _WITH_SNMP_
					vrrp_snmp_group_trap(vgroup);
#endif
				}
			}
		}
	}
}
コード例 #24
0
ファイル: service.c プロジェクト: zhoukk/service
static void log_close(uint32_t handle, FILE *f) {
	service_log(handle, "close log file %u\n", handle);
	fprintf(f, "close time:%u\n", timer_now());
	fclose(f);
}
コード例 #25
0
ファイル: vrrp_daemon.c プロジェクト: Zex/keepalived
/* Daemon init sequence */
static void
start_vrrp(void)
{
	/* Initialize sub-system */
	init_interface_queue();
	kernel_netlink_init();
	gratuitous_arp_init();
	ndisc_init();

	global_data = alloc_global_data();

#ifdef _HAVE_LIBIPTC_
	iptables_init();
#endif

	/* Parse configuration file */
	vrrp_data = alloc_vrrp_data();
	init_data(conf_file, vrrp_init_keywords);
	if (!vrrp_data) {
		stop_vrrp();
		return;
	}
	init_global_data(global_data);

	/* Set the process priority and non swappable if configured */
	if (global_data->vrrp_process_priority)
		set_process_priority(global_data->vrrp_process_priority);

	if (global_data->vrrp_no_swap)
		set_process_dont_swap(4096);	/* guess a stack size to reserve */

#ifdef _WITH_SNMP_
	if (!reload && (global_data->enable_snmp_keepalived || global_data->enable_snmp_rfcv2 || global_data->enable_snmp_rfcv3)) {
		vrrp_snmp_agent_init(global_data->snmp_socket);
#ifdef _WITH_SNMP_RFC_
		vrrp_start_time = timer_now();
#endif
	}
#endif

#ifdef _WITH_LVS_
	if (vrrp_ipvs_needed()) {
		/* Initialize ipvs related */
		if (ipvs_start() != IPVS_SUCCESS) {
			stop_vrrp();
			return;
		}

#ifdef _HAVE_IPVS_SYNCD_
		/* If we are managing the sync daemon, then stop any
		 * instances of it that may have been running if
		 * we terminated abnormally */
		ipvs_syncd_cmd(IPVS_STOPDAEMON, NULL, IPVS_MASTER, 0, true);
		ipvs_syncd_cmd(IPVS_STOPDAEMON, NULL, IPVS_BACKUP, 0, true);
#endif
	}
#endif

	if (reload) {
		clear_diff_saddresses();
#ifdef _HAVE_FIB_ROUTING_
		clear_diff_srules();
		clear_diff_sroutes();
#endif
		clear_diff_vrrp();
		clear_diff_script();
	}
	else {
		/* Clear leftover static entries */
		netlink_iplist(vrrp_data->static_addresses, IPADDRESS_DEL);
#ifdef _HAVE_FIB_ROUTING_
		netlink_rtlist(vrrp_data->static_routes, IPROUTE_DEL);
		netlink_error_ignore = ENOENT;
		netlink_rulelist(vrrp_data->static_rules, IPRULE_DEL, true);
		netlink_error_ignore = 0;
#endif
	}

	/* Complete VRRP initialization */
	if (!vrrp_complete_init()) {
		if (vrrp_ipvs_needed()) {
			stop_vrrp();
		}
		return;
	}

#ifdef _HAVE_LIBIPTC_
	iptables_startup();
#endif

	/* Post initializations */
#ifdef _DEBUG_
	log_message(LOG_INFO, "Configuration is using : %lu Bytes", mem_allocated);
#endif

	/* Set static entries */
	netlink_iplist(vrrp_data->static_addresses, IPADDRESS_ADD);
#ifdef _HAVE_FIB_ROUTING_
	netlink_rtlist(vrrp_data->static_routes, IPROUTE_ADD);
	netlink_rulelist(vrrp_data->static_rules, IPRULE_ADD, false);
#endif

	/* Dump configuration */
	if (__test_bit(DUMP_CONF_BIT, &debug)) {
		list ifl;

		dump_global_data(global_data);
		dump_vrrp_data(vrrp_data);
		ifl = get_if_list();
		if (!LIST_ISEMPTY(ifl))
			dump_list(ifl);
	}

	/* Initialize linkbeat */
	init_interface_linkbeat();

	/* Init & start the VRRP packet dispatcher */
	thread_add_event(master, vrrp_dispatcher_init, NULL,
			 VRRP_DISPATCHER);
}
コード例 #26
0
void mesh_gatt_sd_ble_event_handle(ble_evt_t* p_ble_evt)
{
    if (p_ble_evt->header.evt_id == BLE_GATTS_EVT_WRITE)
    {
        if (p_ble_evt->evt.gatts_evt.params.write.handle == m_mesh_service.ble_val_char_handles.value_handle)
        {
            mesh_gatt_evt_t* p_gatt_evt = (mesh_gatt_evt_t*) p_ble_evt->evt.gatts_evt.params.write.data;
            switch ((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode)
            {
                case MESH_GATT_EVT_OPCODE_DATA:
                    {
                        if (p_gatt_evt->param.data_update.handle == RBC_MESH_INVALID_HANDLE)
                        {
                            mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_HANDLE);
                            break;
                        }
                        uint32_t error_code = vh_local_update(
                                p_gatt_evt->param.data_update.handle,
                                p_gatt_evt->param.data_update.data,
                                p_gatt_evt->param.data_update.data_len);

                        if (error_code == NRF_SUCCESS)
                        {
                            rbc_mesh_event_t mesh_evt;
                            mesh_evt.type = RBC_MESH_EVENT_TYPE_UPDATE_VAL;
                            mesh_evt.params.rx.p_data        = p_gatt_evt->param.data_update.data;
                            mesh_evt.params.rx.data_len      = p_gatt_evt->param.data_update.data_len;
                            mesh_evt.params.rx.value_handle  = p_gatt_evt->param.data_update.handle;
                            mesh_evt.params.rx.version_delta = 1;
                            mesh_evt.params.rx.timestamp_us  = timer_now();
                            if (rbc_mesh_event_push(&mesh_evt) != NRF_SUCCESS)
                            {
                                mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_BUSY);
                            }
                            else
                            {
                                mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_SUCCESS);
                            }
                        }
                        else
                        {
                            mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_BUSY);
                        }

                    }
                    break;

                case MESH_GATT_EVT_OPCODE_FLAG_SET:
                    switch ((mesh_gatt_evt_flag_t) p_gatt_evt->param.flag_update.flag)
                    {
                        case MESH_GATT_EVT_FLAG_PERSISTENT:
                            if (vh_value_persistence_set(p_gatt_evt->param.flag_update.handle,
                                        !!(p_gatt_evt->param.flag_update.value))
                                    != NRF_SUCCESS)
                            {
                                mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_HANDLE);
                                break;
                            }
                            mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_SUCCESS);
                            break;

                        case MESH_GATT_EVT_FLAG_DO_TX:
                            if (p_gatt_evt->param.flag_update.value)
                            {
                                if (vh_value_enable(p_gatt_evt->param.flag_update.handle)
                                        != NRF_SUCCESS)
                                {
                                    mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_HANDLE);
                                    break;
                                }
                                mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_SUCCESS);
                            }
                            else
                            {
                                if (vh_value_disable(p_gatt_evt->param.flag_update.handle)
                                        != NRF_SUCCESS)
                                {
                                    mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_HANDLE);
                                    break;
                                }
                                mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_SUCCESS);
                            }
                            break;

                        default:
                            mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_UNKNOWN_FLAG);
                    }
                    break;

                case MESH_GATT_EVT_OPCODE_FLAG_REQ:
                    switch ((mesh_gatt_evt_flag_t) p_gatt_evt->param.flag_update.flag)
                    {
                        case MESH_GATT_EVT_FLAG_PERSISTENT:
                            {
                                if (p_gatt_evt->param.flag_update.handle == RBC_MESH_INVALID_HANDLE)
                                {
                                    mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_HANDLE);
                                    break;
                                }

                                bool is_persistent = false;
                                if (vh_value_persistence_get(p_gatt_evt->param.flag_update.handle, &is_persistent)
                                        != NRF_SUCCESS)
                                {
                                    mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_NOT_FOUND);
                                    break;
                                }

                                mesh_gatt_evt_t rsp_evt;
                                rsp_evt.opcode = MESH_GATT_EVT_OPCODE_FLAG_RSP;
                                rsp_evt.param.flag_update.handle = p_gatt_evt->param.flag_update.handle;
                                rsp_evt.param.flag_update.flag = p_gatt_evt->param.flag_update.flag;
                                rsp_evt.param.flag_update.value = (uint8_t) is_persistent;
                                mesh_gatt_evt_push(&rsp_evt);
                            }
                            break;

                        case MESH_GATT_EVT_FLAG_DO_TX:
                            {
                                bool is_enabled;
                                if (vh_value_is_enabled(p_gatt_evt->param.flag_update.handle, &is_enabled)
                                        != NRF_SUCCESS)
                                {
                                    mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_HANDLE);
                                    break;
                                }

                                mesh_gatt_evt_t rsp_evt;
                                rsp_evt.opcode = MESH_GATT_EVT_OPCODE_FLAG_RSP;
                                rsp_evt.param.flag_update.handle = p_gatt_evt->param.flag_update.handle;
                                rsp_evt.param.flag_update.flag = p_gatt_evt->param.flag_update.flag;
                                rsp_evt.param.flag_update.value = (uint8_t) is_enabled;
                                mesh_gatt_evt_push(&rsp_evt);
                            }
                            break;

                        default:
                            mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_UNKNOWN_FLAG);
                    }
                    break;

                default:
                    mesh_gatt_cmd_rsp_push((mesh_gatt_evt_opcode_t) p_gatt_evt->opcode, MESH_GATT_RESULT_ERROR_INVALID_OPCODE);
            }
        }
        else if (p_ble_evt->evt.gatts_evt.params.write.handle == m_mesh_service.ble_md_char_handles.value_handle)
        {
            mesh_metadata_char_t* p_md = (mesh_metadata_char_t*) p_ble_evt->evt.gatts_evt.params.write.data;
            tc_radio_params_set(p_md->mesh_access_addr, p_md->mesh_channel);
            vh_min_interval_set(p_md->mesh_interval_min_ms);
        }
        else if (p_ble_evt->evt.gatts_evt.params.write.handle == m_mesh_service.ble_val_char_handles.cccd_handle)
        {
            m_mesh_service.notification_enabled = (p_ble_evt->evt.gatts_evt.params.write.data[0] != 0);
        }
    }
    else if (p_ble_evt->header.evt_id == BLE_GAP_EVT_CONNECTED)
    {
        m_active_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
    }
    else if (p_ble_evt->header.evt_id == BLE_GAP_EVT_DISCONNECTED)
    {
        m_active_conn_handle = CONN_HANDLE_INVALID;
    }
}
コード例 #27
0
ファイル: connect.c プロジェクト: Amanjot1507/OS-Work
/* Activity on a socket: input, output, or error...
 */
static void message_handler(struct file_info *fi, int events){
  	printf("Message handler called\n");
	char buf[512];

	if (events & (POLLERR | POLLHUP)) {
		double time;
		int error;
		socklen_t len = sizeof(error);
		if (getsockopt(fi->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
			perror("getsockopt");
		}
		switch (error) {
		case 0:
			printf("Lost connection on socket %d\n", fi->fd);
			time = timer_now() + 1;
			break;
		default:
			printf("Error '%s' on socket %d\n", strerror(error), fi->fd);
			time = timer_now() + 5;
		}

		close(fi->fd);

		/* Start a timer to reconnect.
		 */
		if (fi->type == FI_OUTGOING) {
			timer_start(time, timer_reconnect, fi->uid);
			fi->fd = -1;
			fi->u.fi_outgoing.status = FI_CONNECTING;
		}
		else {
			fi->type = FI_FREE;
		}
		char *my_addr_str = addr_to_string(my_addr);
		char *fi_addr_str = addr_to_string(fi->addr);
		  
		set_dist(nl, graph, nl_nsites(nl), fi_addr_str, my_addr_str, 0);
		updateGraph();
		send_gossip();
		free (my_addr_str);
		free (fi_addr_str);

		return;
	}
	if (events & POLLOUT) {
		int n = send(fi->fd, fi->output_buffer, fi->amount_to_send, 0);
		if (n < 0) {
			perror("send");
		}
		if (n > 0) {
			if (n == fi->amount_to_send) {
				fi->amount_to_send = 0;
			}
			else {
				memmove(&fi->output_buffer[n], fi->output_buffer, fi->amount_to_send - n);
				fi->amount_to_send -= n;
			}
		}
	}
	if (events & POLLIN) {
		add_input(fi);
	}
	if (events & ~(POLLIN|POLLOUT|POLLERR|POLLHUP)) {
		printf("message_handler: unknown events\n");
		fi->events = 0;
	}
}
コード例 #28
0
ファイル: main.c プロジェクト: aquasan/keepalived
int
main(int argc, char **argv)
{
	thread_t thread;

	/* Allocate the room */
	req = (REQ *) MALLOC(sizeof (REQ));

	/* Preset (potentially) non-zero defaults */
	req->hash = hash_default;

	/* Command line parser */
	if (!parse_cmdline(argc, argv, req)) {
		FREE(req);
		exit(0);
	}

	/* Check minimum configuration need */
	if (!req->addr_ip && !req->addr_port && !req->url) {
		FREE(req);
		exit(0);
	}

	/* Init the reference timer */
	req->ref_time = timer_tol(timer_now());
	DBG("Reference timer = %lu\n", req->ref_time);

	/* Init SSL context */
	init_ssl();

	/* Signal handling initialization  */
	signal_init();

	/* Create the master thread */
	master = thread_make_master();

	/* Register the GET request */
	init_sock();

	/*
	 * Processing the master thread queues,
	 * return and execute one ready thread.
	 * Run until error, used for debuging only.
	 * Note that not calling launch_scheduler() does
	 * not activate SIGCHLD handling, however, this
	 * is no issue here.
	 */
	while (thread_fetch(master, &thread))
		thread_call(&thread);

	/* Finalize output informations */
	if (req->verbose)
		printf("Global response time for [%s] =%lu\n",
		       req->url, req->response_time - req->ref_time);

	/* exit cleanly */
	SSL_CTX_free(req->ctx);
	free_sock(sock);
	FREE(req);
	exit(0);
}
コード例 #29
0
void timer_sleep(uint64_t duration_ms)
{
    uint64_t end = timer_now(NULL) + duration_ms * 1000;
    while(timer_now() < end) { ; }
}