lib/libupnpclient/UPNPDevice.cpp: change to non-blocking recv

This commit is contained in:
[CST] Focus
2013-09-09 12:41:50 +04:00
parent 37accb627c
commit 381e59a54f

View File

@@ -34,6 +34,8 @@
#include <poll.h>
#include "upnpclient.h"
#include <algorithm>
#include <errno.h>
#include <stdio.h>
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();
}