|
MythTV
0.26-pre
|
00001 /**************************************************************************** 00002 ** 00003 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. 00004 ** 00005 ** This file is part of the Qt3Support module of the Qt Toolkit. 00006 ** 00007 ** This file may be used under the terms of the GNU General Public 00008 ** License versions 2.0 or 3.0 as published by the Free Software 00009 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3 00010 ** included in the packaging of this file. Alternatively you may (at 00011 ** your option) use any later version of the GNU General Public 00012 ** License if such license has been publicly approved by Trolltech ASA 00013 ** (or its successors, if any) and the KDE Free Qt Foundation. In 00014 ** addition, as a special exception, Trolltech gives you certain 00015 ** additional rights. These rights are described in the Trolltech GPL 00016 ** Exception version 1.2, which can be found at 00017 ** http://www.trolltech.com/products/qt/gplexception/ and in the file 00018 ** GPL_EXCEPTION.txt in this package. 00019 ** 00020 ** Please review the following information to ensure GNU General 00021 ** Public Licensing requirements will be met: 00022 ** http://trolltech.com/products/qt/licenses/licensing/opensource/. If 00023 ** you are unsure which license is appropriate for your use, please 00024 ** review the following information: 00025 ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview 00026 ** or contact the sales department at sales@trolltech.com. 00027 ** 00028 ** In addition, as a special exception, Trolltech, as the sole 00029 ** copyright holder for Qt Designer, grants users of the Qt/Eclipse 00030 ** Integration plug-in the right for the Qt/Eclipse Integration to 00031 ** link to functionality provided by Qt Designer and its related 00032 ** libraries. 00033 ** 00034 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, 00035 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR 00036 ** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly 00037 ** granted herein. 00038 ** 00039 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00040 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00041 ** 00042 ****************************************************************************/ 00043 00044 #ifndef MSOCKETDEVICE_H 00045 #define MSOCKETDEVICE_H 00046 00047 #include <QIODevice> 00048 #include <QHostAddress> // int->QHostAddress conversion 00049 00050 #include "mythbaseexp.h" 00051 00052 class MSocketDevicePrivate; 00053 00054 class MBASE_PUBLIC MSocketDevice: public QIODevice 00055 { 00056 00057 public: 00058 enum Type { Stream, Datagram }; 00059 enum Protocol { IPv4, IPv6, Unknown }; 00060 00061 MSocketDevice(Type type = Stream); 00062 MSocketDevice(Type type, Protocol protocol, int dummy); 00063 MSocketDevice(int socket, Type type); 00064 virtual ~MSocketDevice(); 00065 00066 bool isValid() const; 00067 Type type() const; 00068 Protocol protocol() const; 00069 00070 void setProtocol(Protocol protocol); 00071 00072 int socket() const; 00073 virtual void setSocket(int socket, Type type); 00074 00075 bool open(OpenMode mode); 00076 bool open(int mode) 00077 { 00078 return open((OpenMode)mode); 00079 } 00080 00081 void close(); 00082 bool flush(); 00083 00084 // Implementation of QIODevice abstract virtual functions 00085 qint64 size() const; 00086 qint64 pos() const; 00087 bool seek(qint64); 00088 bool atEnd() const; 00089 00090 bool blocking() const; 00091 virtual void setBlocking(bool); 00092 00093 bool broadcast() const; 00094 virtual void setBroadcast(bool); 00095 00096 bool addressReusable() const; 00097 virtual void setAddressReusable(bool); 00098 00099 int receiveBufferSize() const; 00100 virtual void setReceiveBufferSize(uint); 00101 int sendBufferSize() const; 00102 virtual void setSendBufferSize(uint); 00103 00104 bool keepalive() const; 00105 virtual void setKeepalive(bool); 00106 00107 virtual bool connect(const QHostAddress &, quint16); 00108 00109 virtual bool bind(const QHostAddress &, quint16); 00110 virtual bool listen(int backlog); 00111 virtual int accept(); 00112 00113 qint64 bytesAvailable() const; 00114 qint64 waitForMore(int msecs, bool *timeout = 0) const; 00115 virtual qint64 writeBlock(const char *data, quint64 len, 00116 const QHostAddress & host, quint16 port); 00117 inline qint64 writeBlock(const char *data, quint64 len) 00118 { 00119 return qint64(write(data, qint64(len))); 00120 } 00121 00122 inline qint64 readBlock(char *data, quint64 maxlen) 00123 { 00124 return qint64(read(data, qint64(maxlen))); 00125 } 00126 00127 virtual quint16 port() const; 00128 virtual quint16 peerPort() const; 00129 virtual QHostAddress address() const; 00130 virtual QHostAddress peerAddress() const; 00131 00132 enum Error 00133 { 00134 NoError, 00135 AlreadyBound, 00136 Inaccessible, 00137 NoResources, 00138 InternalError, 00139 Bug = InternalError, // ### remove in 4.0? 00140 Impossible, 00141 NoFiles, 00142 ConnectionRefused, 00143 NetworkFailure, 00144 UnknownError 00145 }; 00146 Error error() const; 00147 00148 inline bool isSequential() const 00149 { 00150 return true; 00151 } 00152 00153 int createNewSocket(); 00154 00155 protected: 00156 void setError(Error err); 00157 qint64 readData(char *data, qint64 maxlen); 00158 qint64 writeData(const char *data, qint64 len); 00159 00160 private: 00161 int fd; 00162 Type t; 00163 quint16 p; 00164 QHostAddress a; 00165 quint16 pp; 00166 QHostAddress pa; 00167 MSocketDevice::Error e; 00168 MSocketDevicePrivate * d; 00169 00170 enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer, Keepalive }; 00171 00172 int option(Option) const; 00173 virtual void setOption(Option, int); 00174 00175 void fetchConnectionParameters(); 00176 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) 00177 void fetchPeerConnectionParameters(); 00178 #endif 00179 00180 static void init(); 00181 Protocol getProtocol() const; 00182 00183 private: // Disabled copy constructor and operator= 00184 #if defined(Q_DISABLE_COPY) 00185 MSocketDevice(const MSocketDevice &); 00186 MSocketDevice &operator=(const MSocketDevice &); 00187 #endif 00188 }; 00189 00190 #endif // MSOCKETDEVICE_H
1.7.6.1