KDECore
klocalsocket.h
Go to the documentation of this file.
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (C) 2007 Thiago Macieira <thiago@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KLOCALSOCKET_H 00022 #define KLOCALSOCKET_H 00023 00024 #include <kdecore_export.h> 00025 #include <QtCore/QString> 00026 #include <QtNetwork/QTcpSocket> 00027 #include <QtNetwork/QTcpServer> 00028 00029 class KLocalSocketPrivate; 00051 class KDECORE_EXPORT KLocalSocket : public QTcpSocket 00052 { 00053 Q_OBJECT 00054 public: 00059 enum LocalSocketType { 00060 UnixSocket, 00061 AbstractUnixSocket, 00062 UnknownLocalSocketType = -1 00063 }; 00064 00071 explicit KLocalSocket(QObject *parent = 0); 00076 virtual ~KLocalSocket(); 00077 00086 void connectToPath(const QString &path, OpenMode mode = ReadWrite); 00097 void connectToPath(const QString &path, LocalSocketType type, OpenMode mode = ReadWrite); 00101 void disconnectFromPath(); 00102 00108 LocalSocketType localSocketType() const; 00109 00116 QString localPath() const; 00122 QString peerPath() const; 00123 00124 private: 00125 using QAbstractSocket::connectToHost; 00126 using QAbstractSocket::disconnectFromHost; 00127 00128 protected Q_SLOTS: 00130 void connectToHostImplementation(const QString &hostName, quint16 port, OpenMode mode); 00131 void disconnectFromHostImplementation(); 00132 00133 private: 00134 Q_DISABLE_COPY(KLocalSocket) 00135 friend class KLocalSocketPrivate; 00136 KLocalSocketPrivate * const d; 00137 }; 00138 00139 class KLocalSocketServerPrivate; 00159 class KDECORE_EXPORT KLocalSocketServer : public QObject 00160 { 00161 Q_OBJECT 00162 public: 00170 explicit KLocalSocketServer(QObject *parent = 0); 00182 virtual ~KLocalSocketServer(); 00183 00207 bool listen(const QString &path, KLocalSocket::LocalSocketType type = KLocalSocket::UnixSocket); 00208 00217 void close(); 00218 00222 bool isListening() const; 00223 00235 void setMaxPendingConnections(int numConnections); 00239 int maxPendingConnections() const; 00240 00245 KLocalSocket::LocalSocketType localSocketType() const; 00250 QString localPath() const; 00251 00273 bool waitForNewConnection(int msec = 0, bool *timedOut = 0); 00274 00279 virtual bool hasPendingConnections() const; 00288 virtual KLocalSocket *nextPendingConnection(); 00289 00293 QAbstractSocket::SocketError serverError() const; 00297 QString errorString() const; 00298 00299 protected: 00301 virtual void incomingConnection(int handle); 00302 00303 Q_SIGNALS: 00310 void newConnection(); 00311 00312 private: 00313 Q_PRIVATE_SLOT(d, void _k_newConnectionActivity()) 00314 Q_DISABLE_COPY(KLocalSocketServer) 00315 friend class KLocalSocketServerPrivate; 00316 KLocalSocketServerPrivate * const d; 00317 }; 00318 00319 #endif
KDE 4.6 API Reference