[Live-devel] Can't play RTSP streams on some Android devices (LibVLC). "setsockopt(SO_REUSEPORT) error: Protocol not available"

Mirco Pazzaglia mirco.pazzaglia at inim.biz
Mon Dec 23 05:34:29 PST 2019


>> Wouldn't it be better though to add a runtime check for compatibility in the cpp code
> What would that look like??

Perhaps it could look something like this:

--- a/groupsock/GroupsockHelper.cpp
+++ b/groupsock/GroupsockHelper.cpp
@@ -121,11 +121,16 @@
   // Windoze doesn't properly handle SO_REUSEPORT or IP_MULTICAST_LOOP
 #else
 #ifdef SO_REUSEPORT
-  if (setsockopt(newSocket, SOL_SOCKET, SO_REUSEPORT,
-		 (const char*)&reuseFlag, sizeof reuseFlag) < 0) {
-    socketErr(env, "setsockopt(SO_REUSEPORT) error: ");
-    closeSocket(newSocket);
-    return -1;
+  int checkReuseFlag;
+  int checkReuseFlagLen = sizeof checkReuseFlag;
+  if (getsockopt(newSocket, SOL_SOCKET, SO_REUSEPORT,
+     &checkReuseFlag, &checkReuseFlagLen) == 0) {
+    if (setsockopt(newSocket, SOL_SOCKET, SO_REUSEPORT,
+       (const char*)&reuseFlag, sizeof reuseFlag) < 0) {
+      socketErr(env, "setsockopt(SO_REUSEPORT) error: ");
+      closeSocket(newSocket);
+      return -1;
+    }
   }
 #endif

By ensuring with a getsockopt that there are no errors with such socket option. (Code could be improved)
Also, if it is correct, this type of check could be done for other socket options used in the code.




More information about the live-devel mailing list