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(); }