am 8df2477c: am bd0e806a: Support IPv6->IPv4 fallback in HTTP streaming.
* commit '8df2477c4e7e5bf72d6d1216ae5184c53304470e':
Support IPv6->IPv4 fallback in HTTP streaming.
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 @@
}
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;
- }
-
- setReceiveTimeout(30); // Time out reads after 30 secs by default
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;
+ }
- int s = mSocket;
+ setReceiveTimeout(30); // Time out reads after 30 secs by default.
- mLock.unlock();
+ int s = mSocket;
- status_t res = MyConnect(s, ai[0].ai_addr, ai[0].ai_addrlen);
+ mLock.unlock();
+
+ res = MyConnect(s, tmp->ai_addr, tmp->ai_addrlen);
+
+ mLock.lock();
+
+ if (mState != CONNECTING) {
+ close(s);
+ freeaddrinfo(ai);
+ return UNKNOWN_ERROR;
+ }
+
+ if (res == OK) {
+ break;
+ }
+
+ close(s);
+ }
freeaddrinfo(ai);
- mLock.lock();
-
- if (mState != CONNECTING) {
- return UNKNOWN_ERROR;
- }
-
if (res != OK) {
close(mSocket);
mSocket = -1;