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