52#ifndef QSC_SOCKETBASE_H
53#define QSC_SOCKETBASE_H
61QSC_CPLUSPLUS_ENABLED_START
83#if defined(QSC_SYSTEM_OS_WINDOWS)
85#elif defined(QSC_SYSTEM_OS_POSIX)
86# include <sys/select.h>
103#define QSC_SOCKET_RECEIVE_BUFFER_SIZE 1600U
109#define QSC_SOCKET_DEFAULT_SNDBUF_SIZE 65536U
119#if defined(QSC_SYSTEM_OS_WINDOWS)
140 qsc_socket_exception_invalid_parameter = WSA_INVALID_PARAMETER,
143 qsc_socket_exception_invalid_provider = WSAEINVALIDPROVIDER,
151 qsc_socket_exception_no_memory = WSA_NOT_ENOUGH_MEMORY,
154 qsc_socket_exception_not_initialized = WSANOTINITIALISED,
160 qsc_socket_exception_too_many_processes = WSAEPROCLIM,
214extern const char QSC_SOCKET_ERROR_STRINGS[48][128];
637QSC_CPLUSPLUS_ENABLED_END
This file contains common integer manipulation and conversion functions.
IP information function definitions.
Contains common memory-related functions implemented using SIMD instructions.
Contains common definitions for the Quantum Secure Cryptographic (QSC) library.
#define QSC_EXPORT_API
API export macro for Microsoft compilers when importing from a DLL.
Definition qsccommon.h:605
#define QSC_SYSTEM_CONDITION_IGNORE(x)
A macro to disable a specific warning condition.
Definition qsccommon.h:851
TCP/IP function constants and structures.
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....
Definition socketbase.c:706
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.
Definition socketbase.c:1288
QSC_EXPORT_API bool qsc_socket_start_sockets(void)
Start the sockets library.
Definition socketbase.c:1415
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.
Definition socketbase.c:315
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.
Definition socketbase.c:530
QSC_EXPORT_API void qsc_socket_clear_socket(qsc_socket *sock)
Erases the socket struture.
Definition socketbase.c:455
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.
Definition socketbase.c:1343
qsc_socket_exceptions
Socket code enumeration names.
Definition socketbase.h:115
@ qsc_socket_exception_would_block
Definition socketbase.h:206
@ qsc_socket_exception_broadcast_address
Definition socketbase.h:171
@ qsc_socket_exception_socket_unsupported
Definition socketbase.h:200
@ qsc_socket_exception_circuit_terminated
Definition socketbase.h:173
@ qsc_socket_exception_buffer_fault
Definition socketbase.h:172
@ qsc_socket_exception_message_too_long
Definition socketbase.h:190
@ qsc_socket_exception_address_unsupported
Definition socketbase.h:167
@ qsc_socket_exception_invalid_protocol_option
Definition socketbase.h:187
@ qsc_socket_exception_address_required
Definition socketbase.h:166
@ qsc_socket_exception_already_in_use
Definition socketbase.h:168
@ qsc_socket_exception_blocking_in_progress
Definition socketbase.h:170
@ qsc_socket_exception_no_descriptors
Definition socketbase.h:195
@ qsc_socket_exception_host_is_down
Definition socketbase.h:181
@ qsc_socket_exception_connection_refused
Definition socketbase.h:176
@ qsc_socket_exception_operation_unsupported
Definition socketbase.h:198
@ qsc_socket_exception_shut_down
Definition socketbase.h:201
@ qsc_socket_exception_disk_quota_exceeded
Definition socketbase.h:178
@ qsc_socket_exception_item_is_remote
Definition socketbase.h:189
@ qsc_socket_exception_circuit_timeout
Definition socketbase.h:175
@ qsc_socket_invalid_input
Definition socketbase.h:118
@ qsc_socket_exception_name_too_long
Definition socketbase.h:191
@ qsc_socket_exception_host_unreachable
Definition socketbase.h:182
@ qsc_socket_exception_dropped_connection
Definition socketbase.h:179
@ qsc_socket_exception_invalid_address
Definition socketbase.h:184
@ qsc_socket_exception_system_not_ready
Definition socketbase.h:202
@ qsc_socket_exception_not_connected
Definition socketbase.h:197
@ qsc_socket_exception_error
Definition socketbase.h:117
@ qsc_socket_exception_not_bound
Definition socketbase.h:196
@ qsc_socket_exception_success
Definition socketbase.h:116
@ qsc_socket_exception_too_many_users
Definition socketbase.h:204
@ qsc_socket_exception_family_unsupported
Definition socketbase.h:180
@ qsc_socket_exception_blocking_cancelled
Definition socketbase.h:169
@ qsc_socket_exception_circuit_reset
Definition socketbase.h:174
@ qsc_socket_exception_protocol_unsupported
Definition socketbase.h:199
@ qsc_socket_exception_invalid_protocol
Definition socketbase.h:186
@ qsc_socket_exception_descriptor_not_socket
Definition socketbase.h:177
@ qsc_socket_exception_address_in_use
Definition socketbase.h:165
@ qsc_socket_exception_network_failure
Definition socketbase.h:192
@ qsc_socket_exception_no_buffer_space
Definition socketbase.h:194
@ qsc_socket_exception_in_progress
Definition socketbase.h:183
@ qsc_socket_exception_translation_failed
Definition socketbase.h:205
@ qsc_socket_exception_network_unreachable
Definition socketbase.h:193
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.
Definition socketbase.c:421
#define QSC_SOCKET_RECEIVE_BUFFER_SIZE
The socket receive buffer size.
Definition socketbase.h:103
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.
Definition socketbase.c:380
QSC_EXPORT_API void qsc_socket_attach(qsc_socket *source, qsc_socket *target)
Copy a socket to the target socket.
Definition socketbase.c:344
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.
Definition socketbase.c:606
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,...
Definition socketbase.c:799
QSC_EXPORT_API void qsc_socket_set_last_error(qsc_socket_exceptions error)
Set the last error generated by the socket library.
Definition socketbase.c:1372
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.
Definition socketbase.c:637
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 sock...
Definition socketbase.c:769
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.
Definition socketbase.c:500
QSC_EXPORT_API bool qsc_socket_is_blocking(const qsc_socket *sock)
Determines if the socket is in blocking mode.
Definition socketbase.c:219
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.
Definition socketbase.c:568
QSC_EXPORT_API size_t qsc_socket_max_send_buffer_size(const qsc_socket *sock)
Get the maximum send buffer size for a socket.
Definition socketbase.c:658
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_close_socket(qsc_socket *sock)
Closes and disposes of the socket.
Definition socketbase.c:472
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.
Definition socketbase.c:976
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.
Definition socketbase.c:354
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_shut_down(qsc_socket *sock, qsc_socket_shut_down_flags params)
Shuts down a socket.
Definition socketbase.c:1008
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.
Definition socketbase.c:1314
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 downloadin...
Definition socketbase.c:686
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_shut_down_sockets(void)
Shut down the sockets library.
Definition socketbase.c:1381
QSC_EXPORT_API bool qsc_socket_ipv4_valid_address(const char *address)
The socket exception callback prototype.
Definition socketbase.c:185
QSC_EXPORT_API const char * qsc_socket_error_to_string(qsc_socket_exceptions code)
Returns the error string associated with the exception code.
Definition socketbase.c:1034
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_receive_async(qsc_socket_receive_async_state *state)
Receive data from a connected socket asynchronously.
Definition socketbase.c:750
QSC_EXPORT_API bool qsc_socket_is_connected(const qsc_socket *sock)
Determines if the socket is connected.
Definition socketbase.c:241
QSC_EXPORT_API size_t qsc_socket_receive_from(qsc_socket *sock, char *dest, size_t destlen, 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.
Definition socketbase.c:831
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 ...
Definition socketbase.c:917
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.
Definition socketbase.c:937
QSC_EXPORT_API qsc_socket_exceptions qsc_socket_get_last_error(void)
The last error generated by the internal socket library.
Definition socketbase.c:1275
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,...
Definition socketbase.c:1394
QSC_EXPORT_API bool qsc_socket_ipv6_valid_address(const char *address)
Detects if the string contains a valid IPV6 address.
Definition socketbase.c:202
qsc_socket_options
TCP socket options.
Definition socketflags.h:112
qsc_socket_transports
The socket transmission type.
Definition socketflags.h:203
qsc_socket_shut_down_flags
The socket shutdown api flags.
Definition socketflags.h:193
qsc_socket_address_families
The socket address family type.
Definition socketflags.h:80
qsc_socket_receive_flags
The socket receive api flags.
Definition socketflags.h:165
qsc_socket_send_flags
The socket send api flags.
Definition socketflags.h:182
qsc_socket_protocols
The socket IP protocol type.
Definition socketflags.h:142
The IPv4 address structure.
Definition ipinfo.h:161
The IPv6 address structure.
Definition ipinfo.h:320
The socket async receive state structure. The structure contains pointers to the originating socket,...
Definition socketbase.h:222
void(* callback)(qsc_socket *sock, const uint8_t *message, size_t *msglen)
Definition socketbase.h:223
void(* error)(const qsc_socket *sock, qsc_socket_exceptions exception)
Definition socketbase.h:224
uint8_t buffer[QSC_SOCKET_RECEIVE_BUFFER_SIZE]
Definition socketbase.h:226
qsc_socket * source
Definition socketbase.h:225
The socket polling state structure. The structure contains an array of client sockets,...
Definition socketbase.h:235
uint32_t count
Definition socketbase.h:239
void(* error)(qsc_socket *sock, qsc_socket_exceptions exception)
Definition socketbase.h:238
qsc_socket ** sockarr
Definition socketbase.h:236
void(* callback)(qsc_socket *sock, size_t id)
Definition socketbase.h:237
The socket instance structure.
Definition socket.h:133