mirror of
https://projects.vdr-developer.org/git/vdr-plugin-streamdev.git
synced 2023-10-10 19:16:51 +02:00
Added timeout to Commit()
This commit is contained in:
parent
a047fc7d32
commit
c1dc1453c5
1
HISTORY
1
HISTORY
@ -1,6 +1,7 @@
|
|||||||
VDR Plugin 'streamdev' Revision History
|
VDR Plugin 'streamdev' Revision History
|
||||||
---------------------------------------
|
---------------------------------------
|
||||||
|
|
||||||
|
- Added timeout to Connect()
|
||||||
- Report the server-side HTTP status "503 Service unavailable" instead of
|
- Report the server-side HTTP status "503 Service unavailable" instead of
|
||||||
the client-side error "409 Conflict" when a channel is unavailable
|
the client-side error "409 Conflict" when a channel is unavailable
|
||||||
(suggested by Methodus)
|
(suggested by Methodus)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "tools/socket.h"
|
#include "tools/socket.h"
|
||||||
|
#include "tools/select.h"
|
||||||
|
|
||||||
#include <vdr/tools.h>
|
#include <vdr/tools.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -27,7 +28,7 @@ cTBSocket::~cTBSocket() {
|
|||||||
if (IsOpen()) Close();
|
if (IsOpen()) Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cTBSocket::Connect(const std::string &Host, unsigned int Port) {
|
bool cTBSocket::Connect(const std::string &Host, unsigned int Port, unsigned int TimeoutMs) {
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
int socket;
|
int socket;
|
||||||
|
|
||||||
@ -45,14 +46,37 @@ bool cTBSocket::Connect(const std::string &Host, unsigned int Port) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TimeoutMs > 0 && ::fcntl(socket, F_SETFL, O_NONBLOCK) == -1) {
|
||||||
|
::close(socket);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
m_RemoteAddr.sin_family = AF_INET;
|
m_RemoteAddr.sin_family = AF_INET;
|
||||||
m_RemoteAddr.sin_port = htons(Port);
|
m_RemoteAddr.sin_port = htons(Port);
|
||||||
m_RemoteAddr.sin_addr.s_addr = inet_addr(Host.c_str());
|
m_RemoteAddr.sin_addr.s_addr = inet_addr(Host.c_str());
|
||||||
if (::connect(socket, (struct sockaddr*)&m_RemoteAddr,
|
if (::connect(socket, (struct sockaddr*)&m_RemoteAddr, sizeof(m_RemoteAddr)) == -1) {
|
||||||
sizeof(m_RemoteAddr)) == -1) {
|
if (TimeoutMs > 0 && errno == EINPROGRESS) {
|
||||||
|
int so_error;
|
||||||
|
socklen_t len = sizeof(so_error);
|
||||||
|
cTBSelect select;
|
||||||
|
select.Add(socket);
|
||||||
|
if (select.Select(TimeoutMs) == -1 ||
|
||||||
|
::getsockopt(socket, SOL_SOCKET, SO_ERROR, &so_error, &len) == -1) {
|
||||||
::close(socket);
|
::close(socket);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (so_error) {
|
||||||
|
errno = so_error;
|
||||||
|
::close(socket);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
::close(socket);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_Type == SOCK_STREAM) {
|
if (m_Type == SOCK_STREAM) {
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
|
@ -32,11 +32,13 @@ public:
|
|||||||
Reimplemented for TCP/IPv4 sockets. */
|
Reimplemented for TCP/IPv4 sockets. */
|
||||||
virtual ssize_t SysWrite(const void *Buffer, size_t Length) const;
|
virtual ssize_t SysWrite(const void *Buffer, size_t Length) const;
|
||||||
|
|
||||||
/* Connect() tries to connect an available local socket to the port given
|
/* Connect() tries to connect an available local socket within TimeoutMs
|
||||||
by Port of the target host given by Host in numbers-and-dots notation
|
milliseconds to the port given by Port of the target host given by
|
||||||
(i.e. "212.43.45.21"). Returns true if the connection attempt was
|
Host in numbers-and-dots notation (i.e. "212.43.45.21"). A TimeoutMs
|
||||||
successful and false otherwise, setting errno appropriately. */
|
of 0 will disable non-blocking IO for the connect call. Returns true
|
||||||
virtual bool Connect(const std::string &Host, uint Port);
|
if the connection attempt was successful and false otherwise, setting
|
||||||
|
errno appropriately. */
|
||||||
|
virtual bool Connect(const std::string &Host, uint Port, uint TimeoutMs = 0);
|
||||||
|
|
||||||
/* Shutdown() shuts down one or both ends of a socket. If called with How
|
/* Shutdown() shuts down one or both ends of a socket. If called with How
|
||||||
set to SHUT_RD, further reads on this socket will be denied. If called
|
set to SHUT_RD, further reads on this socket will be denied. If called
|
||||||
|
Loading…
Reference in New Issue
Block a user