+ BOOST_FOREACH(const StringMap::value_type& h, r->requestHeaders()) {
+ headerData << h.first << ": " << h.second << "\r\n";
+ }
+
+ headerData << "\r\n"; // final CRLF to terminate the headers
+ if (!bodyData.empty()) {
+ headerData << bodyData;
+ }
+
+ bool ok = push(headerData.str().c_str());
+ if (!ok) {
+ SG_LOG(SG_IO, SG_WARN, "HTTPClient: over-stuffed the socket");
+ // we've over-stuffed the socket, give up for now, let things
+ // drain down before trying to start any more requests.
+ return;
+ }
+
+ if( r->hasBodyData() )
+ for(size_t body_bytes_sent = 0; body_bytes_sent < r->bodyLength();)
+ {
+ char buf[4096];
+ size_t len = r->getBodyData(buf, body_bytes_sent, 4096);
+ if( len )
+ {
+ if( !bufferSend(buf, len) )
+ {
+ SG_LOG(SG_IO,
+ SG_WARN,
+ "overflow the HTTP::Connection output buffer");
+ state = STATE_SOCKET_ERROR;
+ return;
+ }
+ body_bytes_sent += len;
+ }
+ else
+ {
+ SG_LOG(SG_IO,
+ SG_WARN,
+ "HTTP asynchronous request body generation is unsupported");
+ break;
+ }
+ }
+
+ // SG_LOG(SG_IO, SG_INFO, "did start request:" << r->url() <<
+ // "\n\t @ " << reinterpret_cast<void*>(r.ptr()) <<
+ // "\n\t on connection " << this);
+ // successfully sent, remove from queue, and maybe send the next
+ queuedRequests.pop_front();
+ sentRequests.push_back(r);
+ state = STATE_WAITING_FOR_RESPONSE;
+
+ // pipelining, let's maybe send the next request right away
+ tryStartNextRequest();