.. index:: pair: class; EE::Network::Socket .. _doxid-class_e_e_1_1_network_1_1_socket: class EE::Network::Socket ========================= .. toctree:: :hidden: enum_EE_Network_Socket_Status.rst Overview ~~~~~~~~ Base class for all the socket types. :ref:`More...` .. ref-code-block:: cpp :class: doxyrest-overview-code-block #include class Socket: private :ref:`EE::NonCopyable` { public: // enums enum { :ref:`AnyPort` = 0, }; enum :ref:`Status`; // construction virtual :ref:`~Socket`(); // methods void :ref:`setBlocking`(bool blocking); bool :ref:`isBlocking`() const; }; .. _details-class_e_e_1_1_network_1_1_socket: Detailed Documentation ~~~~~~~~~~~~~~~~~~~~~~ Base class for all the socket types. This class mainly defines internal stuff to be used by derived classes. The only public features that it defines, and which is therefore common to all the socket classes, is the blocking state. All sockets can be set as blocking or non-blocking. In blocking mode, socket functions will hang until the operation completes, which means that the entire program (well, in fact the current thread if you use multiple ones) will be stuck waiting for your socket operation to complete. In non-blocking mode, all the socket functions will return immediately. If the socket is not ready to complete the requested operation, the function simply returns the proper status code (:ref:`Socket::NotReady `). The default mode, which is blocking, is the one that is generally used, in combination with threads or selectors. The non-blocking mode is rather used in real-time applications that run an endless loop that can poll the socket often enough, and cannot afford blocking this loop. .. rubric:: See also: :ref:`EE::Network::TcpListener `, :ref:`EE::Network::TcpSocket `, :ref:`EE::Network::UdpSocket ` Enum Values ----------- .. index:: pair: enumvalue; AnyPort .. _doxid-class_e_e_1_1_network_1_1_socket_1aef2c62da180f35c2929b74232065cd07a471e0ea3d91d6c8710afe793686a42dd: .. ref-code-block:: cpp :class: doxyrest-title-code-block AnyPort Special value that tells the system to pick any available port. Construction ------------ .. _doxid-class_e_e_1_1_network_1_1_socket_1a8d35051e84beb41f396027e343635dce: .. ref-code-block:: cpp :class: doxyrest-title-code-block virtual ~Socket() Destructor. Methods ------- .. index:: pair: function; setBlocking .. _doxid-class_e_e_1_1_network_1_1_socket_1a2c93eb187c95d7ef9948cb51b79f8943: .. ref-code-block:: cpp :class: doxyrest-title-code-block void setBlocking(bool blocking) Set the blocking state of the socket In blocking mode, calls will not return until they have completed their task. For example, a call to Receive in blocking mode won't return until some data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking. .. rubric:: Parameters: .. list-table:: :widths: 20 80 * - blocking - True to set the socket as blocking, false for non-blocking .. rubric:: See also: IsBlocking .. index:: pair: function; isBlocking .. _doxid-class_e_e_1_1_network_1_1_socket_1aae9c7f6550d1eea38a12839fbea3d356: .. ref-code-block:: cpp :class: doxyrest-title-code-block bool isBlocking() const Tell whether the socket is in blocking or non-blocking mode. .. rubric:: Returns: True if the socket is blocking, false otherwise .. rubric:: See also: SetBlocking