Mercurial > hg > beaglert
view include/UdpServer.h @ 343:4823ee13bcac prerelease
basic_libpd now populates pd's audio buffers directly. Updated libpd.so binary. This required an API change with respect to standard libpdAPI because for some strange reason, accessing sys_audioin and sys_audioout directly from the render.cpp file would return invalid values.
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Mon, 06 Jun 2016 15:15:15 +0100 |
parents | c42a6b4dc2d4 |
children |
line wrap: on
line source
/* * udpServer.h * * Created on: 19 May 2015 * Author: giulio moro */ #ifndef UDPSERVER_H_ #define UDPSERVER_H_ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <errno.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> class UdpServer{ private: int port; int enabled; int inSocket; struct sockaddr_in server; struct timeval stTimeOut; struct timeval stZeroTimeOut; fd_set stReadFDS; int size; void *wasteBuffer; int wasteBufferSize; int length; socklen_t fromLength; struct sockaddr_in from; public: UdpServer(); UdpServer(int aPort); ~UdpServer(); bool init(int aPort); bool bindToPort(int aPort); int getBoundPort() const; /* * Reads bytes from the socket. * * Drop-in replacement for JUCE DatagramSocket::read() * If blockUntilSpecifiedAmountHasArrived is true, the method will block until maxBytesToRead bytes have been read, (or until an error occurs). If this flag is false, the method will return as much data as is currently available without blocking. */ int read(void* destBuffer, int maxBytesToRead, bool blockUntilSpecifiedAmountHasArrived); void close(); int empty(); int empty(int maxCount); /* * Waits until the socket is ready for reading or writing. * Drop-in replacement for JUCE DatagramSocket::waitUntilReady. If readyForReading is true, it will wait until the socket is ready for reading; if false, it will wait until it's ready for writing. If the timeout is < 0, it will wait forever, or else will give up after the specified time. If the socket is ready on return, this returns 1. If it times-out before the socket becomes ready, it returns 0. If an error occurs, it returns -1. */ int waitUntilReady(bool readyForReading, int timeoutMsecs); }; #endif /* UDPSERVER_H_ */