11 #error "tfcore_win.h included on a non-Windows system"
16 inline int tf_poll(pollfd *fds,
int nfds,
int timeout)
18 return ::WSAPoll(fds, nfds, timeout);
25 inline int tf_poll_recv(
int socket,
int timeout)
27 pollfd pfd = {(SOCKET)socket, POLLIN, 0};
28 int ret = tf_poll(&pfd, 1, timeout);
36 inline int tf_poll_send(
int socket,
int timeout)
38 pollfd pfd = {(SOCKET)socket, POLLOUT, 0};
39 int ret = tf_poll(&pfd, 1, timeout);
44 inline int tf_close(
int fd)
50 inline int tf_read(
int fd,
void *buf,
size_t count)
52 return ::_read(fd, buf, (uint)count);
56 inline int tf_write(
int fd,
const void *buf,
size_t count)
58 return ::_write(fd, buf, (uint)count);
62 inline int tf_send(
int sockfd,
const void *buf,
size_t len,
int flags = 0)
65 return ::send((SOCKET)sockfd, (
const char *)buf, (
int)len, 0);
69 inline int tf_recv(
int sockfd,
void *buf,
size_t len,
int flags = 0)
72 return ::recv((SOCKET)sockfd, (
char *)buf, (
int)len, 0);
76 inline int tf_close_socket(
int sockfd)
78 return ::closesocket((SOCKET)sockfd);
82 inline int tf_dup(
int fd)
88 inline int tf_flock(
int fd,
int op)
96 inline int tf_lockfile(
int fd,
bool exclusive,
bool blocking)
98 auto handle =
reinterpret_cast<HANDLE
>(_get_osfhandle(fd));
99 DWORD dwFlags = (exclusive) ? LOCKFILE_EXCLUSIVE_LOCK : 0;
100 dwFlags |= (blocking) ? 0 : LOCKFILE_FAIL_IMMEDIATELY;
102 std::memset(&ov, 0,
sizeof(OVERLAPPED));
103 BOOL res = LockFileEx(handle, dwFlags, 0, 0, 0, &ov);
104 return (res) ? 0 : -1;
108 inline int tf_unlink(
const char *pathname)
110 return ::_unlink(pathname);
114 inline int tf_fileno(FILE *stream)
116 return ::_fileno(stream);