| 124 | } |
| 125 | |
| 126 | static size_t read_data(char* buffer, size_t size, size_t nitems, void* userdata) |
| 127 | { |
| 128 | auto const limit = size * nitems; |
| 129 | auto* ctx = static_cast<std::pair<std::string const&, size_t>*>(userdata); |
| 130 | assert(ctx); |
| 131 | auto const unread = ctx->first.length() - ctx->second; |
| 132 | if (0 == unread) { |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | if (unread <= limit) { |
| 137 | auto from = ctx->first.begin(); |
| 138 | std::advance(from, ctx->second); |
| 139 | std::copy_n(from, unread, buffer); |
| 140 | ctx->second += unread; |
| 141 | return unread; |
| 142 | } |
| 143 | |
| 144 | auto from = ctx->first.begin(); |
| 145 | std::advance(from, ctx->second); |
| 146 | std::copy_n(from, limit, buffer); |
| 147 | ctx->second += limit; |
| 148 | return limit; |
| 149 | } |
| 150 | |
| 151 | #ifndef NDEBUG |
| 152 | static int rt_curl_debug_callback(CURL* handle, curl_infotype type, char* data, size_t size, void* userdata) |