Cross-Platform C++

ot::net
class SocketImpl  (abstract)

#include "ot/net/SocketImpl.h"

ot::ManagedObject An abstract base class providing an interface for classes that implement sockets. It is used for both client and server sockets. OpenTop is supplied with an undocumented PlainSocketImpl class which provides a default implementation.




Method Summary
protected  virtual void accept(SocketImpl* pSocket)=0
         Waits for and accepts a new socket connection on a passive (server) socket.
protected  virtual size_t available() const=0
         Returns the number of bytes that may be read from the socket without blocking.
protected  virtual void bind(InetAddress* pAddress, int port)=0
         Binds this socket to the specified port and IP address.
protected  virtual void close()=0
         Closes the underlying operating system socket.
protected  virtual void connect(InetAddress* pAddress, int port)=0
         Brief.
protected  virtual void connect(const String& host, int port)=0
         Opens a socket connection with the named host.
protected  virtual void connect(InetAddress* pAddress, int port, size_t timeoutMS)=0
         Opens a socket connection with the specified IP address.
protected  virtual void create(bool bStream)=0
         Creates a socket handle that will be managed and contained by this SocketImpl.
protected  virtual bool getAutoClose() const=0
        
protected  virtual RefPtr< InetAddress > getInetAddress() const=0
         Returns the IP address to which this socket is bound or connected.
protected  virtual RefPtr< InputStream > getInputStream() const=0
         Returns an InputStream that can be used to read bytes from the client socket.
protected  virtual int getIntOption(int level, int option) const=0
         Fetches the (integer) value of a socket option.
protected  virtual RefPtr< InetAddress > getLocalAddress() const=0
         Returns the IP address to which the socket is bound.
protected  virtual int getLocalPort() const=0
         Returns the port number to which the socket is bound.
protected  virtual RefPtr< OutputStream > getOutputStream() const=0
         Returns an output stream for writing bytes to a client socket.
protected  virtual int getPort() const=0
         Returns the remote port to which a client socket is connected.
protected  virtual RefPtr< InetAddress > getRemoteAddress() const=0
         Returns the IP address to which the client socket is connected.
protected  virtual RefPtr< SocketDescriptor > getSocketDescriptor() const=0
         Returns a SocketDescriptor for the contained operating system socket.
protected  virtual size_t getTimeout() const=0
         Fetches the value of the pseudo socket option: SO_TIMEOUT.
protected  virtual void getVoidOption(int level, int option, void* pOut, size_t* pLen) const=0
         Fetches the data value of a socket option.
protected  virtual bool isBound() const=0
         Tests if a server Socket has yet been bound to a local IP address and port.
protected  virtual bool isClosed() const=0
         Tests if the socket is closed.
protected  virtual bool isConnected() const=0
         Tests the connected status of this Socket.
protected  virtual void listen(size_t backlog)=0
         Puts the server socket into listening mode and sets the maximum queue size for pending connection requests.
protected  virtual void setAutoClose(bool bEnable)=0
        
protected  virtual void setInetAddress(InetAddress* pAddress)=0
         Sets the remote IP address for a newly accepted client socket.
protected  virtual void setIntOption(int level, int option, int value)=0
         Sets a (integer) socket option.
protected  virtual void setLocalPort(int localPort)=0
         Sets the local port for a newly accepted client socket.
protected  virtual void setPort(int port)=0
         Sets the remote port for a newly accepted client socket.
protected  virtual void setSocketDescriptor(SocketDescriptor* pSocketDescriptor)=0
         Sets the socket descriptor for a newly accepted client socket.
protected  virtual void setTimeout(size_t timeoutMS)=0
         Sets the value of the pseudo socket option: SO_TIMEOUT.
protected  virtual void setVoidOption(int level, int option, void* pValue, size_t valLen)=0
         Sets a void socket option.
protected  virtual void shutdownInput()=0
         Shuts down this Socket for input operations.
protected  virtual void shutdownOutput()=0
         Shuts down this Socket for output operations.
protected  virtual String toString() const=0
         Returns a string representation of the socket.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Method Detail

accept

protected virtual void accept(SocketImpl* pSocket)=0
Waits for and accepts a new socket connection on a passive (server) socket. When a new connection is established, the passed SocketImpl is updated to reflect the details of the new socket.

Parameters:
pSocket - a pointer to a SocketImpl which will be used to represent the new connection.
Exceptions:
SocketTimeoutException - if the SO_TIMEOUT pseudo socket option has been set for this server socket, and the specified timeout time elapses before a new connection request arrives.
SocketException - if an error occurs accepting a new connection.

available

protected virtual size_t available() const=0
Returns the number of bytes that may be read from the socket without blocking.


bind

protected virtual void bind(InetAddress* pAddress,
                            int port)=0
Binds this socket to the specified port and IP address. Before a server socket enters the passive state (by listen()) it must be bound to a port and (optionally) a local interface.

Parameters:
pAddress - the IP address to bind to. A null pointer means that the socket will be bound to ANY local interface.
port - the port number. A value of 0 indicates that the system will choose the next available port.
Exceptions:
SocketException - if an error occurs binding the socket.

close

protected virtual void close()=0
Closes the underlying operating system socket. In common with most close() methods, further calls to close() have no effect.


connect

protected virtual void connect(InetAddress* pAddress,
                               int port)=0
Brief. Description


connect

protected virtual void connect(const String& host,
                               int port)=0
Opens a socket connection with the named host.

Parameters:
host - the host name
port - the port number
Exceptions:
UnknownHostException - if the host name cannot be resolved into an IP address
SocketException - if an error occurs trying to connect to the host

connect

protected virtual void connect(InetAddress* pAddress,
                               int port,
                               size_t timeoutMS)=0
Opens a socket connection with the specified IP address.

Parameters:
host - the host name
port - the port number
timeoutMS - a timeout value (in milliseconds)
Exceptions:
SocketException - if an error occurs trying to connect to the host
SocketTimeoutException - if timeoutMS milliseconds elapses before the connection can be successfully established.

create

protected virtual void create(bool bStream)=0
Creates a socket handle that will be managed and contained by this SocketImpl.

Parameters:
bStream - if true, creates a Stream (TCP/IP) socket; otherwise creates a datagram (UDP) socket

getAutoClose

protected virtual bool getAutoClose() const=0


getInetAddress

protected virtual RefPtr< InetAddressgetInetAddress() const=0
Returns the IP address to which this socket is bound or connected. For passive (server) sockets, this returns the local address to which the socket is bound. For client sockets, this returns the remote IP address to which the socket is connected.

Returns:
A (reference-counted) pointer to an InetAddress object or null if the socket is not bound or connected.

getInputStream

protected virtual RefPtr< InputStreamgetInputStream() const=0
Returns an InputStream that can be used to read bytes from the client socket.

Exceptions:
SocketException - if the socket is not a connected client socket.
See also:
getOutputStream()

getIntOption

protected virtual int getIntOption(int level,
                                   int option) const=0
Fetches the (integer) value of a socket option.

Parameters:
level - the socket option level.
option - the socket option.
Exceptions:
SocketException - if an error occurs fetching the socket option value.

getLocalAddress

protected virtual RefPtr< InetAddressgetLocalAddress() const=0
Returns the IP address to which the socket is bound.

Returns:
A (reference-counted) pointer to an InetAddress object or null if the socket is not bound or connected.

getLocalPort

protected virtual int getLocalPort() const=0
Returns the port number to which the socket is bound.

Returns:
The local port number of -1 if the socket is not bound or connected.
See also:
isBound()

getOutputStream

protected virtual RefPtr< OutputStreamgetOutputStream() const=0
Returns an output stream for writing bytes to a client socket.

Exceptions:
SocketException - if the socket is not a connected client socket.
See also:
getInputStream()

getPort

protected virtual int getPort() const=0
Returns the remote port to which a client socket is connected.


getRemoteAddress

protected virtual RefPtr< InetAddressgetRemoteAddress() const=0
Returns the IP address to which the client socket is connected.

Returns:
A (reference-counted) pointer to an InetAddress object or null if the socket is not connected or is not a client socket.

getSocketDescriptor

protected virtual RefPtr< SocketDescriptorgetSocketDescriptor() const=0
Returns a SocketDescriptor for the contained operating system socket.


getTimeout

protected virtual size_t getTimeout() const=0
Fetches the value of the pseudo socket option: SO_TIMEOUT.


getVoidOption

protected virtual void getVoidOption(int level,
                                     int option,
                                     void* pOut,
                                     size_t* pLen) const=0
Fetches the data value of a socket option.

Parameters:
level - the socket option level.
option - the socket option.
pOut - a pointer to a byte array to hold the result
pLen - a return parameter that must contain the size of the byte array on input and holds the size of the array used on return.
Exceptions:
SocketException - if an error occurs fetching the socket option value.

isBound

protected virtual bool isBound() const=0
Tests if a server Socket has yet been bound to a local IP address and port.


isClosed

protected virtual bool isClosed() const=0
Tests if the socket is closed.

Returns:
true if the Socket is closed; false otherwise.
Since:
1.3

isConnected

protected virtual bool isConnected() const=0
Tests the connected status of this Socket.

Returns:
true if the Socket is connected; false otherwise.

listen

protected virtual void listen(size_t backlog)=0
Puts the server socket into listening mode and sets the maximum queue size for pending connection requests. Once a socket has been placed into listening mode, the application must call accept() to accept incoming connections.

Parameters:
backlog - the maximum size of the pending connection queue. If a connection request arrives when the queue is full, the underlying socket implementation will refuse the connection.
Exceptions:
SocketException - if an error occurs.
See also:
accept()

setAutoClose

protected virtual void setAutoClose(bool bEnable)=0


setInetAddress

protected virtual void setInetAddress(InetAddress* pAddress)=0
Sets the remote IP address for a newly accepted client socket.


setIntOption

protected virtual void setIntOption(int level,
                                    int option,
                                    int value)=0
Sets a (integer) socket option.

Parameters:
level - the socket option level.
option - the socket option.
value - the new value for the socket option.
Exceptions:
SocketException - if an error occurs setting the socket option.

setLocalPort

protected virtual void setLocalPort(int localPort)=0
Sets the local port for a newly accepted client socket.


setPort

protected virtual void setPort(int port)=0
Sets the remote port for a newly accepted client socket.


setSocketDescriptor

protected virtual void setSocketDescriptor(SocketDescriptor* pSocketDescriptor)=0
Sets the socket descriptor for a newly accepted client socket.


setTimeout

protected virtual void setTimeout(size_t timeoutMS)=0
Sets the value of the pseudo socket option: SO_TIMEOUT.

Parameters:
timeoutMS - the value of the SO_TIMEOUT pseudo option.

setVoidOption

protected virtual void setVoidOption(int level,
                                     int option,
                                     void* pValue,
                                     size_t valLen)=0
Sets a void socket option.

Parameters:
level - the socket option level.
option - the socket option.
pValue - a pointer to a byte array containing the new option value
valLen - the length of the passed byte array
Exceptions:
SocketException - if an error occurs setting the socket option value.

shutdownInput

protected virtual void shutdownInput()=0
Shuts down this Socket for input operations. Any unread data in the socket's receive buffer is discarded. Any read operations from this socket's InputStream will result in an EndOfFile condition.

Exceptions:
SocketException - if an error occurs shutting down the socket

shutdownOutput

protected virtual void shutdownOutput()=0
Shuts down this Socket for output operations. Any previously written data will be flushed to the peer host, followed by TCP's normal connection termination sequence. If an attempt is made to write write data to the socket's output stream after invoking shutdownOutput(), an IOException will be thrown.

Exceptions:
SocketException - if an error occurs shutting down the socket

toString

protected virtual String toString() const=0
Returns a string representation of the socket.



Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements