MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
msocketdevice.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the Qt3Support module of the Qt Toolkit.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License versions 2.0 or 3.0 as published by the Free Software
9 ** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
10 ** included in the packaging of this file. Alternatively you may (at
11 ** your option) use any later version of the GNU General Public
12 ** License if such license has been publicly approved by Trolltech ASA
13 ** (or its successors, if any) and the KDE Free Qt Foundation. In
14 ** addition, as a special exception, Trolltech gives you certain
15 ** additional rights. These rights are described in the Trolltech GPL
16 ** Exception version 1.2, which can be found at
17 ** http://www.trolltech.com/products/qt/gplexception/ and in the file
18 ** GPL_EXCEPTION.txt in this package.
19 **
20 ** Please review the following information to ensure GNU General
21 ** Public Licensing requirements will be met:
22 ** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
23 ** you are unsure which license is appropriate for your use, please
24 ** review the following information:
25 ** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
26 ** or contact the sales department at sales@trolltech.com.
27 **
28 ** In addition, as a special exception, Trolltech, as the sole
29 ** copyright holder for Qt Designer, grants users of the Qt/Eclipse
30 ** Integration plug-in the right for the Qt/Eclipse Integration to
31 ** link to functionality provided by Qt Designer and its related
32 ** libraries.
33 **
34 ** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
35 ** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
36 ** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
37 ** granted herein.
38 **
39 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
40 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
41 **
42 ****************************************************************************/
43 
44 #ifndef MSOCKETDEVICE_H
45 #define MSOCKETDEVICE_H
46 
47 #include <QIODevice>
48 #include <QHostAddress> // int->QHostAddress conversion
49 
50 #include "upnpexp.h"
51 
53 
54 class UPNP_PUBLIC MSocketDevice: public QIODevice
55 {
56 
57 public:
58  enum Type { Stream, Datagram };
59  enum Protocol { IPv4, IPv6, Unknown };
60 
61  MSocketDevice(Type type = Stream);
62  MSocketDevice(Type type, Protocol protocol, int dummy);
63  MSocketDevice(int socket, Type type);
64  virtual ~MSocketDevice();
65 
66  bool isValid() const;
67  Type type() const;
68  Protocol protocol() const;
69 
70  void setProtocol(Protocol protocol);
71 
72  int socket() const;
73  virtual void setSocket(int socket, Type type);
74 
75  bool open(OpenMode mode);
76  bool open(int mode)
77  {
78  return open((OpenMode)mode);
79  }
80 
81  void close();
82  bool flush();
83 
84  // Implementation of QIODevice abstract virtual functions
85  qint64 size() const;
86  qint64 pos() const;
87  bool seek(qint64);
88  bool atEnd() const;
89 
90  bool blocking() const;
91  virtual void setBlocking(bool);
92 
93  bool broadcast() const;
94  virtual void setBroadcast(bool);
95 
96  bool addressReusable() const;
97  virtual void setAddressReusable(bool);
98 
99  int receiveBufferSize() const;
100  virtual void setReceiveBufferSize(uint);
101  int sendBufferSize() const;
102  virtual void setSendBufferSize(uint);
103 
104  bool keepalive() const;
105  virtual void setKeepalive(bool);
106 
107  virtual bool connect(const QHostAddress &, quint16);
108 
109  virtual bool bind(const QHostAddress &, quint16);
110  virtual bool listen(int backlog);
111  virtual int accept();
112 
113  qint64 bytesAvailable() const;
114  qint64 waitForMore(int msecs, bool *timeout = 0) const;
115  virtual qint64 writeBlock(const char *data, quint64 len,
116  const QHostAddress & host, quint16 port);
117  inline qint64 writeBlock(const char *data, quint64 len)
118  {
119  return qint64(write(data, qint64(len)));
120  }
121 
122  inline qint64 readBlock(char *data, quint64 maxlen)
123  {
124  return qint64(read(data, qint64(maxlen)));
125  }
126 
127  virtual quint16 port() const;
128  virtual quint16 peerPort() const;
129  virtual QHostAddress address() const;
130  virtual QHostAddress peerAddress() const;
131 
132  enum Error
133  {
139  Bug = InternalError, // ### remove in 4.0?
144  UnknownError
145  };
146  Error error() const;
147 
148  inline bool isSequential() const
149  {
150  return true;
151  }
152 
153  int createNewSocket();
154 
155 protected:
156  void setError(Error err);
157  qint64 readData(char *data, qint64 maxlen);
158  qint64 writeData(const char *data, qint64 len);
159 
160 private:
161  int fd;
163  quint16 p;
164  QHostAddress a;
165  quint16 pp;
166  QHostAddress pa;
169 
170  enum Option { Broadcast, ReceiveBuffer, ReuseAddress, SendBuffer, Keepalive };
171 
172  int option(Option) const;
173  virtual void setOption(Option, int);
174 
175  void fetchConnectionParameters();
176 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
177  void fetchPeerConnectionParameters();
178 #endif
179 
180  static void init();
181  Protocol getProtocol() const;
182 
183 private: // Disabled copy constructor and operator=
184 #if defined(Q_DISABLE_COPY)
185  MSocketDevice(const MSocketDevice &);
186  MSocketDevice &operator=(const MSocketDevice &);
187 #endif
188 };
189 
190 #endif // MSOCKETDEVICE_H
MYTH_GLsizeiptr const GLvoid * data
open(CONF, $file) or die("\nERROR
qint64 writeBlock(const char *data, quint64 len)
MSocketDevicePrivate * d
int dummy
Definition: programinfo.cpp:46
QHostAddress pa
GLenum GLsizei len
unsigned int uint
Definition: compat.h:135
GLint GLenum GLsizei GLint GLenum GLenum type
bool open(int mode)
Definition: msocketdevice.h:76
qint64 readBlock(char *data, quint64 maxlen)
The MSocketDevice class provides a platform-independent low-level socket API.
Definition: msocketdevice.h:54
MSocketDevice::Error e
static void init(VideoFrame *vf, VideoFrameType _codec, unsigned char *_buf, int _width, int _height, int _size, const int *p=0, const int *o=0, float _aspect=-1.0f, double _rate=-1.0f) MUNUSED
Definition: frame.h:78
then echo error
Definition: unittests.sh:42
bool isSequential() const
def write
Definition: mythburn.py:279
const char int mode
Definition: ioapi.h:135
lzo_uint lzo_uint size
Definition: lzoconf.h:273
close(CACHE)
QHostAddress a