00001 #ifndef FAITH__SOCKET_H
00002 #define FAITH__SOCKET_H
00003
00004 #include <faith/object.h>
00005 #include <faith/net.h>
00006
00007 namespace Faith
00008 {
00009
00010 class SocketNotifier;
00011
00012 class FAITH_NET_EXPORT Socket : public Faith::Object
00013 {
00014 Q_OBJECT
00015 int mSocket;
00016
00017 struct SocketPrivate;
00018 SocketPrivate *d;
00019
00020 enum { Nothing, Trying, Connected, Closed, Error} state;
00021
00022 public:
00023
00024 enum SocketError
00025 {
00026 NoError,
00027 System,
00028 InvalidAddress,
00029 ConnectionRefused,
00030 Unreachable
00031 };
00032
00033 private:
00034 SocketError mError;
00035
00036 public:
00037
00043 Socket(const Faith::String &address, int port, Object *parent=0);
00044
00049 Socket(int fd, Object *parent=0);
00050
00051 Socket(Object *parent=0);
00052
00056 ~Socket();
00057
00061 SocketError error() const { return mError; }
00062
00066 void setPeer(const Faith::String &address, int port);
00067
00072 Faith::String peer() const;
00073
00089 int read(void *data, int count);
00090
00106 int write(const void *data, int count);
00107
00112 bool isClosed() const;
00113
00117 bool isConnected() const;
00118
00122 bool isConnectionFailed() const;
00123
00127 bool hasData() const;
00128
00129 public slots:
00138 void connect();
00139
00145 void close();
00146
00147 signals:
00148 void connected();
00149 void connectFailed();
00150
00151 void canRead();
00152 void canWrite();
00153
00158 void peerDisconnected();
00159
00160 private slots:
00161 void slotCanRead();
00162 void slotCanWrite();
00163
00164 private:
00165 void basicClose();
00166 };
00167
00168
00169 }
00170
00171 #endif