class SF::Socket

Overview

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 (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.

See also: SF::TcpListener, SF::TcpSocket, SF::UdpSocket

Included Modules

Direct Known Subclasses

Defined in:

network/obj.cr

Constant Summary

AnyPort = 0

Special value that tells the system to pick any available port

Instance Method Summary

Instance Method Detail

def blocking=(blocking : Bool) #

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.

  • blocking - True to set the socket as blocking, false for non-blocking

See also: #blocking?


[View source]
def blocking? : Bool #

Tell whether the socket is in blocking or non-blocking mode

Returns: True if the socket is blocking, false otherwise

See also: #blocking=


[View source]
def finalize #

Destructor


[View source]