7#include <sys/syscall.h>
10#include <netinet/in.h>
26#error "tfcore_unix.h included on a non-Unix system"
33inline int tf_ppoll(
struct pollfd *fds, nfds_t nfds,
const struct timespec *ts)
39inline int tf_poll(
struct pollfd *fds, nfds_t nfds,
int timeout)
41 struct timespec ts = {timeout / 1000, (timeout % 1000) * 1000000L};
42 return tf_ppoll(fds, nfds, &ts);
46inline int tf_epoll_wait(
int epfd,
struct epoll_event *events,
47 int maxevents,
int timeout)
49 TF_EINTR_LOOP(::epoll_wait(epfd, events, maxevents, timeout));
53inline int tf_epoll_ctl(
int epfd,
int op,
int fd,
struct epoll_event *event)
59inline int tf_accept4(
int sockfd,
struct sockaddr *addr, socklen_t *addrlen,
int flags)
65inline int tf_connect(
int sockfd,
const struct sockaddr *addr, socklen_t addrlen)
71inline pid_t tf_gettid()
73 return syscall(SYS_gettid);
77inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
79 flags |= MSG_NOSIGNAL;
87inline int tf_poll(
struct pollfd *fds, nfds_t nfds,
int timeout)
93inline pid_t tf_gettid()
96 pthread_threadid_np(NULL, &tid);
101inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
110inline int tf_poll(
struct pollfd *fds, nfds_t nfds,
int timeout)
116inline pid_t tf_gettid()
118 std::ostringstream ss;
119 ss << std::this_thread::get_id();
120 return std::stoull(ss.str());
124inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
137inline int tf_close(
int fd)
143inline int tf_read(
int fd,
void *buf,
size_t count)
149inline int tf_write(
int fd,
const void *buf,
size_t count)
155inline int tf_recv(
int sockfd,
void *buf,
size_t len,
int flags = 0)
161inline int tf_close_socket(
int sockfd)
167inline int tf_dup(
int fd)
169 return ::fcntl(fd, F_DUPFD, 0);
173inline int tf_flock(
int fd,
int op)
179inline int tf_lockfile(
int fd,
bool exclusive,
bool blocking)
183 std::memset(&lck, 0,
sizeof(
struct flock));
184 lck.l_type = (exclusive) ? F_WRLCK : F_RDLCK;
185 lck.l_whence = SEEK_SET;
186 auto cmd = (blocking) ? F_SETLKW : F_SETLK;
191inline int tf_unlink(
const char *pathname)
193 return ::unlink(pathname);
197inline int tf_fileno(FILE *stream)
199 return ::fileno(stream);
206inline int tf_poll_recv(
int socket,
int timeout)
208 struct pollfd pfd = {socket, POLLIN, 0};
209 int ret = tf_poll(&pfd, 1, timeout);
217inline int tf_poll_send(
int socket,
int timeout)
219 struct pollfd pfd = {socket, POLLOUT, 0};
220 int ret = tf_poll(&pfd, 1, timeout);
#define TF_EAGAIN_LOOP(func)
Definition tfcore.h:20
#define TF_EINTR_LOOP(func)
Definition tfcore.h:12