kserversocket.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 KSERVERSOCKET_H 00026 #define KSERVERSOCKET_H 00027 00028 #include <tqobject.h> 00029 #include "tdesocketbase.h" 00030 00031 namespace KNetwork { 00032 00033 class TDESocketDevice; 00034 class KStreamSocket; 00035 class KResolver; 00036 class KResolverResults; 00037 00038 class TDEServerSocketPrivate; 00107 class TDECORE_EXPORT TDEServerSocket: public TQObject, public KPassiveSocketBase 00108 { 00109 Q_OBJECT 00110 00111 public: 00122 TDEServerSocket(TQObject* parent = 0L, const char *name = 0L); 00123 00141 TDEServerSocket(const TQString& service, TQObject* parent = 0L, const char *name = 0L); 00142 00161 TDEServerSocket(const TQString& node, const TQString& service, 00162 TQObject* parent = 0L, const char *name = 0L); 00163 00170 ~TDEServerSocket(); 00171 00172 protected: 00176 virtual bool setSocketOptions(int opts); 00177 00178 public: 00187 KResolver& resolver() const; 00188 00192 const KResolverResults& resolverResults() const; 00193 00208 void setResolutionEnabled(bool enable); 00209 00216 void setFamily(int families); 00217 00231 void setAddress(const TQString& service); 00232 00248 void setAddress(const TQString& node, const TQString& service); 00249 00257 void setTimeout(int msecs); 00258 00276 virtual bool lookup(); 00277 00291 virtual bool bind(const TQString& node, const TQString& service); 00292 00299 virtual bool bind(const TQString& service); 00300 00306 virtual bool bind(); 00307 00315 virtual bool bind(const KResolverEntry& address); 00316 00330 virtual bool listen(int backlog = 5); // 5 is arbitrary 00331 00335 virtual void close(); 00336 00348 void setAcceptBuffered(bool enable); 00349 00367 virtual KActiveSocketBase* accept(); 00368 00372 virtual TDESocketAddress localAddress() const; 00373 00377 virtual TDESocketAddress externalAddress() const; 00378 00379 private slots: 00380 void lookupFinishedSlot(); 00381 00382 signals: 00388 void gotError(int code); 00389 00393 void hostFound(); 00394 00401 void bound(const KResolverEntry& local); 00402 00407 void closed(); 00408 00414 void readyAccept(); 00415 00416 protected: 00421 void copyError(); 00422 00423 private: 00424 bool doBind(); 00425 bool doListen(); 00426 00427 private: 00428 TDEServerSocket(const TDEServerSocket&); 00429 TDEServerSocket& operator=(const TDEServerSocket&); 00430 00431 TDEServerSocketPrivate *d; 00432 }; 00433 00434 } // namespace KNetwork 00435 00436 #endif