From e16f1d8bdd096c055a699822a249eae2b72fe6a1 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Mon, 28 Nov 2011 12:18:03 +0000 Subject: [PATCH] Timeout if the spotify client hasn't connected to the tcpsrc within 5 seconds. --- gst/spotifytcpsrc/gstspotifytcpsrc.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gst/spotifytcpsrc/gstspotifytcpsrc.cpp b/gst/spotifytcpsrc/gstspotifytcpsrc.cpp index 18c6d5d0a..7efdb244b 100644 --- a/gst/spotifytcpsrc/gstspotifytcpsrc.cpp +++ b/gst/spotifytcpsrc/gstspotifytcpsrc.cpp @@ -35,6 +35,7 @@ static const int kPollTimeoutMsec = 100; +static const int kMaxConnectionWaits = 50; // each one takes kPollTimeoutMsec // This is about one second of audio at spotify's bitrate. static const int kSocketBufferSize = 176400; @@ -231,11 +232,18 @@ static gboolean gst_spotifytcp_src_start(GstBaseSrc* src) { server->StartPlayback(QString::fromAscii(*self->uri_), self->server_->serverPort()); // Wait for a client to connect + int attempts = 0; while (!self->server_->waitForNewConnection(kPollTimeoutMsec)) { if (self->unlock_) { qLog(Warning) << "Unlock while waiting for connection"; return FALSE; } + + ++attempts; + if (attempts > kMaxConnectionWaits) { + qLog(Warning) << "Timed out waiting for connection"; + return FALSE; + } } // Take the socket