kdecore Library API Documentation

KSocket Class Reference

A TCP/IP client socket. More...

#include <ksock.h>

Inheritance diagram for KSocket:

Inheritance graph
[legend]
Collaboration diagram for KSocket:

Collaboration graph
[legend]
List of all members.

Public Slots

void slotWrite (int x)
void slotRead (int x)

Signals

void readEvent (KSocket *s)
void writeEvent (KSocket *s)
void closeEvent (KSocket *s)

Public Member Functions

 KSocket (int _sock) KDE_DEPRECATED
 KSocket (const char *_host, unsigned short int _port, int timeOut=30) KDE_DEPRECATED
 KSocket (const char *_path) KDE_DEPRECATED
virtual ~KSocket ()
int socket () const
void enableRead (bool enable)
void enableWrite (bool enable)
unsigned long ipv4_addr () KDE_DEPRECATED

Static Public Member Functions

static bool initSockaddr (ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain=PF_INET) KDE_DEPRECATED

Protected Member Functions

bool connect (const QString &_host, unsigned short int _port, int timeout=0)
bool connect (const char *_path)

Protected Attributes

int sock

Detailed Description

A TCP/IP client socket.

Deprecated:
You can connect this socket to any Internet address.

This class is deprecated and will be removed in the future. For new programs, please use KExtendedSocket class.

The socket gives you three signals: When ready for reading, ready for writing or if the connection is broken. Using socket() you get a file descriptor which you can use with the usual UNIX function like write() or read(). If you have already such a socket identifier you can construct a KSocket on this identifier.

If socket() delivers a value of -1 or less, the connection was not successful.

Author:
Torben Weis <weis@uni-frankfurt.de>

Definition at line 87 of file ksock.h.


Constructor & Destructor Documentation

KSocket::KSocket int  _sock  ) 
 

Constructs a KSocket with the provided file descriptor.

Parameters:
_sock The file descriptor to use.

Definition at line 101 of file ksock.cpp.

References KSocks::getsockname(), and KSocks::self().

KSocket::KSocket const char *  _host,
unsigned short int  _port,
int  timeOut = 30
 

Creates a socket and connects to a host.

Parameters:
_host The remote host to which to connect.
_port The port on the remote host.
timeOut The number of seconds waiting for connect (default 30).

Definition at line 115 of file ksock.cpp.

References connect().

KSocket::KSocket const char *  _path  ) 
 

Connects to a UNIX domain socket.

Parameters:
_path The filename of the socket.

Definition at line 121 of file ksock.cpp.

References connect().

KSocket::~KSocket  )  [virtual]
 

Destructor.

Closes the socket if it is still open.

Definition at line 260 of file ksock.cpp.

References sock.


Member Function Documentation

int KSocket::socket  )  const [inline]
 

Returns a file descriptor for this socket.

Returns:
the file descriptor, or -1 when an error occurred.

Definition at line 119 of file ksock.h.

void KSocket::enableRead bool  enable  ) 
 

Enables the socket for reading.

If you enable read mode, the socket will emit the signal readEvent() whenever there is something to read out of this socket.

Parameters:
enable true to enable reading signals

Definition at line 127 of file ksock.cpp.

References QObject::connect(), slotRead(), and sock.

void KSocket::enableWrite bool  enable  ) 
 

Enables the socket for writing.

If you enable write mode, the socket will emit the signal writeEvent() whenever the socket is ready for writing.

Warning: If you forget to call enableWrite(false) when you are not ready to send data, you will get lots of writeEvent() signals, in the order of thousands a second !

Parameters:
enable true to enable writing signals

Definition at line 143 of file ksock.cpp.

References QObject::connect(), slotWrite(), and sock.

unsigned long KSocket::ipv4_addr  ) 
 

Return address.

This function is dumb. Don't ever use it if you need the peer address of this socket, use KExtendedSocket::peerAddress(int) instead

Deprecated:

Definition at line 207 of file ksock.cpp.

References KSocketAddress::address(), KInetSocketAddress::addressV4(), KExtendedSocket::peerAddress(), and sock.

bool KSocket::initSockaddr ksockaddr_in *  server_name,
const char *  hostname,
unsigned short int  port,
int  domain = PF_INET
[static]
 

A small wrapper around gethostbyname() and such.

Don't use this in new programs. Use KExtendedSocket::lookup

Deprecated:

Definition at line 229 of file ksock.cpp.

References KInetSocketAddress::addressV4(), endl(), QPtrList::getFirst(), QPtrList::isEmpty(), kdDebug(), kdWarning(), KExtendedSocket::lookup(), QString::number(), KInetSocketAddress::pretty(), and QPtrList::setAutoDelete().

void KSocket::readEvent KSocket s  )  [signal]
 

Data has arrived for reading.

This signal will only be raised if enableRead( true ) was called first.

Parameters:
s the KSocket that triggered the event

Referenced by slotRead().

void KSocket::writeEvent KSocket s  )  [signal]
 

Socket is ready for writing.

This signal will only be raised if enableWrite( true ) was called first.

Warning: If you forget to call enableWrite(false) when you are not ready to send data, you will get lots of writeEvent() signals, in the order of thousands a second !

Parameters:
s the KSocket that triggered the event

Referenced by slotWrite().

void KSocket::closeEvent KSocket s  )  [signal]
 

Raised when the connection is broken.

Parameters:
s the KSocket that triggered the event

Referenced by slotRead().

void KSocket::slotWrite int  x  )  [slot]
 

Connected to the writeNotifier.

Called when the socket is ready for writing.

Parameters:
x ignored

Definition at line 171 of file ksock.cpp.

References writeEvent().

Referenced by enableWrite().

void KSocket::slotRead int  x  )  [slot]
 

Connected to the readNotifier.

Called when the socket is ready for reading.

Parameters:
x ignored

Definition at line 160 of file ksock.cpp.

References closeEvent(), readEvent(), and sock.

Referenced by enableRead().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdecore Library Version 3.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Jul 20 13:47:01 2006 by doxygen 1.4.4 written by Dimitri van Heesch, © 1997-2003