2007-10-21 15:31:21 +02:00
|
|
|
/*
|
2013-02-23 01:03:27 +01:00
|
|
|
* socket.h: IPTV plugin for the Video Disk Recorder
|
2007-10-21 15:31:21 +02:00
|
|
|
*
|
|
|
|
* See the README file for copyright information and how to reach the author.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __IPTV_SOCKET_H
|
|
|
|
#define __IPTV_SOCKET_H
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
2012-07-10 21:12:29 +02:00
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif // __FreeBSD__
|
2007-10-21 15:31:21 +02:00
|
|
|
|
|
|
|
class cIptvSocket {
|
2012-04-01 23:35:32 +02:00
|
|
|
private:
|
2013-02-23 16:12:46 +01:00
|
|
|
int socketPortM;
|
2012-04-01 23:35:32 +02:00
|
|
|
|
2007-10-21 15:31:21 +02:00
|
|
|
protected:
|
2014-04-05 18:11:30 +02:00
|
|
|
enum {
|
|
|
|
eReportIntervalS = 300 // in seconds
|
|
|
|
};
|
2013-02-23 16:12:46 +01:00
|
|
|
int socketDescM;
|
|
|
|
struct sockaddr_in sockAddrM;
|
2014-04-05 18:11:30 +02:00
|
|
|
time_t lastErrorReportM;
|
|
|
|
int packetErrorsM;
|
|
|
|
int sequenceNumberM;
|
2013-02-23 16:12:46 +01:00
|
|
|
bool isActiveM;
|
2007-10-21 15:31:21 +02:00
|
|
|
|
|
|
|
protected:
|
2013-02-23 16:12:46 +01:00
|
|
|
bool OpenSocket(const int portP, const bool isUdpP);
|
2007-10-21 15:31:21 +02:00
|
|
|
void CloseSocket(void);
|
2013-02-23 16:12:46 +01:00
|
|
|
bool CheckAddress(const char *addrP, in_addr_t *inAddrP);
|
2007-10-21 15:31:21 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
cIptvSocket();
|
|
|
|
virtual ~cIptvSocket();
|
|
|
|
};
|
|
|
|
|
2007-10-21 19:32:43 +02:00
|
|
|
class cIptvUdpSocket : public cIptvSocket {
|
2010-09-15 16:37:20 +02:00
|
|
|
private:
|
2013-02-23 16:12:46 +01:00
|
|
|
in_addr_t streamAddrM;
|
|
|
|
in_addr_t sourceAddrM;
|
|
|
|
bool useIGMPv3M;
|
2010-09-15 16:37:20 +02:00
|
|
|
|
2007-10-21 19:32:43 +02:00
|
|
|
public:
|
|
|
|
cIptvUdpSocket();
|
|
|
|
virtual ~cIptvUdpSocket();
|
2013-02-23 16:12:46 +01:00
|
|
|
virtual int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
|
2012-09-30 17:42:40 +02:00
|
|
|
bool OpenSocket(const int Port);
|
2013-02-23 16:12:46 +01:00
|
|
|
bool OpenSocket(const int Port, const char *streamAddrP, const char *sourceAddrP, bool useIGMPv3P);
|
2010-09-15 16:37:20 +02:00
|
|
|
void CloseSocket(void);
|
2012-04-01 23:35:32 +02:00
|
|
|
bool JoinMulticast(void);
|
|
|
|
bool DropMulticast(void);
|
2007-10-21 19:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class cIptvTcpSocket : public cIptvSocket {
|
|
|
|
public:
|
|
|
|
cIptvTcpSocket();
|
|
|
|
virtual ~cIptvTcpSocket();
|
2013-02-23 16:12:46 +01:00
|
|
|
virtual int Read(unsigned char* bufferAddrP, unsigned int bufferLenP);
|
|
|
|
bool OpenSocket(const int portP, const char *streamAddrP);
|
2010-09-15 22:41:25 +02:00
|
|
|
void CloseSocket(void);
|
|
|
|
bool ConnectSocket(void);
|
2013-02-23 16:12:46 +01:00
|
|
|
bool ReadChar(char* bufferAddrP, unsigned int timeoutMsP);
|
|
|
|
bool Write(const char* bufferAddrP, unsigned int bufferLenP);
|
2007-10-21 19:32:43 +02:00
|
|
|
};
|
|
|
|
|
2007-10-21 15:31:21 +02:00
|
|
|
#endif // __IPTV_SOCKET_H
|
|
|
|
|