コード例 #1
0
void coap_check_timeouts(coap_endpoint_mgr_t * p_endpoint_mgr, int i)
{
	struct queue_hdr_t *p = NULL, *next = NULL;
	coap_endpoint_t * p_endpoint = coap_get_endpoint(p_endpoint_mgr, i);
	if (NULL == p_endpoint)
	{
		return;
	}

	for (p = p_endpoint->m_send_queue.next; p != &p_endpoint->m_send_queue; p = next)
	{
		coap_pkt_t * p_pkt = queue_entry(p, coap_pkt_t, node);
		next = p->next;
		if (p_pkt->last_transmit_time + p_pkt->retransmit_interval < p_endpoint_mgr->m_endpoint_mgr_time_cache) 
		{
			if (p_pkt->retransmit_count < COAP_MAX_RETRANSMIT)
			{
				coap_log_debug_packet((char *)p_pkt);
				sendto(p_endpoint->m_servsock, (const char *)&p_pkt->hdr, p_pkt->packet_length, 0, (struct sockaddr *)&p_endpoint->m_servaddr, sizeof(p_endpoint->m_servaddr));
				
				p_pkt->last_transmit_time = coap_get_milliseconds();
				p_pkt->retransmit_interval <<= 1;
				p_pkt->retransmit_count++;
			}
			else
			{
				coap_free_endpoint(p_endpoint_mgr, i);
				coap_set_endpoint(p_endpoint_mgr, i, NULL);
				break;
			}
		}
	}

	return;
}
コード例 #2
0
ファイル: coap_io.c プロジェクト: Trilliant/libcoap
coap_endpoint_t *
coap_new_endpoint(const coap_address_t *addr, int flags) {
  struct coap_endpoint_t *ep = coap_malloc_contiki_endpoint();

  if (ep) {
    memset(ep, 0, sizeof(struct coap_endpoint_t));
    ep->handle.conn = udp_new(NULL, 0, NULL);

    if (!ep->handle.conn) {
      coap_free_endpoint(ep);
      return NULL;
    }

    coap_address_init(&ep->addr);
    uip_ipaddr_copy(&ep->addr.addr, &addr->addr);
    ep->addr.port = addr->port;
    udp_bind((struct uip_udp_conn *)ep->handle.conn, addr->port);
  }
  return ep;
}