aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/utils/windows.c16
-rw-r--r--src/libstrongswan/utils/windows.h9
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c
index 6ce9d77c8..e511db026 100644
--- a/src/libstrongswan/utils/windows.c
+++ b/src/libstrongswan/utils/windows.c
@@ -646,6 +646,22 @@ ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
/**
* See header
*/
+#undef read
+ssize_t windows_read(int fd, void *buf, size_t count)
+{
+ ssize_t ret;
+
+ ret = recv(fd, buf, count, 0);
+ if (ret == -1 && WSAGetLastError() == WSAENOTSOCK)
+ {
+ ret = read(fd, buf, count);
+ }
+ return ret;
+}
+
+/**
+ * See header
+ */
int poll(struct pollfd *fds, int nfds, int timeout)
{
return wserr(WSAPoll(fds, nfds, timeout));
diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h
index 80106ecdb..ffd95b3fb 100644
--- a/src/libstrongswan/utils/windows.h
+++ b/src/libstrongswan/utils/windows.h
@@ -362,6 +362,15 @@ ssize_t windows_send(int sockfd, const void *buf, size_t len, int flags);
ssize_t windows_sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen);
+/**
+ * read(2) working on files and sockets, cancellable on sockets only
+ *
+ * On Windows, there does not seem to be a way how a cancellable read can
+ * be implemented on Low level I/O functions for files, _pipe()s or stdio.
+ */
+#define read windows_read
+ssize_t windows_read(int fd, void *buf, size_t count);
+
#if _WIN32_WINNT < 0x0600
/**
* Define pollfd and flags on our own if not specified