SASC-NG
DVBSoftCAM

network.h

Go to the documentation of this file.
00001 /*
00002  * Softcam plugin to VDR (C++)
00003  *
00004  * This code is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This code is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
00018  */
00019 
00020 #ifndef ___NETWORK_H
00021 #define ___NETWORK_H
00022 
00023 #include <vdr/thread.h>
00024 #include <vdr/tools.h>
00025 #include "misc.h"
00026 
00027 // ----------------------------------------------------------------
00028 
00029 extern const char *netscript;
00030 extern int netTimeout;
00031 
00032 // ----------------------------------------------------------------
00033 
00034 class cNetWatcher;
00035 
00036 class cNetSocket : public cSimpleItem, private cMutex {
00037 friend class cNetWatcher;
00038 private:
00039   int sd;
00040   char *hostname;
00041   int port, dummy, conTimeout, rwTimeout, idleTimeout;
00042   bool udp, connected, quietlog;
00043   cTimeMs activity;
00044   //
00045   int Select(bool forRead, int timeout);
00046   void Activity(void);
00047   bool GetAddr(struct sockaddr_in *saddr, const char *Hostname, int Port);
00048   int GetSocket(bool Udp);
00049   cString StrError(int err) const;
00050 public:
00051   cNetSocket(void);
00052   ~cNetSocket();
00053   bool Connect(const char *Hostname, int Port, int timeout=-1);
00054   bool Bind(const char *Hostname, int Port);
00055   void Disconnect(void);
00056   int Read(unsigned char *data, int len, int timeout=-1);
00057   int Write(const unsigned char *data, int len, int timeout=-1);
00058   int SendTo(const char *Host, int Port, const unsigned char *data, int len, int timeout=-1);
00059   void Flush(void);
00060   bool Connected(void) const { return connected; }
00061   void SetQuietLog(bool ql) { quietlog=ql; }
00062   void SetConnectTimeout(int to) { conTimeout=to; }
00063   void SetRWTimeout(int to) { rwTimeout=to; }
00064   void SetIdleTimeout(int to) { idleTimeout=to; }
00065   void SetUDP(bool u) { udp=u; }
00066   };
00067 
00068 #endif //___NETWORK_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines