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

tdecore

  • KNetwork
  • KStreamSocket
Signals | Public Member Functions | Friends | List of all members
KNetwork::KStreamSocket Class Reference

#include <kstreamsocket.h>

Inheritance diagram for KNetwork::KStreamSocket:
KNetwork::KClientSocketBase KNetwork::KActiveSocketBase KNetwork::TDESocketBase KNetwork::TDEBufferedSocket

Signals

void timedOut ()
 
- Signals inherited from KNetwork::KClientSocketBase
void stateChanged (int newstate)
 
void gotError (int code)
 
void hostFound ()
 
void bound (const KResolverEntry &local)
 
void aboutToConnect (const KResolverEntry &remote, bool &skip)
 
void connected (const KResolverEntry &remote)
 
void closed ()
 
void readyRead ()
 
void readyWrite ()
 

Public Member Functions

 KStreamSocket (const TQString &node=TQString::null, const TQString &service=TQString::null, TQObject *parent=0L, const char *name=0L)
 
virtual ~KStreamSocket ()
 
int timeout () const
 
int remainingTimeout () const
 
void setTimeout (int msecs)
 
virtual bool bind (const TQString &node=TQString::null, const TQString &service=TQString::null)
 
virtual bool bind (const KResolverEntry &entry)
 
virtual bool connect (const TQString &node=TQString::null, const TQString &service=TQString::null)
 
virtual bool connect (const KResolverEntry &entry)
 
- Public Member Functions inherited from KNetwork::KClientSocketBase
 KClientSocketBase (TQObject *parent, const char *name)
 
virtual ~KClientSocketBase ()
 
SocketState state () const
 
KResolver & peerResolver () const
 
const KResolverResults & peerResults () const
 
KResolver & localResolver () const
 
const KResolverResults & localResults () const
 
void setResolutionEnabled (bool enable)
 
void setFamily (int families)
 
virtual bool lookup ()
 
virtual bool bind (const TQString &node=TQString::null, const TQString &service=TQString::null)=0
 
virtual bool bind (const KResolverEntry &address)
 
virtual bool connect (const TQString &node=TQString::null, const TQString &service=TQString::null)=0
 
virtual bool connect (const KResolverEntry &address)
 
void connectToHost (const TQString &host, TQ_UINT16 port)
 
virtual bool disconnect ()
 
virtual bool open (int)
 
virtual void close ()
 
virtual void flush ()
 
virtual TQ_LONG bytesAvailable () const
 
virtual TQ_LONG waitForMore (int msecs, bool *timeout=0L)
 
virtual TQ_LONG readBlock (char *data, TQ_ULONG maxlen)
 
virtual TQ_LONG readBlock (char *data, TQ_ULONG maxlen, TDESocketAddress &from)
 
virtual TQ_LONG peekBlock (char *data, TQ_ULONG maxlen)
 
virtual TQ_LONG peekBlock (char *data, TQ_ULONG maxlen, TDESocketAddress &from)
 
virtual TQ_LONG writeBlock (const char *data, TQ_ULONG len)
 
virtual TQ_LONG writeBlock (const char *data, TQ_ULONG len, const TDESocketAddress &to)
 
virtual TDESocketAddress localAddress () const
 
virtual TDESocketAddress peerAddress () const
 
bool emitsReadyRead () const
 
virtual void enableRead (bool enable)
 
bool emitsReadyWrite () const
 
virtual void enableWrite (bool enable)
 
- Public Member Functions inherited from KNetwork::KActiveSocketBase
 KActiveSocketBase ()
 
virtual ~KActiveSocketBase ()
 
virtual bool bind (const KResolverEntry &address)=0
 
virtual bool connect (const KResolverEntry &address)=0
 
virtual bool disconnect ()=0
 
virtual Offset size () const
 
virtual Offset at () const
 
virtual bool at (Offset)
 
virtual bool atEnd () const
 
virtual TQ_LONG bytesAvailable () const =0
 
virtual TQ_LONG waitForMore (int msecs, bool *timeout=0L)=0
 
virtual TQ_LONG readBlock (char *data, TQ_ULONG len)=0
 
virtual TQ_LONG readBlock (char *data, TQ_ULONG maxlen, TDESocketAddress &from)=0
 
virtual TQ_LONG peekBlock (char *data, TQ_ULONG maxlen)=0
 
virtual TQ_LONG peekBlock (char *data, TQ_ULONG maxlen, TDESocketAddress &from)=0
 
virtual TQ_LONG writeBlock (const char *data, TQ_ULONG len)=0
 
virtual TQ_LONG writeBlock (const char *data, TQ_ULONG len, const TDESocketAddress &to)=0
 
virtual int getch ()
 
virtual int putch (int ch)
 
virtual int ungetch (int)
 
virtual TDESocketAddress localAddress () const =0
 
virtual TDESocketAddress peerAddress () const =0
 
- Public Member Functions inherited from KNetwork::TDESocketBase
 TDESocketBase ()
 
virtual ~TDESocketBase ()
 
virtual bool setBlocking (bool enable)
 
bool blocking () const
 
virtual bool setAddressReuseable (bool enable)
 
bool addressReuseable () const
 
virtual bool setIPv6Only (bool enable)
 
bool isIPv6Only () const
 
virtual bool setBroadcast (bool enable)
 
bool broadcast () const
 
TDESocketDevice * socketDevice () const
 
virtual void setSocketDevice (TDESocketDevice *device)
 
int setRequestedCapabilities (int add, int remove=0)
 
SocketError error () const
 
TQString errorString () const
 
TQMutex * mutex () const
 

Friends

class TDEServerSocket
 
class TDEBufferedSocket
 

Additional Inherited Members

- Public Types inherited from KNetwork::KClientSocketBase
enum  SocketState {
  Idle , HostLookup , HostFound , Bound ,
  Connecting , Open , Closing , Unconnected = Bound ,
  Connected = Open , Connection = Open
}
 
- Public Types inherited from KNetwork::TDESocketBase
enum  SocketOptions {
  Blocking = 0x01 , AddressReuseable = 0x02 , IPv6Only = 0x04 , Keepalive = 0x08 ,
  Broadcast = 0x10
}
 
enum  SocketError {
  NoError = 0 , LookupFailure , AddressInUse , AlreadyCreated ,
  AlreadyBound , AlreadyConnected , NotConnected , NotBound ,
  NotCreated , WouldBlock , ConnectionRefused , ConnectionTimedOut ,
  InProgress , NetFailure , NotSupported , Timeout ,
  UnknownError , RemotelyDisconnected
}
 
- Static Public Member Functions inherited from KNetwork::TDESocketBase
static TQString errorString (SocketError code)
 
static bool isFatalError (int code)
 
- Protected Slots inherited from KNetwork::KClientSocketBase
virtual void slotReadActivity ()
 
virtual void slotWriteActivity ()
 
- Protected Member Functions inherited from KNetwork::KClientSocketBase
virtual bool setSocketOptions (int opts)
 
void setState (SocketState state)
 
virtual void stateChanging (SocketState newState)
 
void copyError ()
 
- Protected Member Functions inherited from KNetwork::KActiveSocketBase
void setError (int status, SocketError error)
 
void resetError ()
 
- Protected Member Functions inherited from KNetwork::TDESocketBase
virtual bool setSocketOptions (int opts)
 
virtual int socketOptions () const
 
bool hasDevice () const
 
void setError (SocketError error)
 

Detailed Description

Simple stream socket.

This class provides functionality to creating unbuffered, stream sockets. In the case of Internet (IP) sockets, this class creates and uses TCP/IP sockets.

Objects of this class start, by default, on non-blocking mode. Call setBlocking if you wish to change that.

KStreamSocket objects are thread-safe and can be used in auxiliary threads (i.e., not the thread in which the Qt event loop runs in). Note that TDEBufferedSocket cannot be used reliably in an auxiliary thread.

Sample usage:

TQByteArray httpGet(const TQString& hostname)
{
KStreamSocket socket(hostname, "http");
if (!socket.connect())
return TQByteArray();
TQByteArray data = socket.readAll();
return data;
}
KNetwork::KStreamSocket
Simple stream socket.
Definition: kstreamsocket.h:98

Here's another sample, showing asynchronous operation:

DataRetriever::DataRetriever(const TQString& hostname, const TQString& port)
: socket(hostname, port)
{
// connect signals to our slots
TQObject::connect(&socket, TQ_SIGNAL(connected(const KResolverEntry&)),
this, TQ_SLOT(slotSocketConnected()));
TQObject::connect(&socket, TQ_SIGNAL(gotError(int)),
this, TQ_SLOT(slotSocketError(int)));
TQObject::connect(&socket, TQ_SIGNAL(readyRead()),
this, TQ_SLOT(slotSocketReadyToRead()));
TQObject::connect(&socket, TQ_SIGNAL(readyWrite()),
this, TQ_SLOT(slotSocketReadyToWrite()));
// set non-blocking mode in order to work asynchronously
socket.setBlocking(false);
// turn on signal emission
socket.enableRead(true);
socket.enableWrite(true);
// start connecting
socket.connect();
}
KNetwork::KResolverEntry
One resolution entry.
Definition: kresolver.h:67
See also
KNetwork::TDEBufferedSocket, KNetwork::TDEServerSocket
Author
Thiago Macieira thiag.nosp@m.o@kd.nosp@m.e.org

Definition at line 97 of file kstreamsocket.h.

Constructor & Destructor Documentation

◆ KStreamSocket()

KStreamSocket::KStreamSocket ( const TQString &  node = TQString::null,
const TQString &  service = TQString::null,
TQObject *  parent = 0L,
const char *  name = 0L 
)

Default constructor.

Parameters
nodedestination host
servicedestination service to connect to
parentthe parent TQObject object
namename for this object

Definition at line 53 of file kstreamsocket.cpp.

◆ ~KStreamSocket()

KStreamSocket::~KStreamSocket ( )
virtual

Destructor.

This closes the socket.

Definition at line 67 of file kstreamsocket.cpp.

Member Function Documentation

◆ bind() [1/2]

virtual bool KNetwork::KStreamSocket::bind ( const KResolverEntry &  entry)
inlinevirtual

Reimplemented from KClientSocketBase.

Connect this socket to this specific address.

Unlike bind(const TQString&, const TQString&) above, this function really does bind the socket. No lookup is performed. The bound signal will be emitted.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 176 of file kstreamsocket.h.

◆ bind() [2/2]

bool KStreamSocket::bind ( const TQString &  node = TQString::null,
const TQString &  service = TQString::null 
)
virtual

Binds this socket to the given nodename and service, or use the default ones if none are given.

In order to bind to a service and allow the operating system to choose the interface, set node to TQString::null.

Reimplemented from KClientSocketBase.

Upon successful binding, the bound signal will be emitted. If an error is found, the gotError signal will be emitted.

Note
Due to the internals of the name lookup and binding mechanism, some (if not most) implementations of this function do not actually bind the socket until the connection is requested (see connect). They only set the values for future reference.

This function returns true on success.

Parameters
nodethe nodename
servicethe service

Implements KNetwork::KClientSocketBase.

Definition at line 96 of file kstreamsocket.cpp.

◆ connect() [1/2]

bool KStreamSocket::connect ( const KResolverEntry &  entry)
virtual

Unshadowing from KClientSocketBase.

Reimplemented from KNetwork::KClientSocketBase.

Definition at line 192 of file kstreamsocket.cpp.

◆ connect() [2/2]

bool KStreamSocket::connect ( const TQString &  node = TQString::null,
const TQString &  service = TQString::null 
)
virtual

Reimplemented from KClientSocketBase.

Attempts to connect to the these hostname and service, or use the default ones if none are given. If a connection attempt is already in progress, check on its state and set the error status (NoError, meaning the connection is completed, or InProgress).

If the blocking mode for this object is on, this function will only return when all the resolved peer addresses have been tried or when a connection is established.

Upon successfully connecting, the connected signal will be emitted. If an error is found, the gotError signal will be emitted.

This function also implements timeout handling.

Parameters
nodethe remote node to connect to
servicethe service on the remote node to connect to

Implements KNetwork::KClientSocketBase.

Definition at line 108 of file kstreamsocket.cpp.

◆ remainingTimeout()

int KStreamSocket::remainingTimeout ( ) const

Retrieves the remaining timeout time (in milliseconds).

This value equals timeout() if there's no connection in progress.

Definition at line 78 of file kstreamsocket.cpp.

◆ setTimeout()

void KStreamSocket::setTimeout ( int  msecs)

Sets the timeout value.

Setting this value while a connection attempt is in progress will reset the timer.

Please note that the timeout value is valid for the connection attempt only. No other operations are timed against this value – including the name lookup associated.

Parameters
msecsthe timeout value in milliseconds

Definition at line 88 of file kstreamsocket.cpp.

◆ timedOut

void KNetwork::KStreamSocket::timedOut ( )
signal

This signal is emitted when a connection timeout occurs.

◆ timeout()

int KStreamSocket::timeout ( ) const

Retrieves the timeout value (in milliseconds).

Definition at line 73 of file kstreamsocket.cpp.

Friends And Related Function Documentation

◆ TDEBufferedSocket

friend class TDEBufferedSocket
friend

Definition at line 245 of file kstreamsocket.h.

◆ TDEServerSocket

friend class TDEServerSocket
friend

Definition at line 244 of file kstreamsocket.h.


The documentation for this class was generated from the following files:
  • kstreamsocket.h
  • kstreamsocket.cpp

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.