summaryrefslogtreecommitdiffstats
path: root/src/fluent-bit/lib/monkey/include/monkey/mk_core/external/winuio.h
blob: 4ae74788881565e7b8f94c39a9f7d64c32db9bc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _WINUIO_H
#define _WINUIO_H

#include <inttypes.h>

#ifndef _WIN32
#include <unistd.h>
#else
#include <errno.h>
#include <io.h>
#include <BaseTsd.h>
#include <winsock2.h>
#include <ws2tcpip.h>
typedef SSIZE_T ssize_t;
#endif

struct mk_iovec
{
    void   *iov_base;    /* Base address of a memory region for input or output */
    size_t  iov_len;     /* The size of the memory pointed to by iov_base */
};

/* Long way to go here, it's mostly a placeholder */

static inline ssize_t readv(int fildes, const struct mk_iovec *iov, int iovcnt)
{
    errno = ENOSYS;
    return -1;
}

static inline ssize_t writev(int fildes, const struct mk_iovec *iov, int iovcnt)
{
    int i;
    uint32_t bytes_written = 0;

    for (i = 0; i < iovcnt; i++) {
        int len;

        len = send((SOCKET)fildes, iov[i].iov_base, (int)iov[i].iov_len, 0);
        if (len == SOCKET_ERROR) {
                uint32_t err = GetLastError();
            // errno = win_to_posix_error(err);
            bytes_written = -1;
            break;
        }
        bytes_written += len;
    }

    return bytes_written;
}


#endif /* _WINUIO_H */