
Hi,
I'm using the asynchronous process without success using this source code :
void MyServer::forwardRequest(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn) {
// make sure it will get closed when finished
tcp_conn->setLifecycle(TCPConnection::LIFECYCLE_CLOSE);
// forward request
TCPConnectionPtr tcp_conn_fw(new TCPConnection(getIOService()));
tcp_conn_fw->setLifecycle(TCPConnection::LIFECYCLE_KEEPALIVE);
boost::system::error_code error_code;
error_code = tcp_conn_fw->connect(boost::asio::ip::address::from_string(getFwAddress()), getFwPort());
if (!error_code) {
HTTPRequestWriterPtr writer(HTTPRequestWriter::create(tcp_conn_fw, request,
boost::bind(&MyServer::readResponse,
this, tcp_conn_fw, request, tcp_conn)));
writer->send();
}
}
/**
* reads in a HTTP response asynchronously
*/
void MyServer::readResponse(TCPConnectionPtr& tcp_conn_fw, HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn) {
HTTPResponseReaderPtr reader(HTTPResponseReader::create(tcp_conn_fw, *request,
boost::bind(&MyServer::sendResponse,
this, _1, _2, request, tcp_conn)));
reader->receive();
}
The object never get the response from the target server even if this one receives the request and answer with a server error message. The "readResponse" method is never reached. I write this code based on the WebServerTest.cpp. What's going wrong?
Thanks

I simply miss to run the i/o scheduler. :-(
It works great now. :-)
- Login or register to post comments
Submitted by ruddy32 on Thu, 06/25/2009 - 23:31.Forgive me if this seems like a silly question, but are you sure the call to connect() succeeds? If it were to fail then the HTTPRequestWriter would never be created.. Also, you might want to confirm that the destination server (getFwAddress()) is receiving the forwarded request and sending a reply to it.
- Login or register to post comments
Submitted by Mike Dickey on Thu, 06/25/2009 - 08:43.I have try another process used in "WebServerTest" for asynchronous transfert without success. The bind HTTPRequestWriter method is not called.
class HTTPProxy
...
{
...
public:
...
void send(pion::net::HTTPRequestPtr& request) {
...
pion::net::HTTPRequestWriterPtr writer(
pion::net::HTTPRequestWriter::create(tcp_conn, request,
boost::bind(&HTTPProxy::readResponse, this, tcp_conn, request)));
...
}
void readResponse(pion::net::TCPConnectionPtr& tcp_conn,
pion::net::HTTPRequestPtr& request) {
...
}
...
}
This process is called while the system handles a request. What's going wrong?
- Login or register to post comments
Submitted by ruddy32 on Thu, 06/25/2009 - 01:39.