20 #include <citrusleaf/cf_clock.h>
24 #if defined(__linux__) || defined(__APPLE__)
26 #include <arpa/inet.h>
27 #include <netinet/in.h>
28 #include <sys/socket.h>
31 #define as_socket_data_t void
32 #define as_socket_size_t size_t
33 #define as_close(fd) (close(fd))
36 #if defined(__APPLE__)
37 #define SOL_TCP IPPROTO_TCP
38 #define MSG_NOSIGNAL 0
41 #if defined(CF_WINDOWS)
45 #define as_socket_data_t char
46 #define as_socket_size_t int
47 #define as_close(fd) (closesocket(fd))
49 #define MSG_DONTWAIT 0
50 #define MSG_NOSIGNAL 0
52 #define SHUT_RDWR SD_BOTH
91 #if defined(__linux__) || defined(__APPLE__)
97 static inline uint64_t
98 as_socket_deadline(uint32_t timeout_ms)
100 return (timeout_ms && timeout_ms <= INT32_MAX)? cf_getms() + timeout_ms : 0;
108 as_socket_write_forever(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len);
116 as_socket_write_limit(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len, uint64_t deadline);
124 as_socket_write_deadline(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len, uint64_t deadline)
127 return as_socket_write_limit(err, fd, buf, buf_len, deadline);
130 return as_socket_write_forever(err, fd, buf, buf_len);
140 as_socket_write_timeout(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len, uint32_t timeout_ms)
142 if (timeout_ms && timeout_ms <= INT32_MAX) {
143 return as_socket_write_limit(err, fd, buf, buf_len, cf_getms() + timeout_ms);
146 return as_socket_write_forever(err, fd, buf, buf_len);
155 as_socket_read_forever(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len);
163 as_socket_read_limit(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len, uint64_t deadline);
171 as_socket_read_deadline(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len, uint64_t deadline)
174 return as_socket_read_limit(err, fd, buf, buf_len, deadline);
177 return as_socket_read_forever(err, fd, buf, buf_len);
187 as_socket_read_timeout(
as_error* err,
int fd, uint8_t *buf,
size_t buf_len, uint32_t timeout_ms)
189 if (timeout_ms && timeout_ms <= INT32_MAX) {
190 return as_socket_read_limit(err, fd, buf, buf_len, cf_getms() + timeout_ms);
193 return as_socket_read_forever(err, fd, buf, buf_len);
202 as_socket_address_name(
struct sockaddr_in* address,
char* name)
204 inet_ntop(AF_INET, &(address->sin_addr), name, INET_ADDRSTRLEN);
int as_socket_validate(int fd)
as_status as_socket_start_connect_nb(as_error *err, int fd, struct sockaddr_in *sa)
as_status as_socket_create_and_connect_nb(as_error *err, struct sockaddr_in *sa, int *fd)
int as_socket_create_nb()