From 2d48ae784ea6828e8626c32c848f64232d8f35c0 Mon Sep 17 00:00:00 2001 From: geronimo Date: Fri, 13 Jul 2012 04:26:40 +0200 Subject: initial import --- libs/networking/include/AbstractSocket.h | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 libs/networking/include/AbstractSocket.h (limited to 'libs/networking/include/AbstractSocket.h') diff --git a/libs/networking/include/AbstractSocket.h b/libs/networking/include/AbstractSocket.h new file mode 100644 index 0000000..ff76f52 --- /dev/null +++ b/libs/networking/include/AbstractSocket.h @@ -0,0 +1,63 @@ +/** + * ======================== legal notice ====================== + * + * File: AbstractSocket.h + * Created: 4. Juli 2012, 07:13 + * Author: Geronimo + * Project: libnetworking: classes for tcp/ip sockets and http-protocol handling + * + * CMP - compound media player + * + * is a client/server mediaplayer intended to play any media from any workstation + * without the need to export or mount shares. cmps is an easy to use backend + * with a (ready to use) HTML-interface. Additionally the backend supports + * authentication via HTTP-digest authorization. + * cmpc is a client with vdr-like osd-menues. + * + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! + * published under Creative Commons by-sa + * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * + * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * + * -------------------------------------------------------------- + */ +#ifndef ABSTRACTSOCKET_H +#define ABSTRACTSOCKET_H + +#include +#include + +class cAbstractSocket { +public: + virtual ~cAbstractSocket(); + const cConnectionPoint *ThisSide(void) const { return thisSide; } + const cConnectionPoint *OtherSide(void) const { return others[0]; } + cConnectionPoint *ThisSide(void) { return thisSide; } + cConnectionPoint *OtherSide(void) { return others[0]; } + virtual void ConfigureSocket(int Socket) {} + +protected: + cAbstractSocket(int Port, int Queue = 1); + cAbstractSocket(const char *ServerName, int Port); + bool Connect(); + bool Open(int Port); + cConnectionPoint *Accept(int Port, int TimeoutMs = -1); + bool ForceBlockingIO(void) const { return blocking; } + void SetBlockingIO(bool ForceBlockingIO = true); + cConnectionPoint *GetNameAndAddress(int Socket, struct sockaddr *sa, socklen_t sa_size); + void Close(void); + +private: + int sock; + int queue; + bool blocking; + cConnectionPoint *thisSide; + ConnectionPointList others; ///< client sockets have only one other side, + ///< but server sockets can have multiple connections open at the same time, + ///< so we probabely need a container here. + // cConnectionPointInfo *FetchLocalInfo(int Socket, struct addrinfo *AI); + }; + +#endif /* ABSTRACTSOCKET_H */ + -- cgit v1.2.3