Ejemplo n.º 1
0
void mesg_queue_destroy(mesg_queue * q) {
	pthread_mutex_destroy(&q->lock);
  uint32_t queued_entries = circular_buffer_size(q->buffer);
  //TODO: Need better handling of the still queued entries
  if(queued_entries>0) {
    printf("%d entries still queued - unqueueing\n", (int)queued_entries);
    for(int i=0; i<queued_entries; ++i) {
      void * dummy=NULL;
      circular_buffer_get(q->buffer, &dummy);
      printf("unqueued %p\n", dummy);
    }
  }
  circular_buffer_free(q->buffer);
	free(q);
}
Ejemplo n.º 2
0
int chitcpd_tcp_state_handle_LAST_ACK(serverinfo_t *si, chisocketentry_t *entry, tcp_event_type_t event) {
  tcp_data_t *data = &entry->socket_state.active.tcp_data;
  if (event == PACKET_ARRIVAL) {

    while (!list_empty(&data->pending_packets)){
      pthread_mutex_lock(&data->lock_pending_packets);
      tcp_packet_t *pack = list_fetch(&(data->pending_packets));
      pthread_mutex_unlock(&data->lock_pending_packets);
      
      tcphdr_t *head  = TCP_PACKET_HEADER(pack);
    
      if (!acceptability_test(data, pack)) {
	send_ACK(si, entry, data);
	chitcp_tcp_packet_free(pack);
	return CHITCP_OK; 
      }
      if (head->ack) {
	if (inside_window(data, pack)) {
	  circular_buffer_free(&data->recv);
	  circular_buffer_free(&data->send);
	  list_destroy(&data->pending_packets);
	  pthread_mutex_destroy(&data->lock_pending_packets);
	  pthread_mutex_destroy(&data->lock_withheld_packets);
	  list_destroy(&data->withheld_packets);
	  free(data);
	  
	  chitcpd_update_tcp_state(si, entry, CLOSED);
	}
      }
      chitcp_tcp_packet_free(pack);
    }
  } else
    chilog(WARNING, "In LAST_ACK state, received unexpected event (%i).", event);

  return CHITCP_OK;
}