annotate include/UdpServer.h @ 44:f5b5c648cd5d ultra-staging

- added (unused) simple c++ classes for udp datagrams\n- added tests for the new classes
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 20 May 2015 18:07:16 +0100
parents
children 2197435e8fb4
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@44 15 #include <netdb.h>
giuliomoro@44 16 #include <stdio.h>
giuliomoro@44 17 #include <stdlib.h>
giuliomoro@44 18 #include <unistd.h>
giuliomoro@44 19 #include <string.h>
giuliomoro@44 20
giuliomoro@44 21 class UdpServer{
giuliomoro@44 22 private:
giuliomoro@44 23 int port;
giuliomoro@44 24 int enabled;
giuliomoro@44 25 int inSocket;
giuliomoro@44 26 struct sockaddr_in server;
giuliomoro@44 27 struct timeval stTimeOut;
giuliomoro@44 28 fd_set stReadFDS;
giuliomoro@44 29 int size;
giuliomoro@44 30 void *wasteBuffer;
giuliomoro@44 31 int wasteBufferSize;
giuliomoro@44 32 int length;
giuliomoro@44 33 socklen_t fromLength;
giuliomoro@44 34 struct sockaddr_in from;
giuliomoro@44 35 public:
giuliomoro@44 36 UdpServer();
giuliomoro@44 37 UdpServer(int aPort);
giuliomoro@44 38 ~UdpServer();
giuliomoro@44 39 bool init(int aPort);
giuliomoro@44 40 bool bindToPort(int aPort);
giuliomoro@44 41 int getBoundPort() const;
giuliomoro@44 42 int read(void *destBuffer,
giuliomoro@44 43 int maxBytesToRead);
giuliomoro@44 44 int emptySocket();
giuliomoro@44 45 int emptySocket(int maxBytes);
giuliomoro@44 46 void *getWaste();
giuliomoro@44 47 };
giuliomoro@44 48
giuliomoro@44 49
giuliomoro@44 50
giuliomoro@44 51 #endif /* UDPSERVER_H_ */