influxdb-cpp icon indicating copy to clipboard operation
influxdb-cpp copied to clipboard

Compiling in UNIX

Open kikoalbiol opened this issue 6 years ago • 6 comments

Implement the writev function

#ifdef _WIN32
    #define NOMINMAX
    #include <windows.h>
    #include <algorithm>
    #pragma comment(lib, "ws2_32")
    typedef struct iovec { void* iov_base; size_t iov_len; } iovec;
    inline __int64 writev(int sock, struct iovec* iov, int cnt) {
        __int64 r = send(sock, (const char*)iov->iov_base, iov->iov_len, 0);
        return (r < 0 || cnt == 1) ? r : r + writev(sock, iov + 1, cnt - 1);
    }
#else
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #define closesocket close
inline size_t writev(int sock, struct iovec* iov, int cnt) {
    size_t retval=0;
    for(auto i=0;i<cnt;i++)
        retval+=write(sock,iov[i].iov_base,iov[i].iov_len);

    return retval;
}
#endif

kikoalbiol avatar Jun 22 '18 16:06 kikoalbiol

Thank you for your contributions. I'll check it and merge them then. : )

orca-zhang avatar Jul 10 '18 12:07 orca-zhang

A simpler fix (and without compiler warnings) is to add :

#include <sys/uio.h>

instead of implementing the writev function.

rerunner avatar Dec 03 '18 13:12 rerunner

Hi, expnkx,

So, does the library work with good performance now? If not, how could we improve it?

orca-zhang avatar Nov 12 '20 05:11 orca-zhang

The latest version, use

#include <sys/uio.h>

instead.

orca-zhang avatar Dec 01 '20 07:12 orca-zhang