kbufferedsocket.h
00001 /* -*- C++ -*- 00002 * Copyright (C) 2003 Thiago Macieira <thiago@kde.org> 00003 * 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining 00006 * a copy of this software and associated documentation files (the 00007 * "Software"), to deal in the Software without restriction, including 00008 * without limitation the rights to use, copy, modify, merge, publish, 00009 * distribute, sublicense, and/or sell copies of the Software, and to 00010 * permit persons to whom the Software is furnished to do so, subject to 00011 * the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00021 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 #ifndef KBUFFEREDSOCKET_H 00026 #define KBUFFEREDSOCKET_H 00027 00028 #include <qobject.h> 00029 #include <qcstring.h> 00030 #include <qvaluelist.h> 00031 #include "kstreamsocket.h" 00032 #include <kdelibs_export.h> 00033 00034 class KIOBufferBase; 00035 00036 namespace KNetwork { 00037 00038 class KBufferedSocketPrivate; 00058 class KDECORE_EXPORT KBufferedSocket: public KStreamSocket 00059 { 00060 Q_OBJECT 00061 public: 00070 KBufferedSocket(const QString& node = QString::null, const QString& service = QString::null, 00071 QObject* parent = 0L, const char *name = 0L); 00072 00076 virtual ~KBufferedSocket(); 00077 00081 virtual void setSocketDevice(KSocketDevice* device); 00082 00083 protected: 00087 virtual bool setSocketOptions(int opts); 00088 00089 public: 00096 virtual void close(); 00097 00101 virtual Q_LONG bytesAvailable() const; 00102 00106 virtual Q_LONG waitForMore(int msecs, bool *timeout = 0L); 00107 00111 virtual Q_LONG readBlock(char *data, Q_ULONG maxlen); 00112 00119 virtual Q_LONG readBlock(char *data, Q_ULONG maxlen, KSocketAddress& from); 00120 00124 virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen); 00125 00132 virtual Q_LONG peekBlock(char *data, Q_ULONG maxlen, KSocketAddress &from); 00133 00137 virtual Q_LONG writeBlock(const char *data, Q_ULONG len); 00138 00145 virtual Q_LONG writeBlock(const char *data, Q_ULONG len, const KSocketAddress& to); 00146 00150 virtual void enableRead(bool enable); 00151 00155 virtual void enableWrite(bool enable); 00156 00160 void setInputBuffering(bool enable); 00161 00165 KIOBufferBase* inputBuffer(); 00166 00170 void setOutputBuffering(bool enable); 00171 00175 KIOBufferBase* outputBuffer(); 00176 00180 virtual Q_ULONG bytesToWrite() const; 00181 00188 virtual void closeNow(); 00189 00193 bool canReadLine() const; 00194 00198 QCString readLine(); 00199 00200 // KDE4: make virtual, add timeout to match the Qt4 signature 00201 // and move to another class up the hierarchy 00206 void waitForConnect(); 00207 00208 protected: 00212 virtual void stateChanging(SocketState newState); 00213 00214 protected slots: 00218 virtual void slotReadActivity(); 00219 00223 virtual void slotWriteActivity(); 00224 00225 signals: 00229 void bytesWritten(int bytes); 00230 00231 private: 00232 KBufferedSocket(const KBufferedSocket&); 00233 KBufferedSocket& operator=(const KBufferedSocket&); 00234 00235 KBufferedSocketPrivate *d; 00236 00237 public: 00238 // KDE4: remove this function 00247 inline void reset() 00248 { closeNow(); } 00249 }; 00250 00251 } // namespace KNetwork 00252 00253 #endif