class Poco::Net::ServerSocket

Overview

This class provides an interface to a TCP server socket. More…

#include <ServerSocket.h>

class ServerSocket: public Poco::Net::Socket
{
public:
    // construction

    ServerSocket();
    ServerSocket(const Socket& socket);

    ServerSocket(
        const SocketAddress& address,
        int backlog = 64
        );

    ServerSocket(
        Poco::UInt16 port,
        int backlog = 64
        );

    // methods

    ServerSocket&
    operator=(const Socket& socket);

    virtual
    void
    bind(
        const SocketAddress& address,
        bool reuseAddress = false
        );

    virtual
    void
    bind(
        Poco::UInt16 port,
        bool reuseAddress = false
        );

    virtual
    void
    bind6(
        const SocketAddress& address,
        bool reuseAddress = false,
        bool ipV6Only = false
        );

    virtual
    void
    bind6(
        Poco::UInt16 port,
        bool reuseAddress = false,
        bool ipV6Only = false
        );

    virtual
    void
    listen(int backlog = 64);

    virtual
    StreamSocket
    acceptConnection(SocketAddress& clientAddr);

    virtual
    StreamSocket
    acceptConnection();

protected:
    // construction

    ServerSocket(
        SocketImpl* pImpl,
        bool
        );
};

Inherited Members

public:
    // typedefs

    typedef std::vector<Socket> SocketList;

    // enums

    enum SelectMode;

    // methods

    Socket&
    operator=(const Socket& socket);

    bool
    operator==(const Socket& socket) const;

    bool
    operator!=(const Socket& socket) const;

    bool
    operator<(const Socket& socket) const;

    bool
    operator<=(const Socket& socket) const;

    bool
    operator>(const Socket& socket) const;

    bool
    operator>=(const Socket& socket) const;

    void
    close();

    bool
    poll(
        const Poco::Timespan& timeout,
        int mode
        ) const;

    int
    available() const;

    void
    setSendBufferSize(int size);

    int
    getSendBufferSize() const;

    void
    setReceiveBufferSize(int size);

    int
    getReceiveBufferSize() const;

    void
    setSendTimeout(const Poco::Timespan& timeout);

    Poco::Timespan
    getSendTimeout() const;

    void
    setReceiveTimeout(const Poco::Timespan& timeout);

    Poco::Timespan
    getReceiveTimeout() const;

    void
    setOption(
        int level,
        int option,
        int value
        );

    void
    setOption(
        int level,
        int option,
        unsigned value
        );

    void
    setOption(
        int level,
        int option,
        unsigned char value
        );

    void
    setOption(
        int level,
        int option,
        const Poco::Timespan& value
        );

    void
    setOption(
        int level,
        int option,
        const IPAddress& value
        );

    void
    getOption(
        int level,
        int option,
        int& value
        ) const;

    void
    getOption(
        int level,
        int option,
        unsigned& value
        ) const;

    void
    getOption(
        int level,
        int option,
        unsigned char& value
        ) const;

    void
    getOption(
        int level,
        int option,
        Poco::Timespan& value
        ) const;

    void
    getOption(
        int level,
        int option,
        IPAddress& value
        ) const;

    void
    setLinger(
        bool on,
        int seconds
        );

    void
    getLinger(
        bool& on,
        int& seconds
        ) const;

    void
    setNoDelay(bool flag);

    bool
    getNoDelay() const;

    void
    setKeepAlive(bool flag);

    bool
    getKeepAlive() const;

    void
    setReuseAddress(bool flag);

    bool
    getReuseAddress() const;

    void
    setReusePort(bool flag);

    bool
    getReusePort() const;

    void
    setOOBInline(bool flag);

    bool
    getOOBInline() const;

    void
    setBlocking(bool flag);

    bool
    getBlocking() const;

    SocketAddress
    address() const;

    SocketAddress
    peerAddress() const;

    SocketImpl*
    impl() const;

    bool
    secure() const;

    void
    init(int af);

    static
    int
    select(
        SocketList& readList,
        SocketList& writeList,
        SocketList& exceptList,
        const Poco::Timespan& timeout
        );

    static
    bool
    supportsIPv4();

    static
    bool
    supportsIPv6();

protected:
    // methods

    poco_socket_t
    sockfd() const;

Detailed Documentation

This class provides an interface to a TCP server socket.

Construction

ServerSocket()

Creates a server socket.

The server socket must be bound to an address and put into listening state.

ServerSocket(const Socket& socket)

Creates the ServerSocket with the SocketImpl from another socket.

The SocketImpl must be a ServerSocketImpl, otherwise an InvalidArgumentException will be thrown.

ServerSocket(
    const SocketAddress& address,
    int backlog = 64
    )

Creates a server socket, binds it to the given address and puts it in listening state.

After successful construction, the server socket is ready to accept connections.

ServerSocket(
    Poco::UInt16 port,
    int backlog = 64
    )

Creates a server socket, binds it to the given port and puts it in listening state.

After successful construction, the server socket is ready to accept connections.

ServerSocket(
    SocketImpl* pImpl,
    bool
    )

The bool argument is to resolve an ambiguity with another constructor (Microsoft Visual C++ 2005)

Methods

ServerSocket&
operator=(const Socket& socket)

Assignment operator.

Releases the socket’s SocketImpl and attaches the SocketImpl from the other socket and increments the reference count of the SocketImpl.

virtual
void
bind(
    const SocketAddress& address,
    bool reuseAddress = false
    )

Binds a local address to the socket.

This is usually only done when establishing a server socket. TCP clients should not bind a socket to a specific address.

If reuseAddress is true, sets the SO_REUSEADDR socket option.

virtual
void
bind(
    Poco::UInt16 port,
    bool reuseAddress = false
    )

Binds a local port to the socket.

This is usually only done when establishing a server socket.

If reuseAddress is true, sets the SO_REUSEADDR socket option.

virtual
void
bind6(
    const SocketAddress& address,
    bool reuseAddress = false,
    bool ipV6Only = false
    )

Binds a local IPv6 address to the socket.

This is usually only done when establishing a server socket. TCP clients should not bind a socket to a specific address.

If reuseAddress is true, sets the SO_REUSEADDR socket option.

The given address must be an IPv6 address. The IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket according to the ipV6Only parameter.

If the library has not been built with IPv6 support, a Poco::NotImplementedException will be thrown.

virtual
void
bind6(
    Poco::UInt16 port,
    bool reuseAddress = false,
    bool ipV6Only = false
    )

Binds a local IPv6 port to the socket.

This is usually only done when establishing a server socket.

If reuseAddress is true, sets the SO_REUSEADDR socket option.

The given address must be an IPv6 address. The IPPROTO_IPV6/IPV6_V6ONLY option is set on the socket according to the ipV6Only parameter.

If the library has not been built with IPv6 support, a Poco::NotImplementedException will be thrown.

virtual
void
listen(int backlog = 64)

Puts the socket into listening state.

The socket becomes a passive socket that can accept incoming connection requests.

The backlog argument specifies the maximum number of connections that can be queued for this socket.

virtual
StreamSocket
acceptConnection(SocketAddress& clientAddr)

Gets the next completed connection from the socket’s completed connection queue.

If the queue is empty, waits until a connection request completes.

Returns a new TCP socket for the connection with the client.

The client socket’s address is returned in clientAddr.

virtual
StreamSocket
acceptConnection()

Gets the next completed connection from the socket’s completed connection queue.

If the queue is empty, waits until a connection request completes.

Returns a new TCP socket for the connection with the client.