Example #1
0
void zmq_msg_destroy(zmq_msg_t **self_p) {
    if (*self_p) {
        zmq_msg_t *self = *self_p;
        if (self->greedy)
            free(self->data);
        memb_free(&zmq_messages, self);
        *self_p = NULL;
    }
}
Example #2
0
/*---------------------------------------------------------------------------*/
void
phase_update(const struct phase_list *list,
             const rimeaddr_t *neighbor, rtimer_clock_t time,
             int mac_status)
{
  struct phase *e;
  uint8_t tmp;

  /* If we have an entry for this neighbor already, we renew it. */
  e = find_neighbor(list, neighbor);
  if(e != NULL) {
    if(mac_status == MAC_TX_OK) {
#if PHASE_DRIFT_CORRECT
      e->drift = time-e->time;
#endif
      e->time = time;
    }
    /* If the neighbor didn't reply to us, it may have switched
       phase (rebooted). We try a number of transmissions to it
       before we drop it from the phase list. */
    if(mac_status == MAC_TX_NOACK) {
      PRINTF("phase noacks %d to %d.%d\n", e->noacks, neighbor->u8[0], neighbor->u8[1]);
      tmp=      e->noacks;
      e->noacks=tmp++;
      if(e->noacks == 1) {
        timer_set(&e->noacks_timer, MAX_NOACKS_TIME);
      }
      if(e->noacks >= MAX_NOACKS || timer_expired(&e->noacks_timer)) {
        PRINTF("drop %d\n", neighbor->u8[0]);
        list_remove(*list->list, e);
        memb_free(list->memb, e);
        return;
      }
    } else if(mac_status == MAC_TX_OK) {
      e->noacks = 0;
    }
  } else {
    /* No matching phase was found, so we allocate a new one. */
    if(mac_status == MAC_TX_OK && e == NULL) {
      e = memb_alloc(list->memb);
      if(e == NULL) {
        PRINTF("phase alloc NULL\n");
        /* We could not allocate memory for this phase, so we drop
           the last item on the list and reuse it for our phase. */
        e = list_chop(*list->list);
      }
      rimeaddr_copy(&e->neighbor, neighbor);
      e->time = time;
#if PHASE_DRIFT_CORRECT
      e->drift = 0;
#endif
      e->noacks = 0;
      list_push(*list->list, e);
    }
  }
}
Example #3
0
/*---------------------------------------------------------------------------*/
void
httpd_appcall(void *state)
{
  struct httpd_state *s = (struct httpd_state *)state;

  if(uip_closed() || uip_aborted() || uip_timedout()) {
    if(s != NULL) {
      s->script = NULL;
      memb_free(&conns, s);
    }
  } else if(uip_connected()) {
    s = (struct httpd_state *)memb_alloc(&conns);
    if(!s) {
      //puts("Aborting connection - no memory");
      uip_abort();
      return;
      //webserver_log_file(&uip_conn->ripaddr, "reset (no memory block)");
    }
    tcp_markconn(uip_conn, s);
    PSOCK_INIT(&s->sin, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
    PSOCK_INIT(&s->sout, (uint8_t *)s->inputbuf, sizeof(s->inputbuf) - 1);
    PT_INIT(&s->outputpt);
    s->script = NULL;
    s->state = STATE_WAITING;
    timer_set(&s->timer, CLOCK_SECOND * 10);
    handle_connection(s);
  } else if(s) {
    if(uip_poll()) {
      if(timer_expired(&s->timer)) {
        uip_abort();
        s->script = NULL;
        memb_free(&conns, s);
	return;
        //webserver_log_file(&uip_conn->ripaddr, "reset (timeout)");
      }
    } else {
      timer_restart(&s->timer);
    }
    handle_connection(s);
  } else {
    uip_abort();
  }
}
Example #4
0
/*---------------------------------------------------------------------------*/
void
uip_packetqueue_free(struct uip_packetqueue_handle *handle)
{
  PRINTF("uip_packetqueue_free %p\n", handle);
  if(handle->packet != NULL) {
    ctimer_stop(&handle->packet->lifetimer);
    memb_free(&packets_memb, handle->packet);
    handle->packet = NULL;
  }
}
void routingtable_clear(struct routingtable *t){
    
   struct routingtable_item *i;
   for(i = list_head(*t->list); i != NULL; i = list_item_next(i)) {
       list_remove(*t->list, i);
       memb_free(t->memb, i);
   }
   
   PRINTF("DEBUG: Routing table has been cleared\n");
}
Example #6
0
/*---------------------------------------------------------------------------*/
static void
free_packet(struct neighbor_queue *n, struct rdc_buf_list *p)
{
  if(p != NULL) {

//ADILA EDIT 09/02/14
//cc2420_set_channel(list_length(n->queued_packet_list) + 10);
//printf("%d BEFORE FREE Q %d\n", cc2420_get_channel(), list_length(n->queued_packet_list));
//-------------------

    /* Remove packet from list and deallocate */
    list_remove(n->queued_packet_list, p);

    queuebuf_free(p->buf);
    memb_free(&metadata_memb, p->ptr);
    memb_free(&packet_memb, p);

//ADILA EDIT 09/02/14
if((list_length(n->queued_packet_list)) == 0) {
cc2420_set_channel(26);
//printf("%d empty Q %d\n", cc2420_get_channel(), list_length(n->queued_packet_list));

}
//-------------------

    PRINTF("csma: free_queued_packet, queue length %d\n",
        list_length(n->queued_packet_list));
    if(list_head(n->queued_packet_list) != NULL) {
      /* There is a next packet. We reset current tx information */
      n->transmissions = 0;
      n->collisions = 0;
      n->deferrals = 0;
      /* Set a timer for next transmissions */
      ctimer_set(&n->transmit_timer, default_timebase(),
                 transmit_packet_list, n);
    } else {
      /* This was the last packet in the queue, we free the neighbor */
      ctimer_stop(&n->transmit_timer);
      list_remove(neighbor_list, n);
      memb_free(&neighbor_memb, n);
    }
  }
}
Example #7
0
/*---------------------------------------------------------------------------*/
void
phase_remove(const struct phase_list *list, const rimeaddr_t *neighbor)
{
  struct phase *e;
  e = find_neighbor(list, neighbor);
  if(e != NULL) {
    list_remove(*list->list, e);
    memb_free(list->memb, e);
  }
}
Example #8
0
/*---------------------------------------------------------------------------*/
static void
remove_encounter(void *encounter)
{
  struct encounter *e = encounter;

  ctimer_stop(&e->remove_timer);
  ctimer_stop(&e->turn_on_radio_timer);
  list_remove(encounter_list, e);
  memb_free(&encounter_memb, e);
}
Example #9
0
/*---------------------------------------------------------------------------*/
void
queuebuf_free(struct queuebuf *buf)
{
  if(memb_inmemb(&bufmem, buf)) {
    memb_free(&bufmem, buf);
#if QUEUEBUF_STATS
    --queuebuf_len;
    printf("#A q=%d\n", queuebuf_len);
#endif /* QUEUEBUF_STATS */
#if QUEUEBUF_DEBUG
    list_remove(queuebuf_list, buf);
#endif /* QUEUEBUF_DEBUG */
  } else if(memb_inmemb(&refbufmem, buf)) {
    memb_free(&refbufmem, buf);
#if QUEUEBUF_STATS
    --queuebuf_ref_len;
#endif /* QUEUEBUF_STATS */
  }
}
Example #10
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_route_rm(uip_ds6_route_t *route)
{
#if DEBUG != DEBUG_NONE
  assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
  if(route != NULL && route->routes != NULL) {

    PRINTF("uip_ds6_route_rm: removing route: ");
    PRINT6ADDR(&route->ipaddr);
    PRINTF("\n");

    list_remove(route->routes->route_list, route);
    if(list_head(route->routes->route_list) == NULL) {
      /* If this was the only route using this neighbor, remove the
         neibhor from the table */
      PRINTF("uip_ds6_route_rm: removing neighbor too\n");
      nbr_table_remove(nbr_routes, route->routes->route_list);
    }
    memb_free(&routememb, route);

    num_routes--;

    PRINTF("uip_ds6_route_rm num %d\n", num_routes);

#if UIP_DS6_NOTIFICATIONS
    call_route_callback(UIP_DS6_NOTIFICATION_ROUTE_RM,
        &route->ipaddr, uip_ds6_route_nexthop(route));
#endif
#if 0 //(DEBUG & DEBUG_ANNOTATE) == DEBUG_ANNOTATE
    /* we need to check if this was the last route towards "nexthop" */
    /* if so - remove that link (annotation) */
    uip_ds6_route_t *r;
    for(r = uip_ds6_route_head();
        r != NULL;
        r = uip_ds6_route_next(r)) {
      uip_ipaddr_t *nextr, *nextroute;
      nextr = uip_ds6_route_nexthop(r);
      nextroute = uip_ds6_route_nexthop(route);
      if(nextr != NULL &&
         nextroute != NULL &&
         uip_ipaddr_cmp(nextr, nextroute)) {
        /* we found another link using the specific nexthop, so keep the #L */
        return;
      }
    }
    ANNOTATE("#L %u 0\n", uip_ds6_route_nexthop(route)->u8[sizeof(uip_ipaddr_t) - 1]);
#endif
  }

#if DEBUG != DEBUG_NONE
  assert_nbr_routes_list_sane();
#endif /* DEBUG != DEBUG_NONE */
  return;
}
void conditionalFQDiscard() {
	pmesg(200, "%s :: %s :: Line #%d\n", __FILE__, __func__, __LINE__);

	static fe_queue_entry_t* discardQe;// = memb_alloc(&send_stack_mem); 

	if(list_length(send_stack) >= SEND_STACK_SIZE) {

		discardQe = list_chop(send_stack);
		list_remove(message_pool, discardQe -> msg);
		memb_free(&message_pool_mem, discardQe -> msg);

		list_remove(q_entry_pool, discardQe);
		memb_free(&q_entry_pool_mem, discardQe);

#ifdef VIRTQ 
		//	Dropped a data packet, increase virtual queue size
		virtualQueueSize++;
#endif
	}
}
Example #12
0
/*---------------------------------------------------------------------------*/
void
collect_neighbor_list_purge(struct collect_neighbor_list *neighbors_list)
{
  if(neighbors_list == NULL) {
    return;
  }

  while(list_head(neighbors_list->list) != NULL) {
    memb_free(&collect_neighbors_mem, list_pop(neighbors_list->list));
  }
}
Example #13
0
/**
 * @brief neighs_remove
 * @param nodeid
 */
void neighs_remove(uint8_t nodeid){

    struct nodelist_item *n2r = NULL;
    
    n2r = neighs_get(nodeid);
    
    if(n2r != NULL){
        list_remove(neighs_list, n2r);
        memb_free(&neighs_memb, n2r);
    }
}
Example #14
0
/*----------------------------------------------------------------------------*/
  static void
  entry_free(entry_t *e)
  {
    purge_windows(e->windows);
    purge_actions(e->actions);
    list_remove(flowtable, e);
    int res = memb_free(&entries_memb, e); 
    if (res !=0){
      PRINTF("[FLT]: Failed to free an entry. Reference count: %d\n",res);
    }
  }
void delete_device_by_id(uint8_t id){
	device *d;
	for(d=list_head(device_table);
		d!=NULL;
		d=list_item_next(d)){
		if(d->deviceId==id){
			list_remove(device_table, d);
			memb_free(&device_mem, d);
			break;
		}
	}
}
void delete_device_by_name(char *name){
	device *d;
	for(d=list_head(device_table);
		d!=NULL;
		d=list_item_next(d)){
		if(compare_string(d->deviceName, name)){
			list_remove(device_table, d);
			memb_free(&device_mem, d);
			break;
		}
	}
}
Example #17
0
/*---------------------------------------------------------------------------*/
void
collect_neighbor_list_remove(struct collect_neighbor_list *neighbors_list,
                             const rimeaddr_t *addr)
{
    struct collect_neighbor *n = collect_neighbor_list_find(neighbors_list, addr);

    if(n != NULL)
    {
        list_remove(neighbors_list->list, n);
        memb_free(&collect_neighbors_mem, n);
    }
}
Example #18
0
/*---------------------------------------------------------------------------*/
int
neighbor_attr_remove_neighbor(const rimeaddr_t *addr)
{
  struct neighbor_addr *item = neighbor_addr_get(addr);

  if(item != NULL) {
    list_remove(neighbor_addrs, item);
    memb_free(&neighbor_addr_mem, item);
    return 0;
  }
  return -1;
}
Example #19
0
/*---------------------------------------------------------------------------*/
static void
remove_queued_packet(void *item)
{
    struct packetqueue_item *i = item;
    struct packetqueue *q = i->queue;

    list_remove(*q->list, i);
    queuebuf_free(i->buf);
    ctimer_stop(&i->lifetimer);
    memb_free(q->memb, i);
    /*  printf("removing queued packet due to timeout\n");*/
}
Example #20
0
static void
relation_free(relation_t *rel)
{
  attribute_t *attr;

  while((attr = list_pop(rel->attributes)) != NULL) {
    attribute_free(rel, attr);
  }

  list_remove(relations, rel);
  memb_free(&relations_memb, rel);
}
Example #21
0
/*---------------------------------------------------------------------------*/
void
rpl_remove_parent(rpl_dag_t *dag, rpl_parent_t *parent)
{
  rpl_nullify_parent(dag, parent);

  PRINTF("RPL: Removing parent ");
  PRINT6ADDR(&parent->addr);
  PRINTF("\n");

  list_remove(dag->parents, parent);
  memb_free(&parent_memb, parent);
}
Example #22
0
/*---------------------------------------------------------------------------*/
void
uaodv_rt_flush_all(void)
{
  struct uaodv_rt_entry *e;

  while (1) {
    e = list_pop(route_table);
    if(e != NULL)
      memb_free(&route_mem, e);
    else
      break;
  }
} 
Example #23
0
/**
 * Purge expired records
 */
static void
purge(void)
{
  register uip_nameserver_record *e = NULL;
  uint32_t time = clock_seconds();
  for(e = list_head(dns); e != NULL; e = list_item_next(e)) {
    if(DNS_EXPIRATION(e) < time) {
      list_remove(dns, e);
      memb_free(&dnsmemb, e);
      e = list_head(dns);
    }
  }
}
Example #24
0
/*---------------------------------------------------------------------------*/
void
rpl_remove_parent(rpl_dag_t *dag, rpl_parent_t *parent)
{
  rpl_nullify_parent(dag, parent);

  PRINTF("RPL: Removing parent ");
  PRINT6ADDR(&parent->addr);
  PRINTF("\n");
  ANNOTATE("#L %u 0\n", parent->addr.u8[sizeof(uip_ipaddr_t) - 1]);

  list_remove(dag->parents, parent);
  memb_free(&parent_memb, parent);
}
/*----------------------------------------------------------------------------*/
static void
task_is_delete_all(tres_res_t *task)
{
  tres_is_t *is;

  tres_stop_monitoring(task);
  is = list_pop(task->is_list);
  while(is) {
    memb_free(&is_mem, is);
    is = list_pop(task->is_list);
  }
  task_reset_state(task);
}
Example #26
0
/*---------------------------------------------------------------------------*/
void
packetqueue_dequeue(struct packetqueue *q)
{
	struct packetqueue_item *i;

	i = list_head(*q->list);
	if(i != NULL) {
		list_remove(*q->list, i);
		queuebuf_free(i->buf);
		ctimer_stop(&i->lifetimer);
		memb_free(q->memb, i);
	}
}
Example #27
0
void coap_delete_pdu(coap_pdu_t *pdu)
{
#if defined(WITH_POSIX) || defined(WITH_ARDUINO)
    coap_free( pdu );
#endif
#ifdef WITH_LWIP
    if (pdu != NULL) /* accepting double free as the other implementation accept that too */
        pbuf_free(pdu->pbuf);
#endif
#ifdef WITH_CONTIKI
    memb_free(&pdu_storage, pdu);
#endif
}
Example #28
0
/*---------------------------------------------------------------------------*/
static void
send_packet(mac_callback_t sent, void *ptr)
{
  struct queued_packet *q;
  static uint16_t seqno;
  
  packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
  
  /* If the packet is a broadcast, do not allocate a queue
     entry. Instead, just send it out.  */
  if(!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
                   &rimeaddr_null)) {

    /* Remember packet for later. */
    q = memb_alloc(&packet_memb);
    if(q != NULL) {
      q->buf = queuebuf_new_from_packetbuf();
      if(q->buf != NULL) {
        if(packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS) == 0) {
          /* Use default configuration for max transmissions */
          q->max_transmissions = CSMA_MAX_MAC_TRANSMISSIONS;
        } else {
          q->max_transmissions =
            packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS);
        }
        q->transmissions = 0;
        q->collisions = 0;
        q->deferrals = 0;
        q->sent = sent;
        q->cptr = ptr;
        if(packetbuf_attr(PACKETBUF_ATTR_PACKET_TYPE) ==
           PACKETBUF_ATTR_PACKET_TYPE_ACK) {
          list_push(queued_packet_list, q);
        } else {
          list_add(queued_packet_list, q);
        }
        start_transmission_timer();
        return;
      }
      memb_free(&packet_memb, q);
      PRINTF("csma: could not allocate queuebuf, will drop if collision or noack\n");
    }
    PRINTF("csma: could not allocate memb, will drop if collision or noack\n");
  } else {
    PRINTF("csma: send broadcast (%d) or without retransmissions (%d)\n",
           !rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
                         &rimeaddr_null),
           packetbuf_attr(PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS));
  }
  NETSTACK_RDC.send(sent, ptr);
}
void _lmst_nodelist_reconstruct() {
	// clean list
	while(list_length(list_nodelist) > 0) {
		node_t *item = list_pop(list_nodelist);
		networkaddr_reference_free(item->address);
		memb_free(&memb_nodelist, item);
	}

	// add all nodes to list
	neighbor_t *item_neighbor;
	for(item_neighbor = list_head(component_neighbordiscovery_neighbors()); item_neighbor != NULL; item_neighbor = list_item_next(item_neighbor)) {
		node_t *item_node;
		bool found;

		// check for node1
		found = false;
		for(item_node = list_head(list_nodelist); item_node != NULL; item_node = list_item_next(item_node)) {
			if(networkaddr_equal(item_neighbor->node1, item_node->address)) {
				found = true;
				break;
			}
		}
		if(!found) {
			if((item_node = memb_alloc(&memb_nodelist)) == NULL) {
				printf("ERROR[topologycontrol-lmst]: nodelist is full\n");
			} else {
				item_node->address = networkaddr_reference_alloc(item_neighbor->node1);
				item_node->edge = NULL;
				list_add(list_nodelist, item_node);
			}
		}

		// check for node2
		found = false;
		for(item_node = list_head(list_nodelist); item_node != NULL; item_node = list_item_next(item_node)) {
			if(networkaddr_equal(item_neighbor->node2, item_node->address)) {
				found = true;
				break;
			}
		}
		if(!found) {
			if((item_node = memb_alloc(&memb_nodelist)) == NULL) {
				printf("ERROR[topologycontrol-lmst]: nodelist is full\n");
			} else {
				item_node->address = networkaddr_reference_alloc(item_neighbor->node2);
				item_node->edge = NULL;
				list_add(list_nodelist, item_node);
			}
		}
	}
}
Example #30
0
/*---------------------------------------------------------------------------*/
void
httpd_appcall(void *state)
{
  struct httpd_state *s = (struct httpd_state *)state;

  if(uip_closed() || uip_aborted() || uip_timedout()) {
    if(s != NULL) {
      memb_free(&conns, s);
    }
  } else if(uip_connected()) {
    s = (struct httpd_state *)memb_alloc(&conns);
    if(s == NULL) {
      uip_abort();
      return;
    }
    tcp_markconn(uip_conn, s);
    PSOCK_INIT(&s->sin, s->inputbuf, sizeof(s->inputbuf) - 1);
    PSOCK_INIT(&s->sout, s->inputbuf, sizeof(s->inputbuf) - 1);
    PT_INIT(&s->outputpt);
    s->state = STATE_WAITING;
    /*    timer_set(&s->timer, CLOCK_SECOND * 100);*/
    s->timer = 0;
    handle_connection(s);
  } else if(s != NULL) {
    if(uip_poll()) {
      ++s->timer;
      if(s->timer >= 20) {
	uip_abort();
	memb_free(&conns, s);
      }
    } else {
      s->timer = 0;
    }
    handle_connection(s);
  } else {
    uip_abort();
  }
}