From 381e59a54fafc6052d35ea56e604fa084719efa1 Mon Sep 17 00:00:00 2001 From: "[CST] Focus" Date: Mon, 9 Sep 2013 12:41:50 +0400 Subject: [PATCH] lib/libupnpclient/UPNPDevice.cpp: change to non-blocking recv --- lib/libupnpclient/UPNPDevice.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/libupnpclient/UPNPDevice.cpp b/lib/libupnpclient/UPNPDevice.cpp index bc8aa49bb..6611b21ed 100644 --- a/lib/libupnpclient/UPNPDevice.cpp +++ b/lib/libupnpclient/UPNPDevice.cpp @@ -34,6 +34,8 @@ #include #include "upnpclient.h" #include +#include +#include struct ToLower { @@ -433,11 +435,32 @@ std::string CUPnPDevice::HTTP(std::string url, std::string post, std::string act commandstr = command.str(); send(t_socket, commandstr.c_str(), commandstr.size(), 0); +#if 0 while ((received = recv(t_socket, buf, sizeof(buf)-1, 0)) > 0) { buf[received] = 0; reply << buf; } +#endif + struct pollfd fds[1]; + fds[0].fd = t_socket; + fds[0].events = POLLIN; + while (true) { + int result = poll(fds, 1, 4000); + if (result < 0) { + printf("CUPnPDevice::HTTP: poll error %s\n", strerror(errno)); + break; + } + if (result == 0) { + printf("CUPnPDevice::HTTP: poll timeout\n"); + break; + } + received = recv(t_socket, buf, sizeof(buf)-1, 0); + if (received <= 0) + break; + buf[received] = 0; + reply << buf; + } close(t_socket); return reply.str(); }