[vlc-commits] demux: adadptative: reuse connection by hostname/port/protocol
Francois Cartegnie
git at videolan.org
Tue Oct 27 19:13:52 CET 2015
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Oct 16 15:34:04 2015 +0200| [b656202b5cfec33bfe0543edb9b830a04f58d0ed] | committer: Francois Cartegnie
demux: adadptative: reuse connection by hostname/port/protocol
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b656202b5cfec33bfe0543edb9b830a04f58d0ed
---
modules/demux/adaptative/http/HTTPConnection.cpp | 11 ++++++++++-
modules/demux/adaptative/http/HTTPConnection.hpp | 4 +++-
.../demux/adaptative/http/HTTPConnectionManager.cpp | 16 +++++++++-------
modules/demux/adaptative/http/HTTPConnectionManager.h | 2 +-
modules/demux/adaptative/http/Sockets.cpp | 14 +++++++++++++-
modules/demux/adaptative/http/Sockets.hpp | 5 +++++
6 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/modules/demux/adaptative/http/HTTPConnection.cpp b/modules/demux/adaptative/http/HTTPConnection.cpp
index 240d16a..c0d35be 100644
--- a/modules/demux/adaptative/http/HTTPConnection.cpp
+++ b/modules/demux/adaptative/http/HTTPConnection.cpp
@@ -38,6 +38,7 @@ HTTPConnection::HTTPConnection(vlc_object_t *stream_, Socket *socket_,
queryOk = false;
retries = 0;
connectionClose = !persistent;
+ port = 80;
bindChunk(chunk_);
}
@@ -47,12 +48,20 @@ HTTPConnection::~HTTPConnection()
delete socket;
}
-bool HTTPConnection::connect(const std::string &hostname, int port)
+bool HTTPConnection::compare(const std::string &hostname, uint16_t port, int type) const
+{
+ return ( hostname == this->hostname &&
+ (socket && socket->getType() == type) &&
+ port == this->port );
+}
+
+bool HTTPConnection::connect(const std::string &hostname, uint16_t port)
{
if(!socket->connect(stream, hostname.c_str(), port))
return false;
this->hostname = hostname;
+ this->port = port;
return true;
}
diff --git a/modules/demux/adaptative/http/HTTPConnection.hpp b/modules/demux/adaptative/http/HTTPConnection.hpp
index eca03e9..ec3da7a 100644
--- a/modules/demux/adaptative/http/HTTPConnection.hpp
+++ b/modules/demux/adaptative/http/HTTPConnection.hpp
@@ -45,7 +45,8 @@ namespace adaptative
HTTPConnection(vlc_object_t *stream, Socket *, Chunk * = NULL, bool = false);
virtual ~HTTPConnection();
- virtual bool connect (const std::string& hostname, int port = 80);
+ virtual bool compare (const std::string &, uint16_t, int) const;
+ virtual bool connect (const std::string& hostname, uint16_t port = 80);
virtual bool connected () const;
virtual int query (const std::string& path);
virtual bool send (const void *buf, size_t size);
@@ -68,6 +69,7 @@ namespace adaptative
int parseReply();
std::string readLine();
std::string hostname;
+ uint16_t port;
char * psz_useragent;
vlc_object_t *stream;
size_t toRead;
diff --git a/modules/demux/adaptative/http/HTTPConnectionManager.cpp b/modules/demux/adaptative/http/HTTPConnectionManager.cpp
index ccaeb77..9dfc892 100644
--- a/modules/demux/adaptative/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptative/http/HTTPConnectionManager.cpp
@@ -54,13 +54,14 @@ void HTTPConnectionManager::releaseAllConnections()
(*it)->releaseChunk();
}
-HTTPConnection * HTTPConnectionManager::getConnectionForHost(const std::string &hostname)
+HTTPConnection * HTTPConnectionManager::getConnection(const std::string &hostname, uint16_t port, int sockettype)
{
std::vector<HTTPConnection *>::const_iterator it;
for(it = connectionPool.begin(); it != connectionPool.end(); ++it)
{
- if(!(*it)->getHostname().compare(hostname) && (*it)->isAvailable())
- return *it;
+ HTTPConnection *conn = *it;
+ if(conn->isAvailable() && conn->compare(hostname, port, sockettype))
+ return conn;
}
return NULL;
}
@@ -75,15 +76,16 @@ bool HTTPConnectionManager::connectChunk(Chunk *chunk)
msg_Dbg(stream, "Retrieving %s @%zu", chunk->getUrl().c_str(),
chunk->getStartByte());
- HTTPConnection *conn = getConnectionForHost(chunk->getHostname());
+ const int sockettype = (chunk->getScheme() == "https") ? TLSSocket::TLS : Socket::REGULAR;
+ HTTPConnection *conn = getConnection(chunk->getHostname(), chunk->getPort(), sockettype);
if(!conn)
{
- const bool tls = (chunk->getScheme() == "https");
- Socket *socket = tls ? new (std::nothrow) TLSSocket(): new (std::nothrow) Socket();
+ Socket *socket = (sockettype == TLSSocket::TLS) ? new (std::nothrow) TLSSocket()
+ : new (std::nothrow) Socket();
if(!socket)
return false;
/* disable pipelined tls until we have ticket/resume session support */
- conn = new (std::nothrow) HTTPConnection(stream, socket, chunk, !tls);
+ conn = new (std::nothrow) HTTPConnection(stream, socket, chunk, sockettype != TLSSocket::TLS);
if(!conn)
{
delete socket;
diff --git a/modules/demux/adaptative/http/HTTPConnectionManager.h b/modules/demux/adaptative/http/HTTPConnectionManager.h
index 12a0d66..2d9df54 100644
--- a/modules/demux/adaptative/http/HTTPConnectionManager.h
+++ b/modules/demux/adaptative/http/HTTPConnectionManager.h
@@ -54,7 +54,7 @@ namespace adaptative
std::vector<HTTPConnection *> connectionPool;
vlc_object_t *stream;
- HTTPConnection * getConnectionForHost (const std::string &hostname);
+ HTTPConnection * getConnection(const std::string &hostname, uint16_t port, int);
};
}
}
diff --git a/modules/demux/adaptative/http/Sockets.cpp b/modules/demux/adaptative/http/Sockets.cpp
index 50c5e69..3c0b1ab 100644
--- a/modules/demux/adaptative/http/Sockets.cpp
+++ b/modules/demux/adaptative/http/Sockets.cpp
@@ -27,6 +27,13 @@ using namespace adaptative::http;
Socket::Socket()
{
netfd = -1;
+ type = REGULAR;
+}
+
+Socket::Socket( int type_ )
+{
+ netfd = -1;
+ type = type_;
}
Socket::~Socket()
@@ -44,6 +51,11 @@ bool Socket::connect(vlc_object_t *stream, const std::string &hostname, int port
return true;
}
+int Socket::getType() const
+{
+ return type;
+}
+
bool Socket::connected() const
{
return (netfd != -1);
@@ -89,7 +101,7 @@ bool Socket::send(vlc_object_t *stream, const void *buf, size_t size)
return net_Write(stream, netfd, buf, size) == (ssize_t)size;
}
-TLSSocket::TLSSocket() : Socket()
+TLSSocket::TLSSocket() : Socket( TLS )
{
creds = NULL;
tls = NULL;
diff --git a/modules/demux/adaptative/http/Sockets.hpp b/modules/demux/adaptative/http/Sockets.hpp
index fbf2d97..09608d7 100644
--- a/modules/demux/adaptative/http/Sockets.hpp
+++ b/modules/demux/adaptative/http/Sockets.hpp
@@ -43,9 +43,13 @@ namespace adaptative
virtual ssize_t read (vlc_object_t *, void *p_buffer, size_t len);
virtual std::string readline(vlc_object_t *);
virtual void disconnect ();
+ int getType() const;
+ static const int REGULAR = 0;
protected:
+ Socket( int );
int netfd;
+ int type;
};
class TLSSocket : public Socket
@@ -59,6 +63,7 @@ namespace adaptative
virtual ssize_t read (vlc_object_t *, void *p_buffer, size_t len);
virtual std::string readline(vlc_object_t *);
virtual void disconnect ();
+ static const int TLS = REGULAR + 1;
private:
vlc_tls_creds_t *creds;
More information about the vlc-commits
mailing list