PixelLightAPI  .
Public Member Functions
PLCore::Socket Class Reference

Socket class. More...

#include <Socket.h>

List of all members.

Public Member Functions

PLCORE_API Socket ()
 Constructor.
 Socket (const Socket &cSocket)
 Copy constructor.
 Socket (handle nSocket)
 Constructor.
 ~Socket ()
 Destructor.
PLCORE_API bool IsValid () const
 Returns whether the socket is currently valid.
PLCORE_API bool Close ()
 Closes the socket.
const SocketAddressGetSocketAddress () const
 Returns the socket address object.
bool Connect (const String &sAddress, uint32 nPort)
 Establishes a connection to a host by using an address and port.
PLCORE_API bool Connect (const SocketAddress &cSocketAddress)
 Establishes a connection to a host by using a given socked address.
bool Bind (uint32 nPort)
 Associate local address with socket.
bool Bind (const String &sAddress, uint32 nPort)
 Associate local address with socket.
PLCORE_API bool Bind (const SocketAddress &cSocketAddress)
 Associate local address with socket.
PLCORE_API bool Listen (int nMaxQueue=0) const
 Mark a socket as accepting connections.
PLCORE_API Socket Accept () const
 Accept a connection on a socket (blocking)
PLCORE_API int Send (const char *pBuffer, uint32 nSize) const
 Sends data.
PLCORE_API bool IsDataWaiting () const
 Returns whether or not data is waiting to be received (non-blocking request)
PLCORE_API int Receive (char *pBuffer, uint32 nSize) const
 Receives data (blocking request)

Detailed Description

Socket class.

Remarks:
A socket is an object used to send and receive data.

Constructor & Destructor Documentation

PLCORE_API PLCore::Socket::Socket ( )
PLCore::Socket::Socket ( const Socket cSocket) [inline]

Copy constructor.

Parameters:
[in]cSocketSocket to copy from
PLCore::Socket::Socket ( handle  nSocket) [inline]

Constructor.

Parameters:
[in]nSocketSystem socket handle
Note:
  • Should be used mainly to create an invalid socket ('INVALID_SOCKET')

Destructor.


Member Function Documentation

PLCORE_API bool PLCore::Socket::IsValid ( ) const

Returns whether the socket is currently valid.

Returns:
'true' if the socket is currently valid, else 'false'
PLCORE_API bool PLCore::Socket::Close ( )

Closes the socket.

Returns:
'true' if all went fine, else 'false' (maybe it's already closed?)
const SocketAddress & PLCore::Socket::GetSocketAddress ( ) const [inline]

Returns the socket address object.

Returns:
The socket address object
bool PLCore::Socket::Connect ( const String sAddress,
uint32  nPort 
) [inline]

Establishes a connection to a host by using an address and port.

Parameters:
[in]sAddressAddress of the host to connect to
[in]nPortNumber of the port to use
Returns:
'true' if all went fine, else 'false'
PLCORE_API bool PLCore::Socket::Connect ( const SocketAddress cSocketAddress)

Establishes a connection to a host by using a given socked address.

Parameters:
[in]cSocketAddressSocket address of the host to connect to
Returns:
'true' if all went fine, else 'false'
bool PLCore::Socket::Bind ( uint32  nPort) [inline]

Associate local address with socket.

Parameters:
[in]nPortNumber of the port to use
Returns:
'true' if all went fine, else 'false'
bool PLCore::Socket::Bind ( const String sAddress,
uint32  nPort 
) [inline]

Associate local address with socket.

Parameters:
[in]sAddressAddress of the host to bind to
[in]nPortNumber of the port to use
Returns:
'true' if all went fine, else 'false'
PLCORE_API bool PLCore::Socket::Bind ( const SocketAddress cSocketAddress)

Associate local address with socket.

Parameters:
[in]cSocketAddressSocket address of the host to bind to
Returns:
'true' if all went fine, else 'false'
PLCORE_API bool PLCore::Socket::Listen ( int  nMaxQueue = 0) const

Mark a socket as accepting connections.

Parameters:
[in]nMaxQueueMaximum length of the queue of pending connections
Returns:
'true' if all went fine, else 'false'
PLCORE_API Socket PLCore::Socket::Accept ( ) const

Accept a connection on a socket (blocking)

Returns:
Socket with the accepted connection or an invalid socket on error
PLCORE_API int PLCore::Socket::Send ( const char *  pBuffer,
uint32  nSize 
) const

Sends data.

Parameters:
[in]pBufferData to send, if a null pointer, nothing is send
[in]nSizeSize in bytes of the buffer to send, MUST be valid!
Returns:
Total number of bytes sent which can be less than the number requested to be sent, negative value on error
PLCORE_API bool PLCore::Socket::IsDataWaiting ( ) const

Returns whether or not data is waiting to be received (non-blocking request)

Returns:
'true' if data is waiting to be received, else 'false'
PLCORE_API int PLCore::Socket::Receive ( char *  pBuffer,
uint32  nSize 
) const

Receives data (blocking request)

Parameters:
[out]pBufferBuffer that receives the data, if a null pointer, nothing can be received
[in]nSizeSize in bytes of the buffer that receives the data, MUST be valid!
Returns:
Total number of received bytes, negative value on error
Note:
  • If there is currently not enough data available, this function will read as much as possible, meaning that less data can be read than requested
  • If more data is waiting to be received as the given buffer is able to store, you have to call this method multiple times in order to gather all waiting data

The documentation for this class was generated from the following files:


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:15
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported