annotate include/UdpServer.h @ 152:8f98b32d0e23 ClockSync

Last commit on this branch for a while. Overall not very succesful
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 05 Oct 2015 13:06:14 +0100
parents ff28e56e5b7e
children
rev   line source
giuliomoro@44 1 /*
giuliomoro@44 2 * udpServer.h
giuliomoro@44 3 *
giuliomoro@44 4 * Created on: 19 May 2015
giuliomoro@44 5 * Author: giulio moro
giuliomoro@44 6 */
giuliomoro@44 7
giuliomoro@44 8 #ifndef UDPSERVER_H_
giuliomoro@44 9 #define UDPSERVER_H_
giuliomoro@44 10
giuliomoro@44 11 #include <sys/types.h>
giuliomoro@44 12 #include <sys/socket.h>
giuliomoro@44 13 #include <netinet/in.h>
giuliomoro@44 14 #include <arpa/inet.h>
giuliomoro@126 15 #include <errno.h>
giuliomoro@44 16 #include <netdb.h>
giuliomoro@44 17 #include <stdio.h>
giuliomoro@44 18 #include <stdlib.h>
giuliomoro@44 19 #include <unistd.h>
giuliomoro@44 20 #include <string.h>
giuliomoro@44 21
giuliomoro@44 22 class UdpServer{
giuliomoro@44 23 private:
giuliomoro@44 24 int port;
giuliomoro@44 25 int enabled;
giuliomoro@44 26 int inSocket;
giuliomoro@44 27 struct sockaddr_in server;
giuliomoro@44 28 struct timeval stTimeOut;
giuliomoro@121 29 struct timeval stZeroTimeOut;
giuliomoro@44 30 fd_set stReadFDS;
giuliomoro@44 31 int size;
giuliomoro@44 32 void *wasteBuffer;
giuliomoro@44 33 int wasteBufferSize;
giuliomoro@44 34 int length;
giuliomoro@44 35 socklen_t fromLength;
giuliomoro@44 36 struct sockaddr_in from;
giuliomoro@44 37 public:
giuliomoro@44 38 UdpServer();
giuliomoro@44 39 UdpServer(int aPort);
giuliomoro@44 40 ~UdpServer();
giuliomoro@44 41 bool init(int aPort);
giuliomoro@44 42 bool bindToPort(int aPort);
giuliomoro@44 43 int getBoundPort() const;
giuliomoro@121 44 /*
giuliomoro@121 45 * Reads bytes from the socket.
giuliomoro@121 46 *
giuliomoro@121 47 * Drop-in replacement for JUCE DatagramSocket::read()
giuliomoro@121 48 *
giuliomoro@121 49 If blockUntilSpecifiedAmountHasArrived is true, the method will block until maxBytesToRead
giuliomoro@121 50 bytes have been read, (or until an error occurs). If this flag is false, the method will
giuliomoro@121 51 return as much data as is currently available without blocking.
giuliomoro@121 52 */
giuliomoro@121 53 int read(void* destBuffer, int maxBytesToRead, bool blockUntilSpecifiedAmountHasArrived);
giuliomoro@126 54 void close();
giuliomoro@131 55 int empty();
giuliomoro@131 56 int empty(int maxCount);
giuliomoro@121 57 /*
giuliomoro@121 58 * Waits until the socket is ready for reading or writing.
giuliomoro@121 59 *
giuliomoro@121 60 Drop-in replacement for JUCE DatagramSocket::waitUntilReady.
giuliomoro@121 61 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.
giuliomoro@121 62 If the timeout is < 0, it will wait forever, or else will give up after the specified time.
giuliomoro@121 63 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.
giuliomoro@121 64 */
giuliomoro@121 65 int waitUntilReady(bool readyForReading, int timeoutMsecs);
giuliomoro@44 66 };
giuliomoro@44 67
giuliomoro@44 68
giuliomoro@44 69
giuliomoro@44 70 #endif /* UDPSERVER_H_ */