~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to iris/src/xmpp/cutestuff/bsocket.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * bsocket.h - QSocket wrapper based on Bytestream with SRV DNS support
 
3
 * Copyright (C) 2003  Justin Karneges
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Lesser General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2.1 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Lesser General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU Lesser General Public
 
16
 * License along with this library; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 *
 
19
 */
 
20
 
 
21
#ifndef CS_BSOCKET_H
 
22
#define CS_BSOCKET_H
 
23
 
 
24
#include <QAbstractSocket>
 
25
 
 
26
#include "bytestream.h"
 
27
 
 
28
class QString;
 
29
class QObject;
 
30
class QByteArray;
 
31
 
 
32
// CS_NAMESPACE_BEGIN
 
33
 
 
34
class BSocket : public ByteStream
 
35
{
 
36
        Q_OBJECT
 
37
public:
 
38
        enum Error { ErrConnectionRefused = ErrCustom, ErrHostNotFound };
 
39
        enum State { Idle, HostLookup, Connecting, Connected, Closing };
 
40
        BSocket(QObject *parent=0);
 
41
        ~BSocket();
 
42
 
 
43
        void connectToHost(const QString &host, quint16 port);
 
44
        void connectToServer(const QString &srv, const QString &type);
 
45
        int socket() const;
 
46
        void setSocket(int);
 
47
        int state() const;
 
48
 
 
49
        // from ByteStream
 
50
        bool isOpen() const;
 
51
        void close();
 
52
        void write(const QByteArray &);
 
53
        QByteArray read(int bytes=0);
 
54
        int bytesAvailable() const;
 
55
        int bytesToWrite() const;
 
56
 
 
57
        // local
 
58
        QHostAddress address() const;
 
59
        quint16 port() const;
 
60
 
 
61
        // remote
 
62
        QHostAddress peerAddress() const;
 
63
        quint16 peerPort() const;
 
64
 
 
65
signals:
 
66
        void hostFound();
 
67
        void connected();
 
68
 
 
69
private slots:
 
70
        void qs_hostFound();
 
71
        void qs_connected();
 
72
        void qs_closed();
 
73
        void qs_readyRead();
 
74
        void qs_bytesWritten(qint64);
 
75
        void qs_error(QAbstractSocket::SocketError);
 
76
        void srv_done();
 
77
        void ndns_done();
 
78
        void do_connect();
 
79
 
 
80
private:
 
81
        class Private;
 
82
        Private *d;
 
83
 
 
84
        void reset(bool clear=false);
 
85
        void ensureSocket();
 
86
};
 
87
 
 
88
// CS_NAMESPACE_END
 
89
 
 
90
#endif