Ejemplo n.º 1
0
void udp_close(UDP* udp) {
	MAGIC_ASSERT(udp);
	node_closeDescriptor(worker_getPrivate()->cached_node, udp->super.super.super.handle);
}
Ejemplo n.º 2
0
static void channel_close(Channel* channel) {
	MAGIC_ASSERT(channel);
	descriptor_adjustStatus((Descriptor*)channel, DS_CLOSED, TRUE);
	node_closeDescriptor(worker_getPrivate()->cached_node, channel->super.super.handle);
}
Ejemplo n.º 3
0
static void _tcp_setState(TCP* tcp, enum TCPState state) {
	MAGIC_ASSERT(tcp);

	tcp->stateLast = tcp->state;
	tcp->state = state;

	debug("%s <-> %s: moved from TCP state '%s' to '%s'", tcp->super.boundString, tcp->super.peerString,
			tcp_stateToAscii(tcp->stateLast), tcp_stateToAscii(tcp->state));

	/* some state transitions require us to update the descriptor status */
	switch (state) {
		case TCPS_LISTEN: {
			descriptor_adjustStatus((Descriptor*)tcp, DS_ACTIVE, TRUE);
			break;
		}
		case TCPS_SYNSENT: {
			break;
		}
		case TCPS_SYNRECEIVED: {
			break;
		}
		case TCPS_ESTABLISHED: {
			tcp->flags |= TCPF_WAS_ESTABLISHED;
			if(tcp->state != tcp->stateLast) {
				_tcp_autotune(tcp);
			}
			descriptor_adjustStatus((Descriptor*)tcp, DS_ACTIVE|DS_WRITABLE, TRUE);
			break;
		}
		case TCPS_CLOSING: {
			break;
		}
		case TCPS_CLOSEWAIT: {
			break;
		}
		case TCPS_CLOSED: {
			/* user can no longer use socket */
			descriptor_adjustStatus((Descriptor*)tcp, DS_ACTIVE, FALSE);

			/*
			 * servers have to wait for all children to close.
			 * children need to notify their parents when closing.
			 */
			if(!tcp->server || g_hash_table_size(tcp->server->children) <= 0) {
				if(tcp->child && tcp->child->parent) {
					TCP* parent = tcp->child->parent;

					/* tell my server to stop accepting packets for me
					 * this will destroy the child and NULL out tcp->child */
					g_hash_table_remove(tcp->child->parent->server->children, (gconstpointer)&(tcp->child->key));

					/* if i was the server's last child and its waiting to close, close it */
					g_assert(parent->server);
					if((parent->state == TCPS_CLOSED) && (g_hash_table_size(parent->server->children) <= 0)) {
						/* this will unbind from the network interface and free socket */
						node_closeDescriptor(worker_getPrivate()->cached_node, parent->super.super.super.handle);
					}
				}

				/* this will unbind from the network interface and free socket */
				node_closeDescriptor(worker_getPrivate()->cached_node, tcp->super.super.super.handle);
			}
			break;
		}
		case TCPS_TIMEWAIT: {
			/* schedule a close timer self-event to finish out the closing process */
			TCPCloseTimerExpiredEvent* event = tcpclosetimerexpired_new(tcp);
			worker_scheduleEvent((Event*)event, CONFIG_TCPCLOSETIMER_DELAY, 0);
			break;
		}
		default:
			break;
	}
}
Ejemplo n.º 4
0
static void _epoll_close(Epoll* epoll) {
	MAGIC_ASSERT(epoll);
	descriptor_adjustStatus(&(epoll->super), DS_CLOSED, TRUE);
	node_closeDescriptor(worker_getPrivate()->cached_node, epoll->super.handle);
}