MCPcopy Create free account
hub / github.com/acl-dev/acl / write_chunk

Method write_chunk

lib_acl_cpp/src/http/http_client.cpp:145–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143//////////////////////////////////////////////////////////////////////////////
144
145bool 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
197bool http_client::write_chunk_trailer(ostream& out)
198{

Callers 1

transfer_responseMethod · 0.80

Calls 4

safe_snprintfFunction · 0.85
writevMethod · 0.80
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected