ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
network.h
Go to the documentation of this file.
1
74
75#pragma once
76
78
79#include <libplatform/socket.h>
80#include "../tests/test_env.h"
81#include <sys/types.h>
82
83#ifdef __cplusplus
84extern "C" {
85#endif
86
95
104#define CONNECT_TIMEOUT 3
105
114#ifdef NDEBUG
115#define SEND_TIMEOUT 5
116#else
117#define SEND_TIMEOUT 1
118#endif
119
130#ifdef NDEBUG
131#define RECV_TIMEOUT 1
132#else
133#define RECV_TIMEOUT 1
134#endif
135
145#ifdef NDEBUG
146#define ACCEPT_TIMEOUT 3
147#else
148#define ACCEPT_TIMEOUT 1
149#endif
150
152
158
168#define network_is_test_environment() ((int)is_test_environment())
169
171
180
189#define KEEPALIVE_IDLE 60
190
198#define KEEPALIVE_INTERVAL 10
199
207#define KEEPALIVE_COUNT 8
208
210
216
236ssize_t send_with_timeout(socket_t sockfd, const void *data, size_t len, uint64_t timeout_ns);
237
257ssize_t recv_with_timeout(socket_t sockfd, void *buf, size_t len, uint64_t timeout_ns);
258
277int accept_with_timeout(socket_t listenfd, struct sockaddr *addr, socklen_t *addrlen, uint64_t timeout_ns);
278
297bool connect_with_timeout(socket_t sockfd, const struct sockaddr *addr, socklen_t addrlen, int timeout_seconds);
298
300
306
322
337
354
381
383
389
402const char *network_error_string();
403 /* Error Reporting Functions */
405 /* network */
407
408#ifdef __cplusplus
409}
410#endif
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
unsigned long long uint64_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
asciichat_error_t set_socket_timeout(socket_t sockfd, uint64_t timeout_ns)
Set socket timeout for send/receive operations.
asciichat_error_t set_socket_keepalive(socket_t sockfd)
Enable TCP keepalive on socket.
ssize_t recv_with_timeout(socket_t sockfd, void *buf, size_t len, uint64_t timeout_ns)
Receive data with timeout.
asciichat_error_t set_socket_nonblocking(socket_t sockfd)
Set socket to non-blocking mode.
bool connect_with_timeout(socket_t sockfd, const struct sockaddr *addr, socklen_t addrlen, int timeout_seconds)
Connect to server with timeout.
int accept_with_timeout(socket_t listenfd, struct sockaddr *addr, socklen_t *addrlen, uint64_t timeout_ns)
Accept connection with timeout.
ssize_t send_with_timeout(socket_t sockfd, const void *data, size_t len, uint64_t timeout_ns)
Send data with timeout using chunked transmission.
const char * network_error_string()
Get human-readable error string for network errors.
asciichat_error_t socket_configure_buffers(socket_t sockfd)
Configure socket buffers and TCP_NODELAY for optimal performance.
int socket_t
Test environment detection utilities.