sf :: Http :: sendRequest永远不会返回

时间:2016-11-07 19:46:27

标签: c++ http sfml

我使用pistache撰写了一个简单的网络服务。我正在使用sf::Httpsf::Http::Request类向其发送请求。但是,sf::Http::sendRequest的调用永远不会返回,即使我指定了250毫秒的超时。事情只发生在我网站的请求上。如果我向www.google.com发送GET请求,则该方法会很快返回正确的响应。

这是客户端代码示例:

sf::Http http("http://192.168.1.10", 8080);
sf::Http::Request request("/highscores", sf::Http::Request::Method::Get);
request.setHttpVersion(1, 1);
//the call below never returns
auto response = http.sendRequest(request, sf::seconds(0.25f));
std::cout << response.getBody();

服务响应在浏览器和curl中似乎是正确的:

$ curl -v 192.168.1.10:8080/highscores
*   Trying 192.168.1.10...
* Connected to 192.168.1.10 (192.168.1.10) port 8080 (#0)
> GET /highscores HTTP/1.1
> Host: 192.168.1.10:8080
> User-Agent: curl/7.47.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Connection: Keep-Alive
< Content-Length: 2
< 
* Connection #0 to host 192.168.1.10 left intact
[]%      

在我的应用程序上使用strace表明它发送了正确的请求,甚至在某些时候它收到了正确的响应:

$ strace -s 192 ./sfmlApplication
...
sendto(20, "GET /highscores HTTP/1.1\r\nconnection: close\r\ncontent-length: 0\r\ncontent-type: application/json\r\nfrom: user@sfml-dev.org\r\nhost: 192.168.1.10\r\nuser-agent: libsfml-network/2.x\r\n\r\n", 176, MSG_NOSIGNAL, NULL, 0) = 176
recvfrom(20, "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nConnection: Keep-Alive\r\nContent-Length: 2\r\n\r\n[]", 1024, MSG_NOSIGNAL, NULL, NULL) = 96
recvfrom(20, 

strace程序停止响应并且必须被杀死之后,这些是recvfrom(20,输出的最后一行。

阻塞操作的堆栈跟踪顶部是:

recv() at 0x7ffff7bcd10f    
sf::TcpSocket::receive() at 0x7ffff77b12c0  
sf::Http::sendRequest() at 0x7ffff77ad5ed   

SFML版本:2.3.2

系统:Fedora 4.8.4-200.fc24.x86_64

为什么sf::Http::sendRequest方法调用永远不会返回?

0 个答案:

没有答案