6 #include <sys/socket.h>
7 #include <sys/syscall.h>
10 #include <netinet/in.h>
16 #include <sys/epoll.h>
26 #error "tfcore_unix.h included on a non-Unix system"
33 inline int tf_ppoll(
struct pollfd *fds, nfds_t nfds,
const struct timespec *ts)
39 inline 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);
46 inline 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));
53 inline int tf_epoll_ctl(
int epfd,
int op,
int fd,
struct epoll_event *event)
59 inline int tf_accept4(
int sockfd,
struct sockaddr *addr, socklen_t *addrlen,
int flags)
65 inline int tf_connect(
int sockfd,
const struct sockaddr *addr, socklen_t addrlen)
71 inline pid_t tf_gettid()
73 return syscall(SYS_gettid);
77 inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
79 flags |= MSG_NOSIGNAL;
87 inline int tf_poll(
struct pollfd *fds, nfds_t nfds,
int timeout)
93 inline pid_t tf_gettid()
96 pthread_threadid_np(NULL, &tid);
101 inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
110 inline int tf_poll(
struct pollfd *fds, nfds_t nfds,
int timeout)
116 inline pid_t tf_gettid()
118 std::ostringstream ss;
119 ss << std::this_thread::get_id();
120 return std::stoull(ss.str());
124 inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
137 inline int tf_close(
int fd)
143 inline int tf_read(
int fd,
void *buf,
size_t count)
149 inline int tf_write(
int fd,
const void *buf,
size_t count)
155 inline int tf_recv(
int sockfd,
void *buf,
size_t len,
int flags = 0)
161 inline int tf_close_socket(
int sockfd)
167 inline int tf_dup(
int fd)
169 return ::fcntl(fd, F_DUPFD, 0);
173 inline int tf_flock(
int fd,
int op)
179 inline 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;
191 inline int tf_unlink(
const char *pathname)
193 return ::unlink(pathname);
197 inline int tf_fileno(FILE *stream)
199 return ::fileno(stream);
206 inline int tf_poll_recv(
int socket,
int timeout)
208 struct pollfd pfd = {socket, POLLIN, 0};
209 int ret = tf_poll(&pfd, 1, timeout);
217 inline 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