Ejemplo n.º 1
0
void ReceivePacket(int sockfd) {
    OSCPacketBuffer pb;
    struct NetworkReturnAddressStruct *ra;
    int maxclilen=sizeof(struct sockaddr_in);
    int n;
    int capacity = OSCGetReceiveBufferSize();
    int morePackets = 1;
    char *buf;


    while(morePackets) {
	pb = OSCAllocPacketBuffer();
	if (!pb) {
	    OSCWarning("Out of memory for packet buffers---had to drop a packet!");
	    /* How do I actually gobble down the packet? */
	    return;
	}
	buf = OSCPacketBufferGetBuffer(pb);

	/* The type NetworkReturnAddressPtr is const in two ways, so that
	   callback procedures that are passed the pointer can neither change
	   the pointer itself or the data the pointer points to.  But here's
	   where we fill in the return address, so we do a cast to a non-const
	   type. */

	ra = (struct NetworkReturnAddressStruct *) OSCPacketBufferGetClientAddr(pb);
	ra->clilen = maxclilen;
	ra->sockfd = sockfd;

/*	printf("* recvfrom(sockfd %d, buf %p, capacity %d)\n", sockfd, buf, capacity); */
	n = recvfrom(sockfd, buf, capacity, 0, &(ra->cl_addr), &(ra->clilen));

	if (n > 0) {
	    int *sizep = OSCPacketBufferGetSize(pb);
	    *sizep = n;
	    OSCAcceptPacket(pb);
	    if (time_to_quit) return;
	} else {
	    OSCFreePacket(pb);
	    morePackets = 0;
	}
    }
}
Ejemplo n.º 2
0
static void PacketRemoveRef(OSCPacketBuffer packet) {
    --(packet->refcount);
    if (packet->refcount == 0) {
        OSCFreePacket(packet);
    }
}