Beispiel #1
0
dbuf_t *check_reasm_done(reasm_pile_struct_t *rp, reasm_chunk_t *chk, uint16_t hoffs1, uint16_t hoffs0,
                        char *data, uint16_t len, uint16_t offs, int more) {
  dbuf_t *d = chk->d;

  if (!more) {
    debug(DBG_REASM, 20, "Set desired length %d <= %d + %d\n", chk->esize, offs, len);
    chk->esize = offs+len;
  }
  memcpy(&chk->d->buf[offs], data, len);
  reset_timeout(rp, chk);
  if (d->dsize < offs+len) {
    d->dsize = offs+len;
  }
  debug(DBG_REASM, 20, "Offs: %d, len: %d, chk->esize: %d, chk->hole: %d, d->dsize: %d", 
        offs, len, chk->esize, chk->hole, d->dsize);
  debug_dump(DBG_REASM, 100, d->buf, d->size);
  if (chk->esize == chk->hole) {
    /*
     * reassembly complete. Delete chunk, and return the dbuf.
     * do not unlock since we should have locked it anyway
     */
    d->dsize = chk->esize;
    dispose_chk(rp, chk);
    return d;
  }
  return NULL;
}
void blocking_actor::dequeue(behavior& bhvr, message_id mid) {
  CAF_LOG_TRACE(CAF_MARG(mid, integer_value));
  // try to dequeue from cache first
  if (invoke_from_cache(bhvr, mid)) {
    return;
  }
  // requesting an invalid timeout will reset our active timeout
  uint32_t timeout_id = 0;
  if (mid == invalid_message_id) {
    timeout_id = request_timeout(bhvr.timeout());
  } else {
    request_sync_timeout_msg(bhvr.timeout(), mid);
  }
  // read incoming messages
  for (;;) {
    await_data();
    auto msg = next_message();
    switch (invoke_message(msg, bhvr, mid)) {
      case im_success:
        if (mid == invalid_message_id) {
          reset_timeout(timeout_id);
        }
        return;
      case im_skipped:
        if (msg) {
          push_to_cache(std::move(msg));
        }
        break;
      default:
        // delete msg
        break;
    }
  }
}
// Keep conversions going on for each sensor on each onewire bus
void
operate_onewire_temp_measurement(void)
{
  {
    unsigned char register_testmask;

    if (conv_complete)
      {
        // Not very nice to use a bitmap but we need to spare bytes for the stack to keep things safe:(
        // This bitmap is used to keep track of register conversion initiation information
        register_testmask = 0x01 << register_to_address;

        // Evaluate side effect: Only read until read is succesful
        if (register_conv_initiated & register_testmask)
            read_DS18xxx(register_to_address);

        register_conv_initiated &= ~register_testmask;
        if (issue_convert_for_device(register_to_address))
          register_conv_initiated |= register_testmask;

        // Reset the conversion timer and set the complete flag so we
        // can wait for conversion time expiry of the next device
        reset_timeout(TEMP_CONV_TIMER);
        conv_complete = FALSE;

        if(++register_to_address == NR_OF_TEMP_SENSORS)
          register_to_address = 0;
      }
    else
      {
        conv_complete = timeout_occured(TEMP_CONV_TIMER,
            (DS18x20_CONV_TIME / NR_OF_TEMP_SENSORS) + 50);
      }
  }
}
Beispiel #4
0
static void on_read(h2o_socket_t *sock, const char *err)
{
    struct st_h2o_tunnel_t *tunnel = sock->data;
    h2o_socket_t *dst;
    assert(tunnel != NULL);
    assert(tunnel->sock[0] == sock || tunnel->sock[1] == sock);

    if (err != NULL) {
        close_connection(tunnel);
        return;
    }

    if (sock->bytes_read == 0)
        return;

    h2o_socket_read_stop(sock);
    reset_timeout(tunnel);

    if (tunnel->sock[0] == sock)
        dst = tunnel->sock[1];
    else
        dst = tunnel->sock[0];

    h2o_iovec_t buf;
    buf.base = sock->input->bytes;
    buf.len = sock->input->size;
    h2o_socket_write(dst, &buf, 1, on_write_complete);
}
void blocking_actor::dequeue(behavior& bhvr, message_id mid) {
  // try to dequeue from cache first
  if (invoke_from_cache(bhvr, mid)) {
    return;
  }
  // requesting an invalid timeout will reset our active timeout
  auto timeout_id = request_timeout(bhvr.timeout());
  // read incoming messages
  for (;;) {
    await_data();
    auto msg = next_message();
    switch (invoke_message(msg, bhvr, mid)) {
      case im_success:
        reset_timeout(timeout_id);
        return;
      case im_skipped:
        if (msg) {
          push_to_cache(std::move(msg));
        }
        break;
      default:
        // delete msg
        break;
    }
  }
}
Beispiel #6
0
// Keep conversions going on for each sensor on each onewire bus
void
operate_onewire_temp_measurement(void)
{
  if (conv_complete)
    {
      switch (bus_to_address)
        {
      case 0:
        if (bus0_conv_initiated)
          read_DS18xxx(0);
        bus0_conv_initiated = issue_convert_on_bus(0);
        bus_to_address = 0;
        break;
        }

      // Reset the conversion timer and set the complete flag so we
      // can wait for conversion time expiry on the next bus
      reset_timeout(TEMP_CONV_TIMER);
      conv_complete = FALSE;
    }
  else
    {
      conv_complete = timeout_occured(TEMP_CONV_TIMER,
          DS18x20_CONV_TIME / NR_OF_OW_BUSES);
    }
}
Beispiel #7
0
static void verify_challenge(CcnetProcessor *processor, 
                             char *code, char *code_msg,
                             char *content, int clen)
{
    CcnetKeepaliveProcPriv *priv = GET_PRIV (processor);
    ccnet_debug ("[Conn] Verify Peer Challenge\n");

    if (clen != 40 || memcmp(content, priv->random_buf, 40) != 0) {
        ccnet_debug ("[Conn] Peer Challenge failed\n");
        close_processor(processor);
        return;
    }

    CcnetUser *user = ccnet_peer_get_user(processor->peer);
    if (!user) {
        ccnet_debug ("[Conn] No user for this peer, go to auth done\n");
        processor->peer->auth_done = 1;
        g_signal_emit_by_name (processor->peer, "auth-done");
        
        send_keepalive (processor);
        reset_timeout (processor);
        return;
    }

    if (user->pubkey)
        send_challenge_user(processor, user);
    else
        get_pubkey_user(processor);
}
Beispiel #8
0
	void next_wav(C* c)
	{
		if(wi >= G_N_ELEMENTS(wavs)){
			if(iter++ < 2){
				wi = 0;
			}else{
				g_free(c);
				FINISH_TEST;
			}
		}

		dbg(0, "==========================================================");
		reset_timeout(40000);

		Waveform* w = waveform_new(wavs[wi++]);
		g_object_weak_ref((GObject*)w, finalize_notify, NULL);
		waveform_load_sync(w);

#if 0 // due to internal changes, these tests are no longer valid
		WfGlBlock* blocks = (WfGlBlock*)w->priv->render_data[MODE_MED];
		assert(blocks, "texture container not allocated");
		assert(!blocks->peak_texture[WF_LEFT].main[0], "textures allocated"); // no textures are expected to be allocated.
		assert(!blocks->peak_texture[WF_RIGHT].main[0], "textures allocated");
#endif
		assert(&w->priv->peak, "peak not loaded");
		assert(w->priv->peak.size, "peak size not set");
		assert(w->priv->peak.buf[WF_LEFT], "peak not loaded");
		assert(w->priv->peak.buf[WF_RIGHT], "peak not loaded");

		g_object_unref(w);
		c->next(c);
	}
Beispiel #9
0
static void get_pubkey_user(CcnetProcessor *processor)
{
    ccnet_processor_send_update (processor,
                                 "320", NULL, NULL, 0);
    processor->state = WAIT_PUBKEY_USER;
    reset_timeout(processor);
}
Beispiel #10
0
static void upload_pack(void)
{
	struct string_list symref = STRING_LIST_INIT_DUP;

	head_ref_namespaced(find_symref, &symref);

	if (advertise_refs || !stateless_rpc) {
		reset_timeout();
		head_ref_namespaced(send_ref, &symref);
		for_each_namespaced_ref(send_ref, &symref);
		advertise_shallow_grafts(1);
		packet_flush(1);
	} else {
		head_ref_namespaced(mark_our_ref, NULL);
		for_each_namespaced_ref(mark_our_ref, NULL);
	}
	string_list_clear(&symref, 1);
	if (advertise_refs)
		return;

	receive_needs();
	if (want_obj.nr) {
		get_common_commits();
		create_pack_file();
	}
}
Beispiel #11
0
void upload_pack(struct upload_pack_options *options)
{
	struct string_list symref = STRING_LIST_INIT_DUP;

	stateless_rpc = options->stateless_rpc;
	timeout = options->timeout;
	daemon_mode = options->daemon_mode;

	git_config(upload_pack_config, NULL);

	head_ref_namespaced(find_symref, &symref);

	if (options->advertise_refs || !stateless_rpc) {
		reset_timeout();
		head_ref_namespaced(send_ref, &symref);
		for_each_namespaced_ref(send_ref, &symref);
		advertise_shallow_grafts(1);
		packet_flush(1);
	} else {
		head_ref_namespaced(check_ref, NULL);
		for_each_namespaced_ref(check_ref, NULL);
	}
	string_list_clear(&symref, 1);
	if (options->advertise_refs)
		return;

	receive_needs();
	if (want_obj.nr) {
		get_common_commits();
		create_pack_file();
	}
}
Beispiel #12
0
/* {{{ sapi_apache_read_post
 */
static int sapi_apache_read_post(char *buffer, uint count_bytes TSRMLS_DC)
{
	int total_read_bytes=0, read_bytes;
	request_rec *r = (request_rec *) SG(server_context);
	void (*handler)(int);

	/*
	 * This handles the situation where the browser sends a Expect: 100-continue header
	 * and needs to receive confirmation from the server on whether or not it can send
	 * the rest of the request. RFC 2616
	 *
	 */
	if (!SG(read_post_bytes) && !ap_should_client_block(r)) {
		return total_read_bytes;
	}
 
	handler = signal(SIGPIPE, SIG_IGN);
	while (total_read_bytes<count_bytes) {
		hard_timeout("Read POST information", r); /* start timeout timer */
		read_bytes = get_client_block(r, buffer+total_read_bytes, count_bytes-total_read_bytes);
		reset_timeout(r);
		if (read_bytes<=0) {
			break;
		}
		total_read_bytes += read_bytes;
	}
	signal(SIGPIPE, handler);	
	return total_read_bytes;
}
Beispiel #13
0
static void set_timeout(uint16_t ms)
{
    // clock source is OSC32K
    s_period_counter = BOARD_OSC32_HZ * ms / 1000;
    
    // Reset the counter
    reset_timeout();
}
// called each time a goal is received
void ROSAction::goalCB()
{
	std::cout << "****************************%%%%%%%%%% goalCB %%%%%%%%%%" << std::endl;
	// could add conditions to accept goal or not
	goal_ = as_.acceptNewGoal()->GOAL_;
	std::cout << "Received Goal: " << goal_ << std::endl;

	// send_feedback();

	// if (!busy)
	// {
	// 	feedback_.FEEDBACK_ = NODE_ERROR;
	// 	result_.RESULT_     = NODE_ERROR;
	// }

	if (feedback_.FEEDBACK_ != SUCCESS &&
	    feedback_.FEEDBACK_ != FAILURE)
	{
		bool started;		// is thread running?
		{
			boost::lock_guard<boost::mutex> lock(mutex_started_);
			started = started_;
		}
		std::cout << "started: " << started << std::endl;
		if (started)
		{
			if (goal_ > 0)	    // possitive tick
				reset_timeout();
			else if (goal_ < 0) // negative tick
			{
				std::cout << "Got a negative tick" << std::endl;
				stop();
			}
			else			    // neutral tick
			{}
		}
		else
		{
			if (goal_ > 0)	    // possitive tick
				start();
			else if (goal_ < 0) // negative tick
			{}
			else			    // neutral tick
			{}
		}
	}

	if (feedback_.FEEDBACK_ == SUCCESS ||
	    feedback_.FEEDBACK_ == FAILURE)
	{
		boost::lock_guard<boost::mutex> lock_b(mutex_feedback_);
		boost::lock_guard<boost::mutex> lock_c(mutex_result_);
		feedback_.FEEDBACK_ = NODE_ERROR;
		result_.RESULT_     = NODE_ERROR;
	}

	std::cout << "****************************%%%%%%%%%% goalCB Exit%%%%%%%%%%" << std::endl;
}
Beispiel #15
0
bool it_switch_mode(arg_t a) {
	if (mode == MODE_IMAGE) {
		if (tns.thumbs == NULL)
			tns_init(&tns, filecnt, &win);
		img_close(&img, false);
		reset_timeout(reset_cursor);
		if (img.slideshow) {
			img.slideshow = false;
			reset_timeout(slideshow);
		}
		tns.sel = fileidx;
		tns.dirty = true;
		mode = MODE_THUMB;
	} else {
		load_image(tns.sel);
		mode = MODE_IMAGE;
	}
	return true;
}
Beispiel #16
0
/* A simple time comsuming function. */
static void delay(void) {
    /* Check it is timeput or not. */
    while(is_timeout()) {
        /* Clear the timeout flag. */
        reset_timeout();
        /* Decrease counters. */
        pwm_long--;
        pause_short--;
    }
}
Beispiel #17
0
static int get_common_commits(void)
{
	static char line[1000];
	unsigned char sha1[20];
	char last_hex[41];

	save_commit_buffer = 0;

	for (;;) {
		int len = packet_read_line(0, line, sizeof(line));
		reset_timeout();

		if (!len) {
			if (have_obj.nr == 0 || multi_ack)
				packet_write(1, "NAK\n");
			if (stateless_rpc)
				exit(0);
			continue;
		}
		strip(line, len);
		if (!prefixcmp(line, "have ")) {
			switch (got_sha1(line+5, sha1)) {
			case -1: /* they have what we do not */
				if (multi_ack && ok_to_give_up()) {
					const char *hex = sha1_to_hex(sha1);
					if (multi_ack == 2)
						packet_write(1, "ACK %s ready\n", hex);
					else
						packet_write(1, "ACK %s continue\n", hex);
				}
				break;
			default:
				memcpy(last_hex, sha1_to_hex(sha1), 41);
				if (multi_ack == 2)
					packet_write(1, "ACK %s common\n", last_hex);
				else if (multi_ack)
					packet_write(1, "ACK %s continue\n", last_hex);
				else if (have_obj.nr == 1)
					packet_write(1, "ACK %s\n", last_hex);
				break;
			}
			continue;
		}
		if (!strcmp(line, "done")) {
			if (have_obj.nr > 0) {
				if (multi_ack)
					packet_write(1, "ACK %s\n", last_hex);
				return 0;
			}
			packet_write(1, "NAK\n");
			return -1;
		}
		die("git upload-pack: expected SHA1 list, got '%s'", line);
	}
}
Beispiel #18
0
void
create_large_files()
{
	START_TEST;
	reset_timeout(60000);

	create_large_file(WAV1);
	create_large_file(WAV2);

	FINISH_TEST;
}
Beispiel #19
0
bool i_toggle_animation(arg_t a) {
	if (mode != MODE_IMAGE)
		return false;

	if (img.multi.animate) {
		reset_timeout(animate);
		img.multi.animate = false;
	} else if (img_frame_animate(&img, true)) {
		set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
	}
	return true;
}
Beispiel #20
0
static void upload_pack(void)
{
	reset_timeout();
	head_ref(send_ref, NULL);
	for_each_ref(send_ref, NULL);
	packet_flush(1);
	receive_needs();
	if (want_obj.nr) {
		get_common_commits();
		create_pack_file();
	}
}
Beispiel #21
0
cmdreturn_t it_switch_mode(arg_t a)
{
    if (mode == MODE_IMAGE) {
        if (tns.thumbs == NULL) {
            tns_init(&tns, filecnt, &win);
            tns.alpha = img.alpha;
        }
        img_close(&img, false);
        reset_timeout(reset_cursor);
        if (img.ss.on) {
            img.ss.on = false;
            reset_timeout(slideshow);
        }
        tns.sel = fileidx;
        tns.dirty = true;
        mode = MODE_THUMB;
    } else {
        load_image(tns.sel);
        mode = MODE_IMAGE;
    }
    return CMD_DIRTY;
}
Beispiel #22
0
bool i_toggle_slideshow(arg_t a) {
	if (mode == MODE_IMAGE) {
		if (img.slideshow) {
			img.slideshow = false;
			reset_timeout(slideshow);
			return true;
		} else if (fileidx + 1 < filecnt) {
			img.slideshow = true;
			set_timeout(slideshow, img.ss_delay, true);
			return true;
		}
	}
	return false;
}
Beispiel #23
0
bool i_drag(arg_t a) {
	int dx = 0, dy = 0, i, ox, oy, x, y;
	unsigned int ui;
	bool dragging = true, next = false;
	XEvent e;
	Window w;

	if (mode != MODE_IMAGE)
		return false;
	if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
		return false;
	
	win_set_cursor(&win, CURSOR_HAND);

	while (dragging) {
		if (!next)
			XMaskEvent(win.env.dpy,
			           ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
		switch (e.type) {
			case ButtonPress:
			case ButtonRelease:
				dragging = false;
				break;
			case MotionNotify:
				x = e.xmotion.x;
				y = e.xmotion.y;
				if (x >= 0 && x <= win.w && y >= 0 && y <= win.h) {
					dx += x - ox;
					dy += y - oy;
				}
				ox = x;
				oy = y;
				break;
		}
		if (dragging)
			next = XCheckIfEvent(win.env.dpy, &e, is_motionnotify, None);
		if ((!dragging || !next) && (dx != 0 || dy != 0)) {
			if (img_move(&img, dx, dy))
				img_render(&img);
			dx = dy = 0;
		}
	}
	
	win_set_cursor(&win, CURSOR_ARROW);
	set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
	reset_timeout(redraw);

	return false;
}
Beispiel #24
0
static void send_challenge_user(CcnetProcessor *processor, CcnetUser *user)
{
    CcnetKeepaliveProcPriv *priv = GET_PRIV (processor);
    unsigned char *buf;
    int len;

    ccnet_debug ("[Keepalive] Send user challenge to %.8s\n",
                 processor->peer->id);
    RAND_pseudo_bytes (priv->random_buf, 40);
    buf = public_key_encrypt (user->pubkey, priv->random_buf, 40, &len);
    ccnet_processor_send_update (processor, "321", NULL, (char *)buf, len);

    g_free(buf);
    processor->state = WAIT_CHALLENGE_USER;
    reset_timeout (processor);
}
Beispiel #25
0
bool i_toggle_slideshow(arg_t a) {
	if (mode == MODE_IMAGE) {
		if (img.slideshow) {
			img.slideshow = false;
			win_screensaver_restore(&win);
			reset_timeout(slideshow);
			return true;
		} else if ((fileidx + 1 < filecnt) || options->loop) {
			img.slideshow = true;
			win_screensaver_save(&win);
			set_timeout(slideshow, img.ss_delay, true);
			return true;
		}
	}
	return false;
}
Beispiel #26
0
static void
gtk_search_entry_changed (GtkEditable *editable)
{
  GtkSearchEntry *entry = GTK_SEARCH_ENTRY (editable);
  GtkSearchEntryPrivate *priv = GET_PRIV (entry);
  const char *str, *icon_name;
  gboolean cleared;

  /* Update the icons first */
  str = gtk_entry_get_text (GTK_ENTRY (entry));

  if (str == NULL || *str == '\0')
    {
      icon_name = NULL;
      cleared = TRUE;
    }
  else
    {
      if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
        icon_name = "edit-clear-rtl-symbolic";
      else
        icon_name = "edit-clear-symbolic";
      cleared = FALSE;
    }

  g_object_set (entry,
                "secondary-icon-name", icon_name,
                "secondary-icon-activatable", !cleared,
                "secondary-icon-sensitive", !cleared,
                NULL);

  if (cleared)
    {
      if (priv->delayed_changed_id > 0)
        {
          g_source_remove (priv->delayed_changed_id);
          priv->delayed_changed_id = 0;
        }
      g_signal_emit (entry, signals[SEARCH_CHANGED], 0);
    }
  else
    {
      /* Queue up the timeout */
      reset_timeout (entry);
    }
}
Beispiel #27
0
static void tc_irq(void)
{
    // clear the interrupt flag by reading the status register
    tc_read_sr(CONFIG_BSP_BUZZER_REP_TIMER, CONFIG_BSP_BUZZER_REP_CHANNEL);
    
    // run the state machine
    if (s_buzzer)
    {
        if (s_period_counter == 0)
        {
            next_state();
        }
        else
        {
            reset_timeout();
        }
    }
}
Beispiel #28
0
static void verify_challenge_user(CcnetProcessor *processor, 
                                  char *code, char *code_msg,
                                  char *content, int clen)
{
    CcnetKeepaliveProcPriv *priv = GET_PRIV (processor);
    ccnet_debug ("[Conn] Verify User Challenge\n");

    if (clen != 40 || memcmp(content, priv->random_buf, 40) != 0) {
        ccnet_debug ("[Keepalive] Challenge failed\n");
        close_processor(processor);
        return;
    }

    processor->peer->auth_done = 1;
    g_signal_emit_by_name (processor->peer, "auth-done");

    send_keepalive (processor);
    reset_timeout (processor);
}
Beispiel #29
0
static void _clm_nodetrack_callback(
	const SaClmClusterNotificationBufferT *buffer,
	SaUint32T numberOfMembers,
	SaAisErrorT error)
{
	int i;
	int diff;
	int nmb;

	nmb = numberOfMembers;

	for ( i = 0 ; i < buffer->numberOfItems ; i++ )
	{
		if ( buffer->notification[i].clusterChange == SA_CLM_NODE_LEFT )
			nmb--;
	}

	diff = nmb - test_data.nmb_peers;

	test_data.nmb_clm_notifications++;

	diff = ( diff > 0 ? 1 : -1 );

	DPRINTF("    CLM: Members: %d/%d (%d)", nmb, test_data.max_nmb_peers, numberOfMembers);
	reset_timeout(240);

	for ( i = 0 ; i < buffer->numberOfItems ; i++ )
	{
		if ( test_data.master_id < 0 || test_data.master_id > buffer->notification[i].clusterNode.nodeId )
			test_data.master_id = buffer->notification[i].clusterNode.nodeId;
	}

	if ( diff != test_data.expected_diff )
		DIE("The number of peer changed in an unexpected way: %d instead of %d", diff, test_data.expected_diff);

	if ( nmb == test_data.max_nmb_peers )
		test_data.expected_diff = -1;
	else if ( nmb == 1 )
		test_data.expected_diff = 1;

	test_data.nmb_peers = nmb;
}
Beispiel #30
0
void __connman_ntp_stop()
{
	DBG("");

	if (poll_id > 0)
		g_source_remove(poll_id);

	reset_timeout();

	if (channel_watch > 0) {
		g_source_remove(channel_watch);
		channel_watch = 0;
		transmit_fd = 0;
	}

	if (timeserver) {
		g_free(timeserver);
		timeserver = NULL;
	}
}