kdecore Library API Documentation

KServerSocket Class Reference

Monitors a port for incoming TCP/IP connections. More...

#include <ksock.h>

Inheritance diagram for KServerSocket:

QObject List of all members.

Public Slots

virtual void slotAccept (int)
 Called when someone connected to our port.


Signals

void accepted (KSocket *s)
 A connection has been accepted.


Public Methods

 KServerSocket (unsigned short int _port, bool _bind=true)
 Constructor.

 KServerSocket (const char *_path, bool _bind=true)
 Creates a UNIX domain server socket.

virtual ~KServerSocket ()
 Destructor.

bool bindAndListen ()
 Binds the socket and start listening.

int socket () const
 Returns the file descriptor associated with the socket.

unsigned short int port ()
 Returns the port number which is being monitored.


Protected Attributes

int sock
 The file descriptor for this socket.


Detailed Description

Monitors a port for incoming TCP/IP connections.

Deprecated:
Please use the more powerful KExtendedSocket class.

You can use a KServerSocket to listen on a port for incoming connections. When a connection arrived in the port, a KSocket is created and the signal accepted is raised. Make sure you always connect to this signal. If you don't the ServerSocket will create new KSocket's and no one will delete them!

If socket() is -1 or less the socket was not created properly.

Author:
Torben Weis <weis@stud.uni-frankfurt.de>
Version:
Id:
ksock.h,v 1.53 2002/09/09 21:24:53 tjansen Exp

Definition at line 241 of file ksock.h.


Constructor & Destructor Documentation

KServerSocket::KServerSocket unsigned short int    _port,
bool    _bind = true
 

Constructor.

Parameters:
_port  the port number to monitor for incoming connections.
_bind  if false you need to call bindAndListen yourself. This gives you the opportunity to set options on the socket.

Definition at line 292 of file ksock.cpp.

KServerSocket::KServerSocket const char *    _path,
bool    _bind = true
 

Creates a UNIX domain server socket.

Parameters:
_path  path used for the socket.
_bind  if false you need to call bindAndListen yourself. This gives you the opportunity to set options on the socket.

Definition at line 283 of file ksock.cpp.

KServerSocket::~KServerSocket   [virtual]
 

Destructor.

Closes the socket if it was not already closed.

Definition at line 419 of file ksock.cpp.


Member Function Documentation

bool KServerSocket::bindAndListen  
 

Binds the socket and start listening.

This should only be called once when the constructor was called with _bind false. On error the socket will be closed.

Returns:
true on success. false on error.

Definition at line 329 of file ksock.cpp.

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

int KServerSocket::socket   const [inline]
 

Returns the file descriptor associated with the socket.

Returns:
the file descriptor, -1 when an error occured during construction or bindAndListen

Definition at line 281 of file ksock.h.

References sock.

unsigned short int KServerSocket::port  
 

Returns the port number which is being monitored.

Returns:
the port number

Definition at line 353 of file ksock.cpp.

References KSocketAddress::address(), kde_sockaddr_in6::sin6_port, and sock.

void KServerSocket::slotAccept int    [virtual, slot]
 

Called when someone connected to our port.

Definition at line 400 of file ksock.cpp.

References accepted(), KExtendedSocket::fd(), KExtendedSocket::release(), and sock.

Referenced by bindAndListen().

void KServerSocket::accepted KSocket   s [signal]
 

A connection has been accepted.

It is your task to delete the KSocket if it is no longer needed.

WARNING: this signal is always emitted, even if you don't connect anything to it. That would mean memory loss, because the KSockets created go to oblivion.

Parameters:
s  the socket that accepted

Referenced by slotAccept().


Member Data Documentation

int KServerSocket::sock [protected]
 

The file descriptor for this socket.

sock may be -1. This indicates that it is not connected.

Definition at line 326 of file ksock.h.

Referenced by bindAndListen(), port(), slotAccept(), and socket().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:20:46 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001