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

tdecore

  • KNetwork
  • TDESocketDevice
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
KNetwork::TDESocketDevice Class Reference

#include <tdesocketdevice.h>

Inheritance diagram for KNetwork::TDESocketDevice:
KNetwork::KActiveSocketBase KNetwork::KPassiveSocketBase KNetwork::TDESocketBase KNetwork::TDESocketBase KNetwork::KHttpProxySocketDevice KNetwork::KMulticastSocketImpl KNetwork::KSocksSocketDevice

Public Types

enum  Capabilities {
  CanConnectString = 0x01 , CanBindString = 0x02 , CanNotBind = 0x04 , CanNotListen = 0x08 ,
  CanMulticast = 0x10 , CanNotUseDatagrams = 0x20
}
 
- 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
}
 

Public Member Functions

 TDESocketDevice (const TDESocketBase *=0L)
 
 TDESocketDevice (int fd)
 
virtual ~TDESocketDevice ()
 
int socket () const
 
virtual int capabilities () const
 
virtual bool setSocketOptions (int opts)
 
virtual bool open (int mode)
 
virtual void close ()
 
virtual void flush ()
 
virtual bool create (int family, int type, int protocol)
 
bool create (const KResolverEntry &address)
 
virtual bool bind (const KResolverEntry &address)
 
virtual bool listen (int backlog=5)
 
virtual bool connect (const KResolverEntry &address)
 
virtual TDESocketDevice * accept ()
 
virtual bool disconnect ()
 
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
 
virtual TDESocketAddress externalAddress () const
 
TQSocketNotifier * readNotifier () const
 
TQSocketNotifier * writeNotifier () const
 
TQSocketNotifier * exceptionNotifier () const
 
virtual bool poll (bool *input, bool *output, bool *exception=0L, int timeout=-1, bool *timedout=0L)
 
bool poll (int timeout=-1, bool *timedout=0L)
 
- 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
 
- Public Member Functions inherited from KNetwork::KPassiveSocketBase
 KPassiveSocketBase ()
 
virtual ~KPassiveSocketBase ()
 
virtual bool bind (const KResolverEntry &address)=0
 
virtual bool listen (int backlog)=0
 
virtual void close ()=0
 
virtual KActiveSocketBase * accept ()=0
 
virtual TDESocketAddress localAddress () const =0
 
virtual TDESocketAddress externalAddress () const =0
 

Static Public Member Functions

static TDESocketDevice * createDefault (TDESocketBase *parent)
 
static TDESocketDevice * createDefault (TDESocketBase *parent, int capabilities)
 
static TDESocketDeviceFactoryBase * setDefaultImpl (TDESocketDeviceFactoryBase *factory)
 
static void addNewImpl (TDESocketDeviceFactoryBase *factory, int capabilities)
 
- Static Public Member Functions inherited from KNetwork::TDESocketBase
static TQString errorString (SocketError code)
 
static bool isFatalError (int code)
 

Protected Member Functions

 TDESocketDevice (bool, const TDESocketBase *parent=0L)
 
virtual TQSocketNotifier * createNotifier (TQSocketNotifier::Type type) const
 
- 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)
 

Protected Attributes

int m_sockfd
 

Detailed Description

Low-level socket functionality.

This class provides low-level socket functionality.

Most users will prefer "cooked" interfaces like those of KStreamSocket or TDEServerSocket.

Descended classes from this one provide some other kinds of socket functionality, like proxying or specific socket types.

Author
Thiago Macieira thiag.nosp@m.o.ma.nosp@m.cieir.nosp@m.a@kd.nosp@m.email.nosp@m..net

Definition at line 50 of file tdesocketdevice.h.

Member Enumeration Documentation

◆ Capabilities

enum KNetwork::TDESocketDevice::Capabilities

Capabilities for the socket implementation.

TDESocketDevice-derived classes can implement certain capabilities that are not available in the default class. These capabilities are described by these flags. The default TDESocketDevice class has none of these capabilities.

For the negative capabilities (inabilities, the CanNot* forms), when a capability is not present, the implementation will default to the original behaviour.

Enumerator
CanConnectString 

Can connect to hostnames.

If this flag is present, the string form of connect can be used.

CanBindString 

Can bind to hostnames.

If this flag is present, the string form of bind can be used

CanNotBind 

Can not bind.

If this flag is present, this implementation cannot bind

CanNotListen 

Can not listen.

If this flag is present, this implementation cannot listen

CanMulticast 

Can send multicast as well as join/leave multicast groups.

CanNotUseDatagrams 

Can not use datagrams.

Note that this implies multicast capability not being available either.

Definition at line 63 of file tdesocketdevice.h.

Constructor & Destructor Documentation

◆ TDESocketDevice() [1/3]

TDESocketDevice::TDESocketDevice ( const TDESocketBase *  parent = 0L)
explicit

Default constructor.

The parameter is used to specify which socket this object is used as a device for.

Definition at line 78 of file tdesocketdevice.cpp.

◆ TDESocketDevice() [2/3]

TDESocketDevice::TDESocketDevice ( int  fd)
explicit

Constructs a new object around an already-open socket.

Note: you should write programs that create sockets through the classes whenever possible.

Definition at line 86 of file tdesocketdevice.cpp.

◆ ~TDESocketDevice()

TDESocketDevice::~TDESocketDevice ( )
virtual

Destructor.

This closes the socket if it's open.

Definition at line 103 of file tdesocketdevice.cpp.

◆ TDESocketDevice() [3/3]

TDESocketDevice::TDESocketDevice ( bool  ,
const TDESocketBase *  parent = 0L 
)
protected

Special constructor.

This constructor will cause the internal socket device NOT to be set. Use this if your socket device class takes another underlying socket device.

Parameters
parentthe parent, if any

Definition at line 95 of file tdesocketdevice.cpp.

Member Function Documentation

◆ accept()

TDESocketDevice * TDESocketDevice::accept ( )
virtual

Accepts a new incoming connection.

Note: this function returns a socket of type TDESocketDevice.

Implements KNetwork::KPassiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 309 of file tdesocketdevice.cpp.

◆ addNewImpl()

void TDESocketDevice::addNewImpl ( TDESocketDeviceFactoryBase *  factory,
int  capabilities 
)
static

Adds a factory of TDESocketDevice objects to the list, along with its capabilities flag.

Definition at line 879 of file tdesocketdevice.cpp.

◆ bind()

bool TDESocketDevice::bind ( const KResolverEntry &  address)
virtual

Binds this socket to the given address.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 232 of file tdesocketdevice.cpp.

◆ bytesAvailable()

TQ_LONG TDESocketDevice::bytesAvailable ( ) const
virtual

Returns the number of bytes available for reading without blocking.

Implements KNetwork::KActiveSocketBase.

Definition at line 367 of file tdesocketdevice.cpp.

◆ capabilities()

virtual int KNetwork::TDESocketDevice::capabilities ( ) const
inlinevirtual

Returns the set of capabilities this socket class implements.

The set of capabilities is defined as an OR-ed mask of Capabilities bits.

The default implementation is guaranteed to always return 0. That is, derived implementations always return bits where they differ from the system standard sockets.

Reimplemented in KNetwork::KHttpProxySocketDevice, KNetwork::KSocksSocketDevice, and KNetwork::KMulticastSocketImpl.

Definition at line 134 of file tdesocketdevice.h.

◆ close()

void TDESocketDevice::close ( )
virtual

Closes the socket.

Reimplemented from TQIODevice.

Use this function to close the socket this object is holding open.

Implements KNetwork::KPassiveSocketBase.

Reimplemented in KNetwork::KHttpProxySocketDevice.

Definition at line 180 of file tdesocketdevice.cpp.

◆ connect()

bool TDESocketDevice::connect ( const KResolverEntry &  address)
virtual

Connect to a remote host.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KHttpProxySocketDevice, KNetwork::KSocksSocketDevice, and KNetwork::KMulticastSocketImpl.

Definition at line 276 of file tdesocketdevice.cpp.

◆ create() [1/2]

bool TDESocketDevice::create ( const KResolverEntry &  address)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Creates a socket but don't connect or bind anywhere.

Definition at line 227 of file tdesocketdevice.cpp.

◆ create() [2/2]

bool TDESocketDevice::create ( int  family,
int  type,
int  protocol 
)
virtual

Creates a socket but don't connect or bind anywhere.

This function is the equivalent of the system call socket(2).

Reimplemented in KNetwork::KMulticastSocketImpl.

Definition at line 201 of file tdesocketdevice.cpp.

◆ createDefault() [1/2]

TDESocketDevice * TDESocketDevice::createDefault ( TDESocketBase *  parent)
static

Creates a new default TDESocketDevice object given the parent object.

The capabilities flag indicates the desired capabilities the object being created should possess. Those capabilities are not guaranteed: if no factory can provide such an object, a default object will be created.

Parameters
parentthe TDESocketBase parent

Definition at line 839 of file tdesocketdevice.cpp.

◆ createDefault() [2/2]

TDESocketDevice * TDESocketDevice::createDefault ( TDESocketBase *  parent,
int  capabilities 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This will create an object only if the requested capabilities match.

Parameters
parentthe parent
capabilitiesthe requested capabilities

Definition at line 854 of file tdesocketdevice.cpp.

◆ createNotifier()

TQSocketNotifier * TDESocketDevice::createNotifier ( TQSocketNotifier::Type  type) const
protectedvirtual

Creates a socket notifier of the given type.

This function is called by readNotifier, writeNotifier and exceptionNotifier when they need to create a socket notifier (i.e., the first call to those functions after the socket is open). After that call, those functions cache the socket notifier and will not need to call this function again.

Reimplement this function in your derived class if your socket type requires a different kind of TQSocketNotifier. The return value should be deleteable with delete. (close deletes them).

Parameters
typethe socket notifier type

Definition at line 791 of file tdesocketdevice.cpp.

◆ disconnect()

bool TDESocketDevice::disconnect ( )
virtual

Disconnects this socket.

Implements KNetwork::KActiveSocketBase.

Definition at line 333 of file tdesocketdevice.cpp.

◆ exceptionNotifier()

TQSocketNotifier * TDESocketDevice::exceptionNotifier ( ) const

Returns a socket notifier for exceptional events on this socket.

The is created only when requested.

This function might return NULL.

Definition at line 645 of file tdesocketdevice.cpp.

◆ externalAddress()

TDESocketAddress TDESocketDevice::externalAddress ( ) const
virtual

Returns this socket's externally visible local address.

If this socket has a local address visible externally different from the normal local address (as returned by localAddress), then return it.

Certain implementations will use proxies and thus have externally visible addresses different from the local socket values. The default implementation returns the same value as localAddress.

Note
This function may return an empty TDESocketAddress. In that case, the externally visible address could/can not be determined.

Implements KNetwork::KPassiveSocketBase.

Reimplemented in KNetwork::KHttpProxySocketDevice, and KNetwork::KSocksSocketDevice.

Definition at line 602 of file tdesocketdevice.cpp.

◆ flush()

virtual void KNetwork::TDESocketDevice::flush ( )
inlinevirtual

This call is not supported on sockets.

Reimplemented from TQIODevice.

Definition at line 157 of file tdesocketdevice.h.

◆ listen()

bool TDESocketDevice::listen ( int  backlog = 5)
virtual

Puts this socket into listening mode.

Implements KNetwork::KPassiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 255 of file tdesocketdevice.cpp.

◆ localAddress()

TDESocketAddress TDESocketDevice::localAddress ( ) const
virtual

Returns this socket's local address.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 530 of file tdesocketdevice.cpp.

◆ open()

bool TDESocketDevice::open ( int  mode)
virtual

Reimplementation from TQIODevice.

You should not call this function in sockets.

Definition at line 174 of file tdesocketdevice.cpp.

◆ peekBlock() [1/2]

TQ_LONG TDESocketDevice::peekBlock ( char *  data,
TQ_ULONG  maxlen 
)
virtual

Peeks data in the socket.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 459 of file tdesocketdevice.cpp.

◆ peekBlock() [2/2]

TQ_LONG TDESocketDevice::peekBlock ( char *  data,
TQ_ULONG  maxlen,
TDESocketAddress &  from 
)
virtual

Peeks the data in the socket and the source address.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 480 of file tdesocketdevice.cpp.

◆ peerAddress()

TDESocketAddress TDESocketDevice::peerAddress ( ) const
virtual

Returns this socket's peer address.

If this implementation does proxying of some sort, this is the real external address, not the proxy's address.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KHttpProxySocketDevice, and KNetwork::KSocksSocketDevice.

Definition at line 566 of file tdesocketdevice.cpp.

◆ poll() [1/2]

bool TDESocketDevice::poll ( bool *  input,
bool *  output,
bool *  exception = 0L,
int  timeout = -1,
bool *  timedout = 0L 
)
virtual

Executes a poll in the socket, via select(2) or poll(2).

The events polled are returned in the parameters pointers. Set any of them to NULL to disable polling of that event.

On exit, input, output and exception will contain true if an event of that kind is waiting on the socket or false if not. If a timeout occurred, set timedout to true (all other parameters are necessarily set to false).

Parameters
inputif set, turns on polling for input events
outputif set, turns on polling for output events
exceptionif set, turns on polling for exceptional events
timeoutthe time in milliseconds to wait for an event; 0 for no wait and any negative value to wait forever
timedouton exit, will contain true if the polling timed out
Returns
true if the poll call succeeded and false if an error occurred

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 663 of file tdesocketdevice.cpp.

◆ poll() [2/2]

bool TDESocketDevice::poll ( int  timeout = -1,
bool *  timedout = 0L 
)

Shorter version to poll for any events in a socket.

This call polls for input, output and exceptional events in a socket but does not return their states. This is useful if you need to wait for any event, but don't need to know which; or for timeouts.

Parameters
timeoutthe time in milliseconds to wait for an event; 0 for no wait and any negative value to wait forever
timedouton exit, will contain true if the polling timed out
Returns
true if the poll call succeeded and false if an error occurred

Definition at line 785 of file tdesocketdevice.cpp.

◆ readBlock() [1/2]

TQ_LONG TDESocketDevice::readBlock ( char *  data,
TQ_ULONG  maxlen 
)
virtual

Reads data from this socket.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 417 of file tdesocketdevice.cpp.

◆ readBlock() [2/2]

TQ_LONG TDESocketDevice::readBlock ( char *  data,
TQ_ULONG  maxlen,
TDESocketAddress &  from 
)
virtual

Reads data and the source address from this socket.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 438 of file tdesocketdevice.cpp.

◆ readNotifier()

TQSocketNotifier * TDESocketDevice::readNotifier ( ) const

Returns a socket notifier for input on this socket.

The notifier is created only when requested. Whether it is enabled or not depends on the implementation.

This function might return NULL.

Definition at line 609 of file tdesocketdevice.cpp.

◆ setDefaultImpl()

TDESocketDeviceFactoryBase * TDESocketDevice::setDefaultImpl ( TDESocketDeviceFactoryBase *  factory)
static

Sets the default TDESocketDevice implementation to use and return the old factory.

Parameters
factorythe factory object for the implementation

Definition at line 871 of file tdesocketdevice.cpp.

◆ setSocketOptions()

bool TDESocketDevice::setSocketOptions ( int  opts)
virtual

This implementation sets the options on the socket.

Reimplemented from KNetwork::TDESocketBase.

Definition at line 110 of file tdesocketdevice.cpp.

◆ socket()

int KNetwork::TDESocketDevice::socket ( ) const
inline

Returns the file descriptor for this socket.

Definition at line 122 of file tdesocketdevice.h.

◆ waitForMore()

TQ_LONG TDESocketDevice::waitForMore ( int  msecs,
bool *  timeout = 0L 
)
virtual

Waits up to msecs for more data to be available on this socket.

This function is a wrapper against poll. This function will wait for any read events.

Implements KNetwork::KActiveSocketBase.

Definition at line 379 of file tdesocketdevice.cpp.

◆ writeBlock() [1/2]

TQ_LONG TDESocketDevice::writeBlock ( const char *  data,
TQ_ULONG  len 
)
virtual

Writes data to the socket.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 501 of file tdesocketdevice.cpp.

◆ writeBlock() [2/2]

TQ_LONG TDESocketDevice::writeBlock ( const char *  data,
TQ_ULONG  len,
const TDESocketAddress &  to 
)
virtual

Writes the given data to the given destination address.

Implements KNetwork::KActiveSocketBase.

Reimplemented in KNetwork::KSocksSocketDevice.

Definition at line 506 of file tdesocketdevice.cpp.

◆ writeNotifier()

TQSocketNotifier * TDESocketDevice::writeNotifier ( ) const

Returns a socket notifier for output on this socket.

The is created only when requested.

This function might return NULL.

Definition at line 627 of file tdesocketdevice.cpp.

Member Data Documentation

◆ m_sockfd

int KNetwork::TDESocketDevice::m_sockfd
protected

The socket file descriptor.

It is used throughout the implementation and subclasses.

Definition at line 95 of file tdesocketdevice.h.


The documentation for this class was generated from the following files:
  • tdesocketdevice.h
  • tdesocketdevice.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.