mirror of
https://projects.vdr-developer.org/git/vdr-plugin-streamdev.git
synced 2023-10-10 19:16:51 +02:00
Now preventing fd leaks.
Fix kindly provided by Artur Skawina: http://www.linuxtv.org/pipermail/vdr/2006-May/009342.html Closing bug: http://www.vdr-developer.org/mantisbt/view.php?id=115
This commit is contained in:
parent
01752a66d6
commit
7c8e59a917
@ -29,23 +29,31 @@ bool cTBSocket::Connect(const std::string &Host, unsigned int Port) {
|
|||||||
m_LocalAddr.sin_port = 0;
|
m_LocalAddr.sin_port = 0;
|
||||||
m_LocalAddr.sin_addr.s_addr = INADDR_ANY;
|
m_LocalAddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
if (::bind(socket, (struct sockaddr*)&m_LocalAddr, sizeof(m_LocalAddr))
|
if (::bind(socket, (struct sockaddr*)&m_LocalAddr, sizeof(m_LocalAddr))
|
||||||
== -1)
|
== -1) {
|
||||||
|
::close(socket);
|
||||||
return false;
|
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) {
|
||||||
|
::close(socket);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
if (::getpeername(socket, (struct sockaddr*)&m_RemoteAddr, &len) == -1)
|
if (::getpeername(socket, (struct sockaddr*)&m_RemoteAddr, &len) == -1) {
|
||||||
|
::close(socket);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
if (::getsockname(socket, (struct sockaddr*)&m_LocalAddr, &len) == -1)
|
if (::getsockname(socket, (struct sockaddr*)&m_LocalAddr, &len) == -1) {
|
||||||
|
::close(socket);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return cTBSource::Open(socket);
|
return cTBSource::Open(socket);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user