influxdb-cpp
influxdb-cpp copied to clipboard
Compiling in UNIX
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
Thank you for your contributions. I'll check it and merge them then. : )
A simpler fix (and without compiler warnings) is to add :
#include <sys/uio.h>
instead of implementing the writev function.
Hi, expnkx,
So, does the library work with good performance now? If not, how could we improve it?
The latest version, use
#include <sys/uio.h>
instead.