├── test ├── CMakeLists.txt └── main.cpp ├── .gitignore ├── LICENSE ├── README.md └── influxdb.hpp /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 2 | CMAKE_POLICY(VERSION 2.8) 3 | 4 | PROJECT(influxdb_cpp_ut) 5 | 6 | AUX_SOURCE_DIRECTORY(. DIR_SRCS) 7 | 8 | IF(CMAKE_SYSTEM_NAME MATCHES "Linux") 9 | LINK_LIBRARIES(gtest pthread) 10 | SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb") 11 | SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall") 12 | ENDIF() 13 | 14 | SET(CMAKE_BUILD_TYPE "Debug") 15 | 16 | ADD_EXECUTABLE(influxdb_cpp_ut ${DIR_SRCS}) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | CMakeFiles 10 | CMakeCache.txt 11 | *.cmake 12 | Makefile 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | *_ut 38 | 39 | # ctags files 40 | .tags* 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Orca 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /test/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../influxdb.hpp" 2 | #include 3 | using namespace std; 4 | 5 | // Visit https://github.com/orca-zhang/influxdb-c for more test cases 6 | 7 | int main(int argc, char const *argv[]) 8 | { 9 | influxdb_cpp::server_info si("127.0.0.1", 8086, "testx", "test", "test"); 10 | // post_http demo with resp[optional] 11 | string resp; 12 | int ret = influxdb_cpp::builder() 13 | .meas("test") 14 | .tag("k", "v") 15 | .tag("x", "y") 16 | .field("x", 10) 17 | .field("y", 10.3, 2) 18 | .field("b", !!10) 19 | .timestamp(1512722735522840439) 20 | .post_http(si, &resp); 21 | 22 | cout << ret << endl << resp << endl; 23 | 24 | // send_udp demo 25 | ret = influxdb_cpp::builder() 26 | .meas("test") 27 | .tag("k", "v") 28 | .tag("x", "y") 29 | .field("x", 10) 30 | .field("y", 3.14e18, 3) 31 | .field("b", !!10) 32 | .timestamp(1512722735522840439) 33 | .send_udp("127.0.0.1", 8089); 34 | 35 | cout << ret << endl; 36 | 37 | // query from table 38 | influxdb_cpp::server_info si_new("127.0.0.1", 8086, "", "test", "test"); 39 | influxdb_cpp::query(resp, "show databases", si); 40 | cout << resp << endl; 41 | 42 | // create_db 43 | influxdb_cpp::create_db(resp, "x", si_new); 44 | cout << resp << endl; 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # influxdb-cpp-2.0 2 | 3 | A header-only C++ query & write client for InfluxDB 2.0. 4 | 5 | [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/orca-zhang/influxdb-cpp/blob/master/LICENSE) [![Build Status](https://semaphoreci.com/api/v1/orca-zhang-91/influxdb-cpp/branches/master/shields_badge.svg)](https://semaphoreci.com/orca-zhang-91/influxdb-cpp) [![Build status](https://ci.appveyor.com/api/projects/status/gusrrn0mn67q2yaj?svg=true)](https://ci.appveyor.com/project/orca-zhang/influxdb-cpp) 6 | 7 | - Support versions: 8 | - InfluxDB v2.0 9 | - Incompatible with versions 1.x 10 | - Check yourself while using future versions. 11 | 12 | ### Why use influxdb-cpp? 13 | 14 | - **Exactly-small**: 15 | - Less than 300 lines and only 10KB+. 16 | - **Easy-to-use**: 17 | - It's designed to be used without extra studies. 18 | - **Easy-to-assemble**: 19 | - Only a tiny header file needs to be included. 20 | - **No-dependencies**: 21 | - Unless STL and std C libraries. 22 | 23 | ### Examples 24 | 25 | #### Before using 26 | 27 | - The very simple thing you should do before using is only: 28 | 29 | ```cpp 30 | #include "influxdb.hpp" 31 | ``` 32 | 33 | #### Writing example 34 | 35 | - You should refer to the [write syntax](https://docs.influxdata.com/influxdb/v1.4/write_protocols/line_protocol_reference/) while writing series(metrics). 36 | 37 | ``` 38 | measurement[,tag-key=tag-value...] field-key=field-value[,field2-key=field2-value...] [unix-nano-timestamp] 39 | ``` 40 | 41 | 42 | - You can rapidly start writing series according to the following example. 43 | 44 | ```cpp 45 | influxdb_cpp::server_info si("127.0.0.1", 8086, "org", "token", "bucket"); 46 | influxdb_cpp::builder() 47 | .meas("foo") 48 | .tag("k", "v") 49 | .tag("x", "y") 50 | .field("x", 10) 51 | .field("y", 10.3, 4) 52 | .field("z", 10.3456) 53 | .field("b", !!10) 54 | .timestamp(1512722735522840439) 55 | .post_http(si); 56 | ``` 57 | 58 | - **Remarks**: 59 | - 3rd parameter `precision` of `field()` is optional for floating point value, and default precision is defined in the top of the header. 60 | - The token must have access to write (and/or read) from the specified organization and bucket. 61 | - Although `bucket` is an optional parameter for a server info object, it is **required** for database writes. 62 | 63 | 64 | - The series sent is: 65 | 66 | ``` 67 | foo,k=v,x=y x=10i,y=10.30,z=10.346,b=t 1512722735522840439 68 | ``` 69 | 70 | 71 | - Bulk/batch/multiple insert also supports: 72 | 73 | ```cpp 74 | influxdb_cpp::builder() 75 | .meas("foo") // series 1 76 | .field("x", 10) 77 | 78 | .meas("bar") // series 2 79 | .field("y", 10.3) 80 | .post_http(si); 81 | ``` 82 | 83 | - The series sent are: 84 | 85 | ``` 86 | foo x=10i 87 | bar y=10.30 88 | ``` 89 | 90 | #### Query example 91 | 92 | - And you can query series using the Flux query language. 93 | 94 | ```cpp 95 | influxdb_cpp::server_info si("localhost", 8086, "spartans", "my_token", ""); 96 | 97 | string resp; 98 | string query("from(bucket: \\\"SR-20\\\")|> range(start: -5m)|>filter(fn: (r)=>r[\\\"_measurement\\\"] == \\\"cpu\\\")|>filter(fn: (r) => r[\\\"_field\\\"] == \\\"usage_user\\\")"); 99 | 100 | influxdb_cpp::query(resp, query, si); 101 | ``` 102 | - _**NOTE:**_ The query is sent in a JSON key-pair, therefore there must be no newlines/tabs, and `"` must be double-escaped as `\\\"`! 103 | 104 | - The results are returned in CSV format. A column, `table`, separates different measurements 105 | 106 | ### **Remarks for Windows** 107 | 108 | - You should **init socket environment by yourself** under Windows. 109 | - FYR: [MSDN doc for `WSAStartup`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms742213(v=vs.85).aspx) 110 | 111 | ### TODO 112 | 113 | - Add more test cases. 114 | - Supports DSN initializatin for server_info. 115 | - Do not need to connect every time. 116 | 117 | ### Misc 118 | 119 | - Please feel free to use influxdb-cpp. 120 | - Looking forward to your suggestions. 121 | - If your project is using influxdb-cpp, you can show your project or company here by creating a issue or let me know. 122 | -------------------------------------------------------------------------------- /influxdb.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | influxdb-cpp -- 💜 C++ client for InfluxDB. 3 | 4 | Copyright (c) 2010-2018 5 | This library is released under the MIT License. 6 | 7 | Please see LICENSE file or visit https://github.com/orca-zhang/influxdb-cpp for details. 8 | */ 9 | 10 | #ifndef INFLUXDB_CPP_HPP 11 | #define INFLUXDB_CPP_HPP 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // for testing 19 | #include 20 | 21 | #define DEFAULT_PRECISION 5 22 | 23 | #ifdef _WIN32 24 | #define NOMINMAX 25 | #include 26 | #include 27 | #pragma comment(lib, "ws2_32") 28 | typedef struct iovec { void* iov_base; size_t iov_len; } iovec; 29 | inline __int64 writev(int sock, struct iovec* iov, int cnt) { 30 | __int64 r = send(sock, (const char*)iov->iov_base, iov->iov_len, 0); 31 | return (r < 0 || cnt == 1) ? r : r + writev(sock, iov + 1, cnt - 1); 32 | } 33 | #else 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #define closesocket close 42 | #endif 43 | 44 | namespace influxdb_cpp { 45 | struct server_info { 46 | std::string host_; 47 | int port_; 48 | std::string org_; 49 | std::string bkt_; 50 | std::string tkn_; 51 | struct addrinfo hints_, *res_=NULL; 52 | server_info(const std::string& host, int port, const std::string& org, const std::string& token, const std::string& bucket = "") { 53 | port_ = port; 54 | org_ = org; 55 | tkn_ = token; 56 | bkt_ = bucket; 57 | 58 | // please reference the IBM documentation for IPv4/IPv6 with questions 59 | // https://www.ibm.com/docs/en/i/7.2?topic=clients-example-ipv4-ipv6-client 60 | int resp = 0; 61 | 62 | struct in6_addr serveraddr; 63 | memset(&hints_, 0x00, sizeof(hints_)); 64 | hints_.ai_flags = AI_NUMERICSERV; 65 | hints_.ai_family = AF_UNSPEC; 66 | hints_.ai_socktype = SOCK_STREAM; 67 | 68 | // check to see if the address is a valid IPv4 address 69 | resp = inet_pton(AF_INET, host.c_str(), &serveraddr); 70 | if (resp == 1){ 71 | hints_.ai_family = AF_INET; // IPv4 72 | hints_.ai_flags |= AI_NUMERICHOST; 73 | 74 | // not a valid IPv4 -> check to see if address is a valid IPv6 address 75 | } else { 76 | resp = inet_pton(AF_INET6, host.c_str(), &serveraddr); 77 | if (resp == 1) { 78 | hints_.ai_family = AF_INET6; // IPv6 79 | hints_.ai_flags |= AI_NUMERICHOST; 80 | 81 | } 82 | } 83 | 84 | resp = getaddrinfo(host.c_str(), std::to_string(port).c_str(), &hints_, &res_); 85 | if (resp != 0) { 86 | std::cerr << "Host not found --> " << gai_strerror(resp) << std::endl; 87 | if (resp == EAI_SYSTEM) 88 | std::cerr << "getaddrinfo() failed" << std::endl; 89 | exit(1); 90 | } 91 | 92 | } 93 | }; 94 | namespace detail { 95 | struct meas_caller; 96 | struct tag_caller; 97 | struct field_caller; 98 | struct ts_caller; 99 | struct inner { 100 | static int http_request(const char*, const char*, const std::string&, const std::string&, const server_info&, std::string*); 101 | static inline unsigned char to_hex(unsigned char x) { return x > 9 ? x + 55 : x + 48; } 102 | static void url_encode(std::string& out, const std::string& src); 103 | }; 104 | } 105 | 106 | inline int flux_query(std::string& resp, const std::string& query, const server_info& si) { 107 | 108 | // query JSON body 109 | std::stringstream body; 110 | body << "{\"query\": \""; 111 | body << query; 112 | body << "\", \"type\": \"flux\" }"; 113 | 114 | return detail::inner::http_request("POST", "query", "", body.str(), si, &resp); 115 | } 116 | 117 | struct builder { 118 | detail::tag_caller& meas(const std::string& m) { 119 | lines_.imbue(std::locale("C")); 120 | lines_.clear(); 121 | return _m(m); 122 | } 123 | protected: 124 | detail::tag_caller& _m(const std::string& m) { 125 | _escape(m, ", "); 126 | return (detail::tag_caller&)*this; 127 | } 128 | detail::tag_caller& _t(const std::string& k, const std::string& v) { 129 | lines_ << ','; 130 | _escape(k, ",= "); 131 | lines_ << '='; 132 | _escape(v, ",= "); 133 | return (detail::tag_caller&)*this; 134 | } 135 | detail::field_caller& _f_s(char delim, const std::string& k, const std::string& v) { 136 | #ifdef INFLUXCPP2_DEBUG 137 | std::cout << "KV: " << k << " " << v << std::endl; 138 | #endif 139 | lines_ << delim; 140 | lines_ << std::fixed; 141 | _escape(k, ",= "); 142 | lines_ << "=\""; 143 | _escape(v, "\""); 144 | lines_ << '\"'; 145 | return (detail::field_caller&)*this; 146 | } 147 | detail::field_caller& _f_i(char delim, const std::string& k, long long v) { 148 | lines_ << delim; 149 | lines_ << std::fixed; 150 | _escape(k, ",= "); 151 | lines_ << '='; 152 | lines_ << v << 'i'; 153 | return (detail::field_caller&)*this; 154 | } 155 | detail::field_caller& _f_f(char delim, const std::string& k, double v, int prec) { 156 | lines_ << delim; 157 | _escape(k, ",= "); 158 | lines_ << std::fixed; 159 | lines_.precision(prec); 160 | lines_ << '=' << v; 161 | return (detail::field_caller&)*this; 162 | } 163 | detail::field_caller& _f_b(char delim, const std::string& k, bool v) { 164 | lines_ << delim; 165 | _escape(k, ",= "); 166 | lines_ << std::fixed; 167 | lines_ << '=' << (v ? 't' : 'f'); 168 | return (detail::field_caller&)*this; 169 | } 170 | detail::ts_caller& _ts(long long ts) { 171 | lines_ << ' ' << ts; 172 | return (detail::ts_caller&)*this; 173 | } 174 | int _post_http(const server_info& si, std::string* resp) { 175 | return detail::inner::http_request("POST", "write", "", lines_.str(), si, resp); 176 | } 177 | void _escape(const std::string& src, const char* escape_seq) { 178 | size_t pos = 0, start = 0; 179 | while((pos = src.find_first_of(escape_seq, start)) != std::string::npos) { 180 | lines_.write(src.c_str() + start, pos - start); 181 | lines_ << '\\' << src[pos]; 182 | start = ++pos; 183 | } 184 | lines_.write(src.c_str() + start, src.length() - start); 185 | } 186 | 187 | std::stringstream lines_; 188 | }; 189 | 190 | namespace detail { 191 | struct tag_caller : public builder { 192 | detail::tag_caller& tag(const std::string& k, const std::string& v) { return _t(k, v); } 193 | detail::field_caller& field(const std::string& k, const std::string& v) { return _f_s(' ', k, v); } 194 | detail::field_caller& field(const std::string& k, bool v) { return _f_b(' ', k, v); } 195 | detail::field_caller& field(const std::string& k, short v) { return _f_i(' ', k, v); } 196 | detail::field_caller& field(const std::string& k, int v) { return _f_i(' ', k, v); } 197 | detail::field_caller& field(const std::string& k, long v) { return _f_i(' ', k, v); } 198 | detail::field_caller& field(const std::string& k, long long v) { return _f_i(' ', k, v); } 199 | detail::field_caller& field(const std::string& k, double v, int prec = DEFAULT_PRECISION) { return _f_f(' ', k, v, prec); } 200 | private: 201 | detail::tag_caller& meas(const std::string& m); 202 | }; 203 | struct ts_caller : public builder { 204 | detail::tag_caller& meas(const std::string& m) { lines_ << '\n'; return _m(m); } 205 | int post_http(const server_info& si, std::string* resp = NULL) { return _post_http(si, resp); } 206 | }; 207 | struct field_caller : public ts_caller { 208 | detail::field_caller& field(const std::string& k, const std::string& v) { return _f_s(',', k, v); } 209 | detail::field_caller& field(const std::string& k, bool v) { return _f_b(',', k, v); } 210 | detail::field_caller& field(const std::string& k, short v) { return _f_i(',', k, v); } 211 | detail::field_caller& field(const std::string& k, int v) { return _f_i(',', k, v); } 212 | detail::field_caller& field(const std::string& k, long v) { return _f_i(',', k, v); } 213 | detail::field_caller& field(const std::string& k, long long v) { return _f_i(',', k, v); } 214 | detail::field_caller& field(const std::string& k, double v, int prec = 2) { return _f_f(',', k, v, prec); } 215 | detail::ts_caller& timestamp(unsigned long long ts) { return _ts(ts); } 216 | }; 217 | inline void inner::url_encode(std::string& out, const std::string& src) { 218 | size_t pos = 0, start = 0; 219 | while((pos = src.find_first_not_of("abcdefghijklmnopqrstuvwxyqABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", start)) != std::string::npos) { 220 | out.append(src.c_str() + start, pos - start); 221 | if(src[pos] == ' ') 222 | out += "+"; 223 | else { 224 | out += '%'; 225 | out += to_hex((unsigned char)src[pos] >> 4); 226 | out += to_hex((unsigned char)src[pos] & 0xF); 227 | } 228 | start = ++pos; 229 | } 230 | out.append(src.c_str() + start, src.length() - start); 231 | } 232 | inline int inner::http_request(const char* method, const char* uri, 233 | const std::string& querystring, const std::string& body, const server_info& si, std::string* resp) { 234 | std::string header; 235 | struct iovec iv[2]; 236 | int sock, ret_code = 0, content_length = 0, len = 0; 237 | char ch; 238 | unsigned char chunked = 0; 239 | 240 | 241 | // open the socket 242 | sock = socket(si.res_->ai_family, si.res_->ai_socktype, si.res_->ai_protocol); 243 | if (sock < 0) { 244 | std::cerr << "socket() failed" << std::endl; 245 | closesocket(sock); 246 | return(1); 247 | } 248 | 249 | 250 | 251 | // connect to the server 252 | ret_code = connect(sock, si.res_->ai_addr, si.res_->ai_addrlen); 253 | if (ret_code < 0) 254 | { 255 | std::cerr << "connect() failed" << std::endl; 256 | closesocket(sock); 257 | exit(1); 258 | } 259 | 260 | 261 | 262 | header.resize(len = 0x100); 263 | 264 | for(;;) { 265 | iv[0].iov_len = snprintf(&header[0], len, 266 | "%s /api/v2/%s?org=%s&bucket=%s%s HTTP/1.1\r\nHost: %s\r\nAuthorization:Token %s\r\nContent-Length: %d\r\n\r\n", 267 | method, uri, si.org_.c_str(), si.bkt_.c_str(), 268 | querystring.c_str(), si.host_.c_str(), si.tkn_.c_str(), (int)body.length()); 269 | 270 | #ifdef INFLUXCPP2_DEBUG 271 | std::cout << printf(&header[0], len, 272 | "%s /api/v2/%s?org=%s&bucket=%s%s HTTP/1.1\r\nHost: %s\r\nAuthorization:Token %s\r\nContent-Length: %d\r\n\r\n", 273 | method, uri, si.org_.c_str(), si.bkt_.c_str(), 274 | querystring.c_str(), si.host_.c_str(), si.tkn_.c_str(), (int)body.length()) << std::endl; 275 | #endif 276 | if((int)iv[0].iov_len >= len) 277 | header.resize(len *= 2); 278 | else 279 | break; 280 | } 281 | iv[0].iov_base = &header[0]; 282 | iv[1].iov_base = (void*)&body[0]; 283 | iv[1].iov_len = body.length(); 284 | 285 | if(writev(sock, iv, 2) < (int)(iv[0].iov_len + iv[1].iov_len)) { 286 | ret_code = -6; 287 | goto END; 288 | } 289 | 290 | iv[0].iov_len = len; 291 | 292 | #define _NO_MORE() (len >= (int)iv[0].iov_len && \ 293 | (iv[0].iov_len = recv(sock, &header[0], header.length(), len = 0)) == size_t(-1)) 294 | #define _GET_NEXT_CHAR() (ch = _NO_MORE() ? 0 : header[len++]) 295 | #define _LOOP_NEXT(statement) for(;;) { if(!(_GET_NEXT_CHAR())) { ret_code = -7; goto END; } statement } 296 | #define _UNTIL(c) _LOOP_NEXT( if(ch == c) break; ) 297 | #define _GET_NUMBER(n) _LOOP_NEXT( if(ch >= '0' && ch <= '9') n = n * 10 + (ch - '0'); else break; ) 298 | #define _GET_CHUNKED_LEN(n, c) _LOOP_NEXT( if(ch >= '0' && ch <= '9') n = n * 16 + (ch - '0'); \ 299 | else if(ch >= 'A' && ch <= 'F') n = n * 16 + (ch - 'A') + 10; \ 300 | else if(ch >= 'a' && ch <= 'f') n = n * 16 + (ch - 'a') + 10; else {if(ch != c) { ret_code = -8; goto END; } break;} ) 301 | #define _(c) if((_GET_NEXT_CHAR()) != c) break; 302 | #define __(c) if((_GET_NEXT_CHAR()) != c) { ret_code = -9; goto END; } 303 | 304 | if(resp) resp->clear(); 305 | 306 | _UNTIL(' ')_GET_NUMBER(ret_code) 307 | for(;;) { 308 | _UNTIL('\n') 309 | switch(_GET_NEXT_CHAR()) { 310 | case 'C':_('o')_('n')_('t')_('e')_('n')_('t')_('-') 311 | _('L')_('e')_('n')_('g')_('t')_('h')_(':')_(' ') 312 | _GET_NUMBER(content_length) 313 | break; 314 | case 'T':_('r')_('a')_('n')_('s')_('f')_('e')_('r')_('-') 315 | _('E')_('n')_('c')_('o')_('d')_('i')_('n')_('g')_(':') 316 | _(' ')_('c')_('h')_('u')_('n')_('k')_('e')_('d') 317 | chunked = 1; 318 | break; 319 | case '\r':__('\n') 320 | switch(chunked) { 321 | do {__('\r')__('\n') 322 | case 1: 323 | _GET_CHUNKED_LEN(content_length, '\r')__('\n') 324 | if(!content_length) { 325 | __('\r')__('\n') 326 | goto END; 327 | } 328 | case 0: 329 | while(content_length > 0 && !_NO_MORE()) { 330 | content_length -= (iv[1].iov_len = std::min(content_length, (int)iv[0].iov_len - len)); 331 | if(resp) resp->append(&header[len], iv[1].iov_len); 332 | len += iv[1].iov_len; 333 | } 334 | } while(chunked); 335 | } 336 | goto END; 337 | } 338 | if(!ch) { 339 | ret_code = -10; 340 | goto END; 341 | } 342 | } 343 | ret_code = -11; 344 | END: 345 | closesocket(sock); 346 | return ret_code / 100 == 2 ? 0 : ret_code; 347 | #undef _NO_MORE 348 | #undef _GET_NEXT_CHAR 349 | #undef _LOOP_NEXT 350 | #undef _UNTIL 351 | #undef _GET_NUMBER 352 | #undef _GET_CHUNKED_LEN 353 | #undef _ 354 | #undef __ 355 | } 356 | } 357 | } 358 | 359 | #endif // INFLUXDB_CPP_HPP 360 | --------------------------------------------------------------------------------