• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
  • network
kclientsocketbase.h
1/*
2 * Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
3 *
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef KCLIENTSOCKETBASE_H
26#define KCLIENTSOCKETBASE_H
27
28#include <tqobject.h>
29#include <tqstring.h>
30
31#include "tdesocketbase.h"
32#include "kresolver.h"
33#include <tdelibs_export.h>
34
35namespace KNetwork {
36
37class KClientSocketBasePrivate;
49class TDECORE_EXPORT KClientSocketBase : public TQObject, public KActiveSocketBase
50{
51 TQ_OBJECT
52
53
54public:
72 enum SocketState
73 {
74 Idle,
75 HostLookup,
76 HostFound,
77 Bound,
78 Connecting,
79 Open,
80 Closing,
81
82 Unconnected = Bound,
83 Connected = Open,
84 Connection = Open
85 };
86
87public:
94 KClientSocketBase(TQObject* parent, const char *name);
95
99 virtual ~KClientSocketBase();
100
105 SocketState state() const;
106
107protected:
111 virtual bool setSocketOptions(int opts);
112
113public:
122 KResolver& peerResolver() const;
123
127 const KResolverResults& peerResults() const;
128
137 KResolver& localResolver() const;
138
142 const KResolverResults& localResults() const;
143
158 void setResolutionEnabled(bool enable);
159
166 void setFamily(int families);
167
185 virtual bool lookup();
186
206 virtual bool bind(const TQString& node = TQString::null,
207 const TQString& service = TQString::null) = 0;
208
217 virtual bool bind(const KResolverEntry& address);
218
247 virtual bool connect(const TQString& node = TQString::null,
248 const TQString& service = TQString::null) = 0;
249
254 virtual bool connect(const KResolverEntry& address);
255
261 inline void connectToHost(const TQString& host, TQ_UINT16 port)
262 { connect(host, TQString::number(port)); }
263
268 virtual bool disconnect();
269
275 virtual inline bool open(int)
276 { return connect(); }
277
284 virtual void close();
285
289 virtual void flush()
290 { }
291
296 virtual TQ_LONG bytesAvailable() const;
297
301 virtual TQ_LONG waitForMore(int msecs, bool *timeout = 0L);
302
306 virtual TQ_LONG readBlock(char *data, TQ_ULONG maxlen);
307
312 virtual TQ_LONG readBlock(char *data, TQ_ULONG maxlen, TDESocketAddress& from);
313
317 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen);
318
323 virtual TQ_LONG peekBlock(char *data, TQ_ULONG maxlen, TDESocketAddress &from);
324
328 virtual TQ_LONG writeBlock(const char *data, TQ_ULONG len);
329
334 virtual TQ_LONG writeBlock(const char *data, TQ_ULONG len, const TDESocketAddress& to);
335
339 virtual TDESocketAddress localAddress() const;
340
344 virtual TDESocketAddress peerAddress() const;
345
349 bool emitsReadyRead() const;
350
357 virtual void enableRead(bool enable);
358
362 bool emitsReadyWrite() const;
363
370 virtual void enableWrite(bool enable);
371
372protected slots:
373 // protected slots
374
384 virtual void slotReadActivity();
385
395 virtual void slotWriteActivity();
396
397private slots:
398 void lookupFinishedSlot();
399
400signals:
409 void stateChanged(int newstate);
410
416 void gotError(int code);
417
421 void hostFound();
422
429 void bound(const KResolverEntry& local);
430
446 void aboutToConnect(const KResolverEntry& remote, bool& skip);
447
454 void connected(const KResolverEntry& remote);
455
460 void closed();
461
470 void readyRead();
471
483 void readyWrite();
484
485protected:
490 void setState(SocketState state);
491
501 virtual void stateChanging(SocketState newState);
502
507 void copyError();
508
509private:
510 KClientSocketBase(const KClientSocketBase&);
511 KClientSocketBase& operator=(const KClientSocketBase&);
512
513 KClientSocketBasePrivate *d;
514};
515
516} // namespace KNetwork
517
518#endif
KNetwork::KActiveSocketBase
Abstract class for active sockets.
Definition: tdesocketbase.h:444
KNetwork::KClientSocketBase
Abstract client socket class.
Definition: kclientsocketbase.h:50
KNetwork::KClientSocketBase::connected
void connected(const KResolverEntry &remote)
This socket is emitted when the socket successfully connects to a remote address.
KNetwork::KClientSocketBase::flush
virtual void flush()
This call is not supported on sockets.
Definition: kclientsocketbase.h:289
KNetwork::KClientSocketBase::SocketState
SocketState
Socket states.
Definition: kclientsocketbase.h:73
KNetwork::KClientSocketBase::open
virtual bool open(int)
Opens the socket.
Definition: kclientsocketbase.h:275
KNetwork::KClientSocketBase::readyRead
void readyRead()
This signal is emitted whenever the socket is ready for reading – i.e., there is data to be read in t...
KNetwork::KClientSocketBase::closed
void closed()
This signal is emitted when the socket completes the closing/shut down process.
KNetwork::KClientSocketBase::bound
void bound(const KResolverEntry &local)
This signal is emitted when the socket successfully binds to an address.
KNetwork::KClientSocketBase::readyWrite
void readyWrite()
This signal is emitted whenever the socket is ready for writing – i.e., whenever there's space availa...
KNetwork::KClientSocketBase::bind
virtual bool bind(const TQString &node=TQString::null, const TQString &service=TQString::null)=0
Binds this socket to the given nodename and service, or use the default ones if none are given.
KNetwork::KClientSocketBase::connect
virtual bool connect(const TQString &node=TQString::null, const TQString &service=TQString::null)=0
Attempts to connect to the these hostname and service, or use the default ones if none are given.
KNetwork::KClientSocketBase::gotError
void gotError(int code)
This signal is emitted when this object finds an error.
KNetwork::KClientSocketBase::aboutToConnect
void aboutToConnect(const KResolverEntry &remote, bool &skip)
This signal is emitted when the socket is about to connect to an address (but before doing so).
KNetwork::KClientSocketBase::hostFound
void hostFound()
This signal is emitted when the lookup is successfully completed.
KNetwork::KClientSocketBase::connectToHost
void connectToHost(const TQString &host, TQ_UINT16 port)
Definition: kclientsocketbase.h:261
KNetwork::KClientSocketBase::stateChanged
void stateChanged(int newstate)
This signal is emitted whenever the socket state changes.
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:67
KNetwork::KResolverResults
Name and service resolution results.
Definition: kresolver.h:198
KNetwork::KResolver
Name and service resolution class.
Definition: kresolver.h:296
KNetwork::TDESocketAddress
A generic socket address.
Definition: tdesocketaddress.h:424
KNetwork
A namespace to store all networking-related (socket) classes.
Definition: kbufferedsocket.h:36

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.