예제 #1
0
파일: shd-socket.c 프로젝트: 4sp1r3/shadow
gboolean socket_addToInputBuffer(Socket* socket, Packet* packet) {
    MAGIC_ASSERT(socket);

    /* check if the packet fits */
    guint length = packet_getPayloadLength(packet);
    if(length > socket_getInputBufferSpace(socket)) {
        return FALSE;
    }

    /* add to our queue */
    g_queue_push_tail(socket->inputBuffer, packet);
    packet_ref(packet);
    socket->inputBufferLength += length;
    packet_addDeliveryStatus(packet, PDS_RCV_SOCKET_BUFFERED);

    /* update the tracker input buffer stats */
    Tracker* tracker = host_getTracker(worker_getCurrentHost());
    Descriptor* descriptor = (Descriptor *)socket;
    tracker_updateSocketInputBuffer(tracker, descriptor->handle, socket->inputBufferLength, socket->inputBufferSize);

    /* we just added a packet, so we are readable */
    if(socket->inputBufferLength > 0) {
        descriptor_adjustStatus((Descriptor*)socket, DS_READABLE, TRUE);
    }

    return TRUE;
}
예제 #2
0
void networkinterface_packetArrived(NetworkInterface* interface, Packet* packet) {
	MAGIC_ASSERT(interface);

	/* a packet arrived. lets try to receive or buffer it */
	guint length = packet_getPayloadLength(packet) + packet_getHeaderSize(packet);
	gssize space = interface->inBufferSize - interface->inBufferLength;
	utility_assert(space >= 0);

	if(length <= space) {
		/* we have space to buffer it */
		packet_ref(packet);
		g_queue_push_tail(interface->inBuffer, packet);
		interface->inBufferLength += length;
		packet_addDeliveryStatus(packet, PDS_RCV_INTERFACE_BUFFERED);

		/* we need a trigger if we are not currently receiving */
		if(!(interface->flags & NIF_RECEIVING)) {
			_networkinterface_scheduleNextReceive(interface);
		}
	} else {
		/* buffers are full, drop packet */
		packet_addDeliveryStatus(packet, PDS_RCV_INTERFACE_DROPPED);
	}
}