Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Common Protocol

Helpers to build and parse Yuneta’s “common protocol” — a small JSON-over-stream framing used between gobjs and yunos.

Source code:

comm_prot_free()

The comm_prot_free function releases all registered communication protocol mappings, freeing associated memory.

void comm_prot_free(void);

Parameters

KeyTypeDescription
--This function does not take any parameters.

Returns

This function does not return a value.

Notes

This function should be called to clean up the communication protocol registry before program termination.


comm_prot_get_gclass()

Retrieves the gclass name associated with a given communication protocol schema.

gclass_name_t comm_prot_get_gclass(
    const char *schema
);

Parameters

KeyTypeDescription
schemaconst char *The communication protocol schema to look up.

Returns

Returns the gclass name associated with the given schema. If the schema is not found, logs an error and returns NULL.

Notes

This function searches the registered communication protocols and returns the corresponding gclass name. If the schema is not found, an error is logged.


comm_prot_register()

Registers a gclass with a specified communication protocol schema, allowing it to be retrieved later by schema name.

int comm_prot_register(
    gclass_name_t gclass_name,
    const char *schema
);

Parameters

KeyTypeDescription
gclass_namegclass_name_tThe name of the gclass to be associated with the schema.
schemaconst char *The communication protocol schema to register with the gclass.

Returns

Returns 0 on success, or -1 if memory allocation fails.

Notes

The function initializes the internal communication protocol registry if it has not been initialized yet. The schema is stored as a dynamically allocated string, which will be freed when the registry is cleared.


get_peername()

Retrieves the remote socket address of a connected socket and formats it as a string.

int get_peername(
    char *bf,
    size_t bfsize,
    int fd
);

Parameters

KeyTypeDescription
bfchar *Buffer to receive the formatted address string.
bfsizesize_tSize of the buffer in bytes.
fdintFile descriptor of the connected socket.

Returns

Returns 0 on success, or -1 on error.


get_sockname()

Retrieves the local socket address of a socket and formats it as a string.

int get_sockname(
    char *bf,
    size_t bfsize,
    int fd
);

Parameters

KeyTypeDescription
bfchar *Buffer to receive the formatted address string.
bfsizesize_tSize of the buffer in bytes.
fdintFile descriptor of the socket.

Returns

Returns 0 on success, or -1 on error.


is_tcp_socket()

Determines if the given file descriptor represents a TCP (stream) socket.

BOOL is_tcp_socket(
    int fd
);

Parameters

KeyTypeDescription
fdintThe file descriptor to check.

Returns

Returns TRUE if the file descriptor is a TCP socket, FALSE otherwise.


is_udp_socket()

Determines if the given file descriptor represents a UDP (datagram) socket.

BOOL is_udp_socket(
    int fd
);

Parameters

KeyTypeDescription
fdintThe file descriptor to check.

Returns

Returns TRUE if the file descriptor is a UDP socket, FALSE otherwise.


Formats a socket address structure into a human-readable string.

int print_socket_address(
    char *buf,
    size_t buflen,
    const struct sockaddr *sa
);

Parameters

KeyTypeDescription
bufchar *Buffer to receive the formatted address string.
buflensize_tSize of the buffer in bytes.
saconst struct sockaddr *Pointer to the socket address structure to format.

Returns

Returns 0 on success, or -1 on error.

Notes

Supports both IPv4 and IPv6 address families.


set_tcp_socket_options()

Configures TCP socket options including TCP_NODELAY, SO_KEEPALIVE, and SO_LINGER.

int set_tcp_socket_options(
    int fd,
    int delay
);

Parameters

KeyTypeDescription
fdintThe TCP socket file descriptor to configure.
delayintKeep-alive idle timeout in seconds. Defaults to 60 if 0 is passed.

Returns

Returns the cumulative result of the setsockopt calls.