mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 15:32:52 +02:00
lib/libupnpclient/UPNPDevice.cpp: change to non-blocking recv
Origin commit data
------------------
Commit: 381e59a54f
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2013-09-09 (Mon, 09 Sep 2013)
This commit is contained in:
@@ -34,6 +34,8 @@
|
|||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include "upnpclient.h"
|
#include "upnpclient.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct ToLower
|
struct ToLower
|
||||||
{
|
{
|
||||||
@@ -433,11 +435,32 @@ std::string CUPnPDevice::HTTP(std::string url, std::string post, std::string act
|
|||||||
|
|
||||||
commandstr = command.str();
|
commandstr = command.str();
|
||||||
send(t_socket, commandstr.c_str(), commandstr.size(), 0);
|
send(t_socket, commandstr.c_str(), commandstr.size(), 0);
|
||||||
|
#if 0
|
||||||
while ((received = recv(t_socket, buf, sizeof(buf)-1, 0)) > 0)
|
while ((received = recv(t_socket, buf, sizeof(buf)-1, 0)) > 0)
|
||||||
{
|
{
|
||||||
buf[received] = 0;
|
buf[received] = 0;
|
||||||
reply << buf;
|
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);
|
close(t_socket);
|
||||||
return reply.str();
|
return reply.str();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user