Skip to content

Commit 7652bbd

Browse files
committed
🐝 easy port for windows
1 parent 070acbe commit 7652bbd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

influxdb.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <windows.h>
88
#include <algorithm>
99
#pragma comment(lib, "ws2_32")
10-
#define close closesocket
1110
typedef struct iovec { void* iov_base; size_t iov_len; } iovec;
1211
inline __int64 writev(int sock, struct iovec* iov, int cnt) {
1312
__int64 r = send(sock, (const char*)iov->iov_base, iov->iov_len, 0);
@@ -19,6 +18,7 @@
1918
#include <sys/socket.h>
2019
#include <netinet/in.h>
2120
#include <arpa/inet.h>
21+
#define closesocket close
2222
#endif
2323

2424
#define FMT_BUF_LEN 25 // double 24 bytes, int64_t 21 bytes
@@ -50,7 +50,7 @@ namespace influxdb_cpp {
5050
if(src[pos] == ' ')
5151
out += "+";
5252
else {
53-
out += '%';
53+
out += '%';
5454
out += to_hex((unsigned char)src[pos] >> 4);
5555
out += to_hex((unsigned char)src[pos] & 0xF);
5656
}
@@ -140,7 +140,7 @@ namespace influxdb_cpp {
140140
if(sendto(sock, &lines_[0], lines_.length(), 0, (struct sockaddr *)&addr, sizeof(addr)) < (int)lines_.length())
141141
ret = -3;
142142

143-
close(sock);
143+
closesocket(sock);
144144
return ret;
145145
}
146146
void _escape(const std::string& src, const char* escape_seq) {
@@ -203,17 +203,17 @@ namespace influxdb_cpp {
203203
return -2;
204204

205205
if(connect(sock, (struct sockaddr*)(&addr), sizeof(addr)) < 0) {
206-
close(sock);
206+
closesocket(sock);
207207
return -3;
208208
}
209209

210210
header.resize(len = 0x100);
211211

212212
for(;;) {
213213
iv[0].iov_len = snprintf(&header[0], len,
214-
"%s /%s?db=%s&u=%s&p=%s%s HTTP/1.1\r\nHost: %s\r\nContent-Length: %zd\r\n\r\n",
214+
"%s /%s?db=%s&u=%s&p=%s%s HTTP/1.1\r\nHost: %s\r\nContent-Length: %d\r\n\r\n",
215215
method, uri, si.db_.c_str(), si.usr_.c_str(), si.pwd_.c_str(),
216-
querystring.c_str(), si.host_.c_str(), body.length());
216+
querystring.c_str(), si.host_.c_str(), (int)body.length());
217217
if((int)iv[0].iov_len > len)
218218
header.resize(len *= 2);
219219
else
@@ -283,7 +283,7 @@ namespace influxdb_cpp {
283283
}
284284
ret_code = -11;
285285
END:
286-
close(sock);
286+
closesocket(sock);
287287
return ret_code / 100 == 2 ? 0 : ret_code;
288288
#undef _NO_MORE
289289
#undef _GET_NEXT_CHAR

0 commit comments

Comments
 (0)