diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/HTTPStream.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/media/libstagefright/HTTPStream.cpp b/media/libstagefright/HTTPStream.cpp index d216ef2..2caf211 100644 --- a/media/libstagefright/HTTPStream.cpp +++ b/media/libstagefright/HTTPStream.cpp @@ -237,31 +237,41 @@ status_t HTTPStream::connect(const char *server, int port, bool https) { } CHECK_EQ(mSocket, -1); - mSocket = socket(ai[0].ai_family, ai[0].ai_socktype, ai[0].ai_protocol); - if (mSocket < 0) { - freeaddrinfo(ai); - return UNKNOWN_ERROR; - } + mState = CONNECTING; + status_t res = -1; + struct addrinfo *tmp; + for (tmp = ai; tmp; tmp = tmp->ai_next) { + mSocket = socket(tmp->ai_family, tmp->ai_socktype, tmp->ai_protocol); + if (mSocket < 0) { + continue; + } - setReceiveTimeout(30); // Time out reads after 30 secs by default + setReceiveTimeout(30); // Time out reads after 30 secs by default. - mState = CONNECTING; + int s = mSocket; - int s = mSocket; + mLock.unlock(); - mLock.unlock(); + res = MyConnect(s, tmp->ai_addr, tmp->ai_addrlen); - status_t res = MyConnect(s, ai[0].ai_addr, ai[0].ai_addrlen); + mLock.lock(); - freeaddrinfo(ai); + if (mState != CONNECTING) { + close(s); + freeaddrinfo(ai); + return UNKNOWN_ERROR; + } - mLock.lock(); + if (res == OK) { + break; + } - if (mState != CONNECTING) { - return UNKNOWN_ERROR; + close(s); } + freeaddrinfo(ai); + if (res != OK) { close(mSocket); mSocket = -1; |