static void _tcpchild_free(TCPChild* child) { MAGIC_ASSERT(child); /* make sure our tcp doesnt try to free the child again */ child->tcp->child = NULL; descriptor_unref(child->tcp); descriptor_unref(child->parent); MAGIC_CLEAR(child); g_free(child); }
void networkinterface_free(NetworkInterface* interface) { MAGIC_ASSERT(interface); /* unref all packets sitting in our input buffer */ while(interface->inBuffer && !g_queue_is_empty(interface->inBuffer)) { Packet* packet = g_queue_pop_head(interface->inBuffer); packet_unref(packet); } g_queue_free(interface->inBuffer); /* unref all sockets wanting to send */ while(interface->rrQueue && !g_queue_is_empty(interface->rrQueue)) { Socket* socket = g_queue_pop_head(interface->rrQueue); descriptor_unref(socket); } g_queue_free(interface->rrQueue); priorityqueue_free(interface->fifoQueue); g_hash_table_destroy(interface->boundSockets); dns_deregister(worker_getDNS(), interface->address); address_unref(interface->address); if(interface->pcapFile) { fclose(interface->pcapFile); } MAGIC_CLEAR(interface); g_free(interface); }
void tcpretransmittimerexpired_free(TCPRetransmitTimerExpiredEvent* event) { MAGIC_ASSERT(event); descriptor_unref(event->tcp); MAGIC_CLEAR(event); g_free(event); }
static void _epollwatch_free(gpointer data) { EpollWatch* watch = data; MAGIC_ASSERT(watch); descriptor_removeStatusListener(watch->descriptor, watch->listener); listener_free(watch->listener); descriptor_unref(watch->descriptor); MAGIC_CLEAR(watch); g_free(watch); }
/* round robin queuing discipline ($ man tc)*/ static Packet* _networkinterface_selectRoundRobin(NetworkInterface* interface, gint* socketHandle) { Packet* packet = NULL; while(!packet && !g_queue_is_empty(interface->rrQueue)) { /* do round robin to get the next packet from the next socket */ Socket* socket = g_queue_pop_head(interface->rrQueue); packet = socket_pullOutPacket(socket); *socketHandle = *descriptor_getHandleReference((Descriptor*)socket); if(socket_peekNextPacket(socket)) { /* socket has more packets, and is still reffed from before */ g_queue_push_tail(interface->rrQueue, socket); } else { /* socket has no more packets, unref it from the sendable queue */ descriptor_unref((Descriptor*) socket); } } return packet; }
/* first-in-first-out queuing discipline ($ man tc)*/ static Packet* _networkinterface_selectFirstInFirstOut(NetworkInterface* interface, gint* socketHandle) { /* use packet priority field to select based on application ordering. * this is really a simplification of prioritizing on timestamps. */ Packet* packet = NULL; while(!packet && !priorityqueue_isEmpty(interface->fifoQueue)) { /* do fifo to get the next packet from the next socket */ Socket* socket = priorityqueue_pop(interface->fifoQueue); packet = socket_pullOutPacket(socket); *socketHandle = *descriptor_getHandleReference((Descriptor*)socket); if(socket_peekNextPacket(socket)) { /* socket has more packets, and is still reffed from before */ priorityqueue_push(interface->fifoQueue, socket); } else { /* socket has no more packets, unref it from the sendable queue */ descriptor_unref((Descriptor*) socket); } } return packet; }