| 143 | ////////////////////////////////////////////////////////////////////////////// |
| 144 | |
| 145 | bool http_client::write_chunk(ostream& out, const void* data, size_t len) |
| 146 | { |
| 147 | #ifndef HAS_IOV |
| 148 | # define HAS_IOV |
| 149 | #endif |
| 150 | |
| 151 | #ifdef HAS_IOV |
| 152 | struct iovec iov[3]; |
| 153 | |
| 154 | char hdr[32]; |
| 155 | safe_snprintf(hdr, sizeof(hdr), "%x\r\n", (int) len); |
| 156 | |
| 157 | #ifdef MINGW |
| 158 | iov[0].iov_base = hdr; |
| 159 | #else |
| 160 | iov[0].iov_base = (void*) hdr; |
| 161 | #endif |
| 162 | iov[0].iov_len = strlen(hdr); |
| 163 | |
| 164 | #ifdef MINGW |
| 165 | iov[1].iov_base = (char*) data; |
| 166 | #else |
| 167 | iov[1].iov_base = (void*) data; |
| 168 | #endif |
| 169 | iov[1].iov_len = (int) len; |
| 170 | |
| 171 | #ifdef MINGW |
| 172 | iov[2].iov_base = (char*) "\r\n"; |
| 173 | #else |
| 174 | iov[2].iov_base = (void*) "\r\n"; |
| 175 | #endif |
| 176 | iov[2].iov_len = 2; |
| 177 | |
| 178 | if (out.writev(iov, 3) == -1) { |
| 179 | disconnected_ = true; |
| 180 | return false; |
| 181 | } else { |
| 182 | return true; |
| 183 | } |
| 184 | #else |
| 185 | if (out.format("%x\r\n", (int) len) == -1 |
| 186 | || out.write(data, len) == -1 |
| 187 | || out.write("\r\n", 2) == -1) { |
| 188 | |
| 189 | disconnected_ = true; |
| 190 | return false; |
| 191 | } else { |
| 192 | return true; |
| 193 | } |
| 194 | #endif |
| 195 | } |
| 196 | |
| 197 | bool http_client::write_chunk_trailer(ostream& out) |
| 198 | { |
no test coverage detected