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 <tqobject.h> 00029 #include <tqcstring.h> 00030 #include <tqvaluelist.h> 00031 #include "kstreamsocket.h" 00032 #include <tdelibs_export.h> 00033 00034 class TDEIOBufferBase; 00035 00036 namespace KNetwork { 00037 00038 class TDEBufferedSocketPrivate; 00058 class TDECORE_EXPORT TDEBufferedSocket: public KStreamSocket 00059 { 00060 Q_OBJECT 00061 00062 public: 00071 TDEBufferedSocket(const TQString& node = TQString::null, const TQString& service = TQString::null, 00072 TQObject* parent = 0L, const char *name = 0L); 00073 00077 virtual ~TDEBufferedSocket(); 00078 00082 virtual void setSocketDevice(TDESocketDevice* device); 00083 00084 protected: 00088 virtual bool setSocketOptions(int opts); 00089 00090 public: 00097 virtual void close(); 00098 00102 #ifdef USE_QT3 00103 virtual TQ_LONG bytesAvailable() const; 00104 #endif 00105 #ifdef USE_QT4 00106 virtual qint64 bytesAvailable() const; 00107 #endif 00108 00112 virtual TQ_LONG waitForMore(int msecs, bool *timeout = 0L); 00113 00117 virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen); 00118 00125 virtual TQT_TQIO_LONG tqreadBlock(char *data, TQT_TQIO_ULONG maxlen, TDESocketAddress& from); 00126 00130 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen); 00131 00138 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen, TDESocketAddress &from); 00139 00143 virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len); 00144 00151 virtual TQT_TQIO_LONG tqwriteBlock(const char *data, TQT_TQIO_ULONG len, const TDESocketAddress& to); 00152 00156 virtual void enableRead(bool enable); 00157 00161 virtual void enableWrite(bool enable); 00162 00166 void setInputBuffering(bool enable); 00167 00171 TDEIOBufferBase* inputBuffer(); 00172 00176 void setOutputBuffering(bool enable); 00177 00181 TDEIOBufferBase* outputBuffer(); 00182 00186 #ifdef USE_QT3 00187 virtual TQ_ULONG bytesToWrite() const; 00188 #endif 00189 #ifdef USE_QT4 00190 virtual qint64 bytesToWrite() const; 00191 #endif 00192 00199 virtual void closeNow(); 00200 00204 bool canReadLine() const; 00205 00209 TQCString readLine(); 00210 00211 // KDE4: make virtual, add timeout to match the Qt4 signature 00212 // and move to another class up the hierarchy 00217 void waitForConnect(); 00218 00219 protected: 00223 virtual void stateChanging(SocketState newState); 00224 00225 protected slots: 00229 virtual void slotReadActivity(); 00230 00234 virtual void slotWriteActivity(); 00235 00236 signals: 00240 void bytesWritten(int bytes); 00241 00242 private: 00243 TDEBufferedSocket(const TDEBufferedSocket&); 00244 TDEBufferedSocket& operator=(const TDEBufferedSocket&); 00245 00246 TDEBufferedSocketPrivate *d; 00247 00248 public: 00249 // KDE4: remove this function 00258 #ifdef USE_QT3 00259 inline void reset() 00260 #endif 00261 #ifdef USE_QT4 00262 inline bool reset() 00263 #endif 00264 { closeNow(); } 00265 }; 00266 00267 } // namespace KNetwork 00268 00269 #endif