QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
socketbase.h File Reference

Socket function definitions. More...

#include "common.h"
#include "intutils.h"
#include "ipinfo.h"
#include "memutils.h"
#include "socket.h"

Go to the source code of this file.

Data Structures

struct  qsc_socket_receive_async_state
 The socket async receive state structure. The structure contains pointers to the originating socket, message and error call-backs, and the message buffer. More...
 
struct  qsc_socket_receive_poll_state
 The socket polling state structure. The structure contains an array of client sockets, and a socket counter with sockets that are ready to receive data. More...
 

Macros

#define QSC_SOCKET_RECEIVE_BUFFER_SIZE   1600ULL
 The socket receive buffer size.
 

Enumerations

enum  qsc_socket_exceptions {
  qsc_socket_exception_success = 0 , qsc_socket_exception_error = -1 , qsc_socket_invalid_input = -2 , qsc_socket_exception_address_in_use = EADDRINUSE ,
  qsc_socket_exception_address_required = EDESTADDRREQ , qsc_socket_exception_address_unsupported = EAFNOSUPPORT , qsc_socket_exception_already_in_use = EISCONN , qsc_socket_exception_blocking_cancelled = EINTR ,
  qsc_socket_exception_blocking_in_progress = EINPROGRESS , qsc_socket_exception_broadcast_address = EACCES , qsc_socket_exception_buffer_fault = EFAULT , qsc_socket_exception_circuit_terminated = ECONNABORTED ,
  qsc_socket_exception_circuit_reset = ECONNRESET , qsc_socket_exception_circuit_timeout = ETIMEDOUT , qsc_socket_exception_connection_refused = ECONNREFUSED , qsc_socket_exception_descriptor_not_socket = ENOTSOCK ,
  qsc_socket_exception_disk_quota_exceeded = EDQUOT , qsc_socket_exception_dropped_connection = ENETRESET , qsc_socket_exception_family_unsupported = EPFNOSUPPORT , qsc_socket_exception_host_is_down = EHOSTDOWN ,
  qsc_socket_exception_host_unreachable = EHOSTUNREACH , qsc_socket_exception_in_progress = EALREADY , qsc_socket_exception_invalid_address = EADDRNOTAVAIL , qsc_socket_exception_invalid_protocol = EPROTOTYPE ,
  qsc_socket_exception_invalid_protocol_option = ENOPROTOOPT , qsc_socket_exception_item_is_remote = EREMOTE , qsc_socket_exception_message_too_long = EMSGSIZE , qsc_socket_exception_name_too_long = ENAMETOOLONG ,
  qsc_socket_exception_network_failure = ENETDOWN , qsc_socket_exception_network_unreachable = ENETUNREACH , qsc_socket_exception_no_buffer_space = ENOBUFS , qsc_socket_exception_no_descriptors = EMFILE ,
  qsc_socket_exception_not_bound = EINVAL , qsc_socket_exception_not_connected = ENOTCONN , qsc_socket_exception_operation_unsupported = EOPNOTSUPP , qsc_socket_exception_protocol_unsupported = EPROTONOSUPPORT ,
  qsc_socket_exception_socket_unsupported = ESOCKTNOSUPPORT , qsc_socket_exception_shut_down = ESHUTDOWN , qsc_socket_exception_system_not_ready = ETXTBSY , qsc_socket_exception_too_many_users = EUSERS ,
  qsc_socket_exception_translation_failed = ELOOP , qsc_socket_exception_would_block = EWOULDBLOCK
}
 Socket code enumeration names. More...
 

Functions

QSC_EXPORT_API bool qsc_socket_ipv4_valid_address (const char *address)
 The socket exception callback prototype.
 
QSC_EXPORT_API bool qsc_socket_ipv6_valid_address (const char *address)
 Detects if the string contains a valid IPV6 address.
 
QSC_EXPORT_API bool qsc_socket_is_blocking (const qsc_socket *sock)
 Determines if the socket is in blocking mode.
 
QSC_EXPORT_API bool qsc_socket_is_connected (const qsc_socket *sock)
 Determines if the socket is connected.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_accept (const qsc_socket *source, qsc_socket *target)
 The Accept function handles an incoming connection attempt on the socket.
 
QSC_EXPORT_API void qsc_socket_attach (qsc_socket *source, qsc_socket *target)
 Copy a socket to the target socket.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_bind (qsc_socket *sock, const char *address, uint16_t port)
 The Bind function associates an IP address with a socket.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_bind_ipv4 (qsc_socket *sock, const qsc_ipinfo_ipv4_address *address, uint16_t port)
 The Bind function associates an IPv4 address with a socket.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_bind_ipv6 (qsc_socket *sock, const qsc_ipinfo_ipv6_address *address, uint16_t port)
 The Bind function associates an IPv6 address with a socket.
 
QSC_EXPORT_API void qsc_socket_clear_socket (qsc_socket *sock)
 Erases the socket struture.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_close_socket (qsc_socket *sock)
 Closes and disposes of the socket.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_connect (qsc_socket *sock, const char *address, uint16_t port)
 The Connect function establishes a connection to a remote host.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_connect_ipv4 (qsc_socket *sock, const qsc_ipinfo_ipv4_address *address, uint16_t port)
 The Connect function establishes a connection to a remote host using IPv4 addressing.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_connect_ipv6 (qsc_socket *sock, const qsc_ipinfo_ipv6_address *address, uint16_t port)
 The Connect function establishes a connection to a remote host using IPv6 addressing.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_create (qsc_socket *sock, qsc_socket_address_families family, qsc_socket_transports transport, qsc_socket_protocols protocol)
 The Create function creates a socket that is bound to a specific transport provider.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_listen (const qsc_socket *sock, int32_t backlog)
 Places the socket in the listening state, waiting for a connection.
 
QSC_EXPORT_API size_t qsc_socket_max_send_buffer_size (const qsc_socket *sock)
 Get the maximum send buffer size for a socket.
 
QSC_EXPORT_API size_t qsc_socket_peek (const qsc_socket *sock, uint8_t *output, size_t otplen)
 Receive data from a synchronous connected socket or a bound connection-less socket without downloading the entire message.
 
QSC_EXPORT_API size_t qsc_socket_receive (const qsc_socket *sock, uint8_t *output, size_t otplen, qsc_socket_receive_flags flag)
 Receive data from a synchronous connected socket or a bound connection-less socket. Note: the receive buffer must be at least 1 byte larger than the expected size to accomodate a packet terminator. When calling receive with the wait-all flag, the receiver must include the terminator to empty the buffer.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_receive_async (qsc_socket_receive_async_state *state)
 Receive data from a connected socket asynchronously.
 
QSC_EXPORT_API size_t qsc_socket_receive_all (const qsc_socket *sock, uint8_t *output, size_t otplen, qsc_socket_receive_flags flag)
 Receive a block of data from a synchronous connected socket or a bound connection-less socket, and returns when buffer is full.
 
QSC_EXPORT_API size_t qsc_socket_receive_from (qsc_socket *sock, char *dest, uint16_t port, uint8_t *output, size_t otplen, qsc_socket_receive_flags flag)
 Receive data from a synchronous connected socket or a bound connection-less socket.
 
QSC_EXPORT_API uint32_t qsc_socket_receive_poll (const qsc_socket_receive_poll_state *state)
 Polls an array of sockets. Fires a callback if a socket is ready to receive data, or an error if socket is disconnected.
 
QSC_EXPORT_API size_t qsc_socket_send (const qsc_socket *sock, const uint8_t *input, size_t inplen, qsc_socket_send_flags flag)
 Sends data on a TCP connected socket. Note: The input buffer must be at least 1 byte longer than the input length. The send function terminates the packet with a null character for simplified string termination.
 
QSC_EXPORT_API size_t qsc_socket_send_to (const qsc_socket *sock, const uint8_t *input, size_t inplen, qsc_socket_send_flags flag)
 Sends data on a UDP socket.
 
QSC_EXPORT_API size_t qsc_socket_send_all (const qsc_socket *sock, const uint8_t *input, size_t inplen, qsc_socket_send_flags flag)
 Sends a block of data larger than a single packet size, on a TCP socket and returns when sent.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_shut_down (qsc_socket *sock, qsc_socket_shut_down_flags params)
 Shuts down a socket.
 
QSC_EXPORT_API const char * qsc_socket_error_to_string (qsc_socket_exceptions code)
 Returns the error string associated with the exception code.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_get_last_error (void)
 The last error generated by the internal socket library.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_ioctl (const qsc_socket *sock, int32_t command, uint32_t *arguments)
 Sets the IO mode of the socket.
 
QSC_EXPORT_API bool qsc_socket_receive_ready (const qsc_socket *sock, const struct timeval *timeout)
 Tests the socket to see if it is ready to receive data.
 
QSC_EXPORT_API bool qsc_socket_send_ready (const qsc_socket *sock, const struct timeval *timeout)
 Tests the socket to see if it is ready to send data.
 
QSC_EXPORT_API void qsc_socket_set_last_error (qsc_socket_exceptions error)
 Set the last error generated by the socket library.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_shut_down_sockets (void)
 Shut down the sockets library.
 
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_set_option (const qsc_socket *sock, qsc_socket_protocols level, qsc_socket_options option, int32_t optval)
 Send an option command to the socket. Options that use a boolean are format: 0=false, 1=true.
 
QSC_EXPORT_API bool qsc_socket_start_sockets (void)
 Start the sockets library.
 

Detailed Description

Socket function definitions.

This header provides the fundamental function definitions, enums, and structures for socket-based networking. It abstracts the underlying system-specific implementations for network socket operations, enabling a unified interface for both Windows and POSIX systems. The API supports the creation, configuration, and management of sockets for TCP/IP communication, including both IPv4 and IPv6. Functions provided in this module handle tasks such as opening, closing, binding, and listening on sockets, as well as setting various socket options and error handling.

Reference Links:

Enumeration Type Documentation

◆ qsc_socket_exceptions

Socket code enumeration names.

Enumerator
qsc_socket_exception_success 

The operation completed successfully

qsc_socket_exception_error 

The operation has failed

qsc_socket_invalid_input 

The input parameters are incorrect

qsc_socket_exception_address_in_use 

address already in use

qsc_socket_exception_address_required 

Destination address required

qsc_socket_exception_address_unsupported 

The address family is not supported

qsc_socket_exception_already_in_use 

qsc_socket is already connected

qsc_socket_exception_blocking_cancelled 

A blocking call was canceled

qsc_socket_exception_blocking_in_progress 

A blocking sockets call is in progress, or the service provider is still processing a callback function

qsc_socket_exception_broadcast_address 

The requested address is a broadcast address, but the appropriate flag was not set

qsc_socket_exception_buffer_fault 

The buffer parameter is not completely contained in a valid part of the user address space

qsc_socket_exception_circuit_terminated 

Software caused connection abort

qsc_socket_exception_circuit_reset 

connection reset by peer

qsc_socket_exception_circuit_timeout 

connection timed out

qsc_socket_exception_connection_refused 

connection refused

qsc_socket_exception_descriptor_not_socket 

qsc_socket operation on non-socket

qsc_socket_exception_disk_quota_exceeded 

The disk quota is exceeded

qsc_socket_exception_dropped_connection 

Network dropped connection on reset

qsc_socket_exception_family_unsupported 

Protocol family not supported

qsc_socket_exception_host_is_down 

The destination host is down

qsc_socket_exception_host_unreachable 

The remote host cannot be reached from this host at this time

qsc_socket_exception_in_progress 

Operation already in progress

qsc_socket_exception_invalid_address 

Can't assign requested address

qsc_socket_exception_invalid_protocol 

Protocol wrong type for socket

qsc_socket_exception_invalid_protocol_option 

Protocol not available

qsc_socket_exception_item_is_remote 

The item is not available locally

qsc_socket_exception_message_too_long 

The message size is too long

qsc_socket_exception_name_too_long 

The name is too long

qsc_socket_exception_network_failure 

Network is down

qsc_socket_exception_network_unreachable 

Network is unreachable

qsc_socket_exception_no_buffer_space 

No buffer space available

qsc_socket_exception_no_descriptors 

No more socket descriptors are available

qsc_socket_exception_not_bound 

The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled

qsc_socket_exception_not_connected 

qsc_socket is not connected

qsc_socket_exception_operation_unsupported 

The socket operation is not supported

qsc_socket_exception_protocol_unsupported 

Protocol not supported

qsc_socket_exception_socket_unsupported 

qsc_socket type not supported

qsc_socket_exception_shut_down 

Can't send after socket shutdown

qsc_socket_exception_system_not_ready 

The subsystem is unavailable

qsc_socket_exception_too_many_users 

The user quota is exceeded

qsc_socket_exception_translation_failed 

Can not translate name

qsc_socket_exception_would_block 

Operation would block

Function Documentation

◆ qsc_socket_accept()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_accept ( const qsc_socket * source,
qsc_socket * target )

The Accept function handles an incoming connection attempt on the socket.

Parameters
source[const qsc_socket*] The source listening socket instance
target[const qsc_socket*] The socket receiving the new socket
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_attach()

QSC_EXPORT_API void qsc_socket_attach ( qsc_socket * source,
qsc_socket * target )

Copy a socket to the target socket.

Parameters
source[qsc_socket*] The source socket instance
target[qsc_socket*] The socket to attach

◆ qsc_socket_bind()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_bind ( qsc_socket * sock,
const char * address,
uint16_t port )

The Bind function associates an IP address with a socket.

Parameters
sock[qsc_socket*] The socket instance
address[const char*] The IP address to bind to the socket
port[uint16_t] The service port number
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_bind_ipv4()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_bind_ipv4 ( qsc_socket * sock,
const qsc_ipinfo_ipv4_address * address,
uint16_t port )

The Bind function associates an IPv4 address with a socket.

Parameters
sock[qsc_socket*] The socket instance
address[const qsc_ipinfo_ipv4_address*] The IPv4 address to bind to the socket
port[uint16_t] The service port number
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_bind_ipv6()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_bind_ipv6 ( qsc_socket * sock,
const qsc_ipinfo_ipv6_address * address,
uint16_t port )

The Bind function associates an IPv6 address with a socket.

Parameters
sock[qsc_socket*] The socket instance
address[const qsc_ipinfo_ipv6_address*] The IPv6 address to bind to the socket
port[uint16_t] The service port number
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_clear_socket()

QSC_EXPORT_API void qsc_socket_clear_socket ( qsc_socket * sock)

Erases the socket struture.

Parameters
sock[qsc_socket*] The socket instance

◆ qsc_socket_close_socket()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_close_socket ( qsc_socket * sock)

Closes and disposes of the socket.

Parameters
sock[qsc_socket*] The socket instance
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_connect()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_connect ( qsc_socket * sock,
const char * address,
uint16_t port )

The Connect function establishes a connection to a remote host.

Parameters
sock[qsc_socket*] The socket instance
address[const char*] The remote hosts IP address
port[uint16_t] The remote hosts service port number
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_connect_ipv4()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_connect_ipv4 ( qsc_socket * sock,
const qsc_ipinfo_ipv4_address * address,
uint16_t port )

The Connect function establishes a connection to a remote host using IPv4 addressing.

Parameters
sock[qsc_socket*] The socket instance
address[const qsc_ipinfo_ipv4_address*] The remote hosts IPv4 address
port[uint16_t] The remote hosts service port number
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_connect_ipv6()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_connect_ipv6 ( qsc_socket * sock,
const qsc_ipinfo_ipv6_address * address,
uint16_t port )

The Connect function establishes a connection to a remote host using IPv6 addressing.

Parameters
sock[qsc_socket*] The socket instance
address[const] The remote hosts IPv6 address
port[const qsc_ipinfo_ipv6_address*] The remote hosts service port number
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_create()

The Create function creates a socket that is bound to a specific transport provider.

Parameters
sock[qsc_socket*] The socket instance
family[qsc_socket_address_families] The address family
transport[qsc_socket_transports] The transport layer
protocol[qsc_socket_protocols] The socket protocol
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_error_to_string()

QSC_EXPORT_API const char * qsc_socket_error_to_string ( qsc_socket_exceptions code)

Returns the error string associated with the exception code.

Parameters
code[qsc_socket_exceptions] The exception code
Returns
[const char*] Returns the error string

◆ qsc_socket_get_last_error()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_get_last_error ( void )

The last error generated by the internal socket library.

Returns
[qsc_socket_exceptions] Returns the last exception code

◆ qsc_socket_ioctl()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_ioctl ( const qsc_socket * sock,
int32_t command,
uint32_t * arguments )

Sets the IO mode of the socket.

Parameters
sock[const qsc_socket*] [const] The socket instance
command[int32_t] The command to pass to the socket
arguments[uint32_t*] The command arguments
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_ipv4_valid_address()

QSC_EXPORT_API bool qsc_socket_ipv4_valid_address ( const char * address)

The socket exception callback prototype.

Parameters
source[qsc_socket*] The socket source
error[qsc_socket_exceptions] The socket exception

The socket receive asynchronous callback prototype

Parameters
source[qsc_socket*] The socket source
message[const uint8_t*] The socket message buffer
msglen[size_t*] A pointer to the size of the message

The receive polling callback prototype

Parameters
source[const qsc_socket*] The socket source
error[size_t] The socket exception

Detects if the string contains a valid IPV4 address

Parameters
address[const char*] The IP address string
Returns
[bool] Returns true if the address is a valid IPV4 address

◆ qsc_socket_ipv6_valid_address()

QSC_EXPORT_API bool qsc_socket_ipv6_valid_address ( const char * address)

Detects if the string contains a valid IPV6 address.

Parameters
address[const char*] The IP address string
Returns
[bool] Returns true if the address is a valid IPV6 address

◆ qsc_socket_is_blocking()

QSC_EXPORT_API bool qsc_socket_is_blocking ( const qsc_socket * sock)

Determines if the socket is in blocking mode.

Parameters
sock[const qsc_socket*] The socket instance
Returns
[bool] Returns true if the socket is blocking

◆ qsc_socket_is_connected()

QSC_EXPORT_API bool qsc_socket_is_connected ( const qsc_socket * sock)

Determines if the socket is connected.

Parameters
sock[const qsc_socket*] The socket instance
Returns
[bool] Returns true if the socket is connected

◆ qsc_socket_listen()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_listen ( const qsc_socket * sock,
int32_t backlog )

Places the socket in the listening state, waiting for a connection.

Parameters
sock[const qsc_socket*] The socket instance
backlog[int32_t] The maximum pending connections queue length
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_max_send_buffer_size()

QSC_EXPORT_API size_t qsc_socket_max_send_buffer_size ( const qsc_socket * sock)

Get the maximum send buffer size for a socket.

Parameters
sock[const qsc_socket*] The socket instance
Returns
[size_t] Returns the maximum length of a send buffer

◆ qsc_socket_peek()

QSC_EXPORT_API size_t qsc_socket_peek ( const qsc_socket * sock,
uint8_t * output,
size_t otplen )

Receive data from a synchronous connected socket or a bound connection-less socket without downloading the entire message.

Parameters
sock[const qsc_socket*] The socket instance
output[uint8_t*] The output buffer that receives data
otplen[size_t] The length of the output received
Returns
[size_t] Returns the number of bytes received from the remote host

◆ qsc_socket_receive()

QSC_EXPORT_API size_t qsc_socket_receive ( const qsc_socket * sock,
uint8_t * output,
size_t otplen,
qsc_socket_receive_flags flag )

Receive data from a synchronous connected socket or a bound connection-less socket. Note: the receive buffer must be at least 1 byte larger than the expected size to accomodate a packet terminator. When calling receive with the wait-all flag, the receiver must include the terminator to empty the buffer.

Parameters
sock[const qsc_socket*] The socket instance
output[uint8_t*] The output buffer that receives data
otplen[size_t] The length of the output received
flag[qsc_socket_receive_flags] Flags that influence the behavior of the receive function
Returns
[size_t] Returns the number of bytes received from the remote host

◆ qsc_socket_receive_all()

QSC_EXPORT_API size_t qsc_socket_receive_all ( const qsc_socket * sock,
uint8_t * output,
size_t otplen,
qsc_socket_receive_flags flag )

Receive a block of data from a synchronous connected socket or a bound connection-less socket, and returns when buffer is full.

Parameters
sock[const qsc_socket*] The socket instance
output[uint8_t*] The output buffer that receives data
otplen[size_t] The length of the output received
flag[qsc_socket_receive_flags] Flags that influence the behavior of the receive function
Returns
[size_t] Returns the number of bytes received from the remote host

◆ qsc_socket_receive_async()

Receive data from a connected socket asynchronously.

Parameters
state[qsc_socket_receive_async_state*] A pointer to the async receive data structure
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_receive_from()

QSC_EXPORT_API size_t qsc_socket_receive_from ( qsc_socket * sock,
char * dest,
uint16_t port,
uint8_t * output,
size_t otplen,
qsc_socket_receive_flags flag )

Receive data from a synchronous connected socket or a bound connection-less socket.

Parameters
sock[qsc_socket*] The local socket
dest[char*] The destination IP address string
port[uint16_t] The port receiving the data
output[uint8_t*] The output buffer
otplen[size_t] The length of the output buffer
flag[qsc_socket_receive_flags] Flags that influence the behavior of the receive from function
Returns
[size_t] Returns the number of bytes received from the remote host

◆ qsc_socket_receive_poll()

QSC_EXPORT_API uint32_t qsc_socket_receive_poll ( const qsc_socket_receive_poll_state * state)

Polls an array of sockets. Fires a callback if a socket is ready to receive data, or an error if socket is disconnected.

Parameters
state[const qsc_socket_receive_poll_state*] The server state, containing a pointer to an array of sockets
Returns
[uint32_t] Returns the number of sockets with data

◆ qsc_socket_receive_ready()

QSC_EXPORT_API bool qsc_socket_receive_ready ( const qsc_socket * sock,
const struct timeval * timeout )

Tests the socket to see if it is ready to receive data.

Parameters
sock[const qsc_socket*] The socket instance
timeout[const struct timeval*] The receive wait timeout
Returns
[bool] Returns true if the socket is ready to receive data

◆ qsc_socket_send()

QSC_EXPORT_API size_t qsc_socket_send ( const qsc_socket * sock,
const uint8_t * input,
size_t inplen,
qsc_socket_send_flags flag )

Sends data on a TCP connected socket. Note: The input buffer must be at least 1 byte longer than the input length. The send function terminates the packet with a null character for simplified string termination.

Parameters
sock[const qsc_socket*] The socket instance
input[const uint8_t*] The input buffer containing the data to be transmitted
inplen[size_t] The number of bytes to send
flag[qsc_socket_send_flags] Flags that influence the behavior of the send function
Returns
[size_t] Returns the number of bytes sent to the remote host

◆ qsc_socket_send_all()

QSC_EXPORT_API size_t qsc_socket_send_all ( const qsc_socket * sock,
const uint8_t * input,
size_t inplen,
qsc_socket_send_flags flag )

Sends a block of data larger than a single packet size, on a TCP socket and returns when sent.

Parameters
sock[const qsc_socket*] The socket instance
input[const uint8_t*] The input buffer containing the data to be transmitted
inplen[size_t] The number of bytes to send
flag[qsc_socket_send_flags] Flags that influence the behavior of the send function
Returns
[size_t] Returns the number of bytes sent to the remote host

◆ qsc_socket_send_ready()

QSC_EXPORT_API bool qsc_socket_send_ready ( const qsc_socket * sock,
const struct timeval * timeout )

Tests the socket to see if it is ready to send data.

Parameters
sock[const qsc_socket*] The socket instance
timeout[const struct timeval*] The maximum time to wait for a response from the socket
Returns
[bool] Returns true if the socket is ready to send data

◆ qsc_socket_send_to()

QSC_EXPORT_API size_t qsc_socket_send_to ( const qsc_socket * sock,
const uint8_t * input,
size_t inplen,
qsc_socket_send_flags flag )

Sends data on a UDP socket.

Parameters
sock[const qsc_socket*] The socket instance
input[const uint8_t*] The input buffer containing the data to be transmitted
inplen[size_t] The number of bytes to send
flag[qsc_socket_send_flags] Flags that influence the behavior of the send function
Returns
[size_t] Returns the number of bytes sent to the remote host

◆ qsc_socket_set_last_error()

QSC_EXPORT_API void qsc_socket_set_last_error ( qsc_socket_exceptions error)

Set the last error generated by the socket library.

Parameters
error[qsc_socket_exceptions] The error code

◆ qsc_socket_set_option()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_set_option ( const qsc_socket * sock,
qsc_socket_protocols level,
qsc_socket_options option,
int32_t optval )

Send an option command to the socket. Options that use a boolean are format: 0=false, 1=true.

Parameters
sock[const qsc_socket*] The socket instance
level[qsc_socket_protocols] The level at which the option is assigned
option[qsc_socket_options] The option command to send
optval[int32_t] The value of the option command
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_shut_down()

Shuts down a socket.

Parameters
sock[qsc_socket*] The socket instance
params[qsc_socket_shut_down_flags] The shutdown parameters
Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_shut_down_sockets()

QSC_EXPORT_API qsc_socket_exceptions qsc_socket_shut_down_sockets ( void )

Shut down the sockets library.

Returns
[qsc_socket_exceptions] Returns an exception code on failure, or success(0)

◆ qsc_socket_start_sockets()

QSC_EXPORT_API bool qsc_socket_start_sockets ( void )

Start the sockets library.

Returns
[bool] Returns true on success