20 #include <citrusleaf/cf_clock.h>
24 #include <openssl/ssl.h>
28 #if defined(__linux__) || defined(__APPLE__)
30 #include <arpa/inet.h>
31 #include <netinet/in.h>
32 #include <sys/socket.h>
35 #define as_socket_data_t void
36 #define as_socket_size_t size_t
37 #define as_close(fd) (close(fd))
40 #if defined(__APPLE__)
41 #define SOL_TCP IPPROTO_TCP
42 #define MSG_NOSIGNAL 0
45 #if defined(CF_WINDOWS)
49 #define as_socket_data_t char
50 #define as_socket_size_t int
51 #define as_close(fd) (closesocket(fd))
53 #define MSG_DONTWAIT 0
54 #define MSG_NOSIGNAL 0
56 #define SHUT_RDWR SD_BOTH
59 #define AS_IP_ADDRESS_SIZE 64
69 typedef struct as_tls_context_s {
76 struct as_queue_lock_s;
82 typedef struct as_socket_s {
183 #if defined(__linux__) || defined(__APPLE__)
189 static inline uint64_t
190 as_socket_deadline(uint32_t timeout_ms)
192 return (timeout_ms && timeout_ms <= INT32_MAX)? cf_getms() + timeout_ms : 0;
200 as_socket_write_forever(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len);
208 as_socket_write_limit(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len, uint64_t deadline);
216 as_socket_write_deadline(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len, uint64_t deadline)
219 return as_socket_write_limit(err, sock, node, buf, buf_len, deadline);
222 return as_socket_write_forever(err, sock, node, buf, buf_len);
232 as_socket_write_timeout(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len, uint32_t timeout_ms)
234 if (timeout_ms && timeout_ms <= INT32_MAX) {
235 return as_socket_write_limit(err, sock, node, buf, buf_len, cf_getms() + timeout_ms);
238 return as_socket_write_forever(err, sock, node, buf, buf_len);
247 as_socket_read_forever(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len);
255 as_socket_read_limit(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len, uint64_t deadline);
263 as_socket_read_deadline(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len, uint64_t deadline)
266 return as_socket_read_limit(err, sock, node, buf, buf_len, deadline);
269 return as_socket_read_forever(err, sock, node, buf, buf_len);
279 as_socket_read_timeout(
as_error* err,
as_socket* sock,
struct as_node_s* node, uint8_t *buf,
size_t buf_len, uint32_t timeout_ms)
281 if (timeout_ms && timeout_ms <= INT32_MAX) {
282 return as_socket_read_limit(err, sock, node, buf, buf_len, cf_getms() + timeout_ms);
285 return as_socket_read_forever(err, sock, node, buf, buf_len);
as_status as_socket_error(int fd, struct as_node_s *node, as_error *err, as_status status, const char *msg, int code)
void as_socket_error_append(as_error *err, struct sockaddr *addr)
int as_socket_validate(as_socket *sock)
int as_socket_validate_fd(int fd)
struct as_queue_lock_s * queue
void as_socket_init(as_socket *sock)
void as_socket_close(as_socket *sock)
int as_socket_create_fd(int family)
bool as_socket_start_connect(as_socket *sock, struct sockaddr *addr)
int as_socket_create(as_socket *sock, int family, as_tls_context *ctx, const char *tls_name)
bool as_socket_wrap(as_socket *sock, int family, int fd, as_tls_context *ctx, const char *tls_name)
as_status as_socket_create_and_connect(as_socket *sock, as_error *err, struct sockaddr *addr, as_tls_context *ctx, const char *tls_name)