File indexing completed on 2024-06-23 04:03:31
0001 /* 0002 * bsocket.h - QSocket wrapper based on Bytestream with SRV DNS support 0003 * Copyright (C) 2003 Justin Karneges 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * either version 2 0009 of the License, or (at your option) any later version.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0019 * 0020 */ 0021 0022 #ifndef CS_BSOCKET_H 0023 #define CS_BSOCKET_H 0024 0025 #include <QAbstractSocket> 0026 0027 #include "iris_export.h" 0028 #include "bytestream.h" 0029 0030 class QString; 0031 class QObject; 0032 class QByteArray; 0033 0034 // CS_NAMESPACE_BEGIN 0035 0036 class IRIS_EXPORT BSocket : public ByteStream 0037 { 0038 Q_OBJECT 0039 public: 0040 enum Error { ErrConnectionRefused = ErrCustom, ErrHostNotFound }; 0041 enum State { Idle, HostLookup, Connecting, Connected, Closing }; 0042 BSocket(QObject *parent=0); 0043 ~BSocket() override; 0044 0045 void connectToHost(const QString &host, quint16 port); 0046 void connectToServer(const QString &srv, const QString &type); 0047 int socket() const; 0048 void setSocket(int); 0049 int state() const; 0050 0051 // from ByteStream 0052 bool isOpen() const override; 0053 void close() override; 0054 void write(const QByteArray &) override; 0055 QByteArray read(int bytes=0) override; 0056 int bytesAvailable() const override; 0057 int bytesToWrite() const override; 0058 0059 // local 0060 QHostAddress address() const; 0061 quint16 port() const; 0062 0063 // remote 0064 QHostAddress peerAddress() const; 0065 quint16 peerPort() const; 0066 0067 signals: 0068 void hostFound(); 0069 void connected(); 0070 0071 private slots: 0072 void qs_hostFound(); 0073 void qs_connected(); 0074 void qs_closed(); 0075 void qs_readyRead(); 0076 void qs_bytesWritten(qint64); 0077 void qs_error(QAbstractSocket::SocketError); 0078 void srv_done(); 0079 void ndns_done(); 0080 void do_connect(); 0081 0082 private: 0083 class Private; 0084 Private *d; 0085 0086 void reset(bool clear=false); 0087 void ensureSocket(); 0088 }; 0089 0090 // CS_NAMESPACE_END 0091 0092 #endif