Bug 1501148 - Replace int (fd) assumptions with portable PlatformHandleType. r=chunmin
authorMatthew Gregan <kinetik@flim.org>
Tue, 23 Oct 2018 16:27:58 +1300
changeset 490749 1e036ba2e247a79a10dc8f6841b2992aafd711e4
parent 490748 ce374302821c1a202263562910e7888ed455f5d8
child 490750 69e4a961b4e4b21548dba0c2f3a80e216258fb50
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerschunmin
bugs1501148
milestone65.0a1
Bug 1501148 - Replace int (fd) assumptions with portable PlatformHandleType. r=chunmin
dom/media/CubebUtils.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -53,18 +53,20 @@
 #define PREF_AUDIOIPC_STACK_SIZE "media.audioipc.stack_size"
 
 #if (defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID)) || defined(XP_MACOSX)
 #define MOZ_CUBEB_REMOTING
 #endif
 
 extern "C" {
 
+// This must match AudioIpcInitParams in media/audioipc/client/src/lib.rs.
+// TODO: Generate this from the Rust definition rather than duplicating it.
 struct AudioIpcInitParams {
-  int mServerConnection;
+  mozilla::ipc::FileDescriptor::PlatformHandleType mServerConnection;
   size_t mPoolSize;
   size_t mStackSize;
   void (*mThreadCreateCallback)(const char*);
 };
 
 // These functions are provided by audioipc-server crate
 extern void* audioipc_server_start();
 extern mozilla::ipc::FileDescriptor::PlatformHandleType audioipc_server_new_client(void*);
@@ -406,19 +408,29 @@ void InitAudioIPCConnection()
                 });
 }
 #endif
 
 ipc::FileDescriptor CreateAudioIPCConnection()
 {
 #ifdef MOZ_CUBEB_REMOTING
   MOZ_ASSERT(sServerHandle);
-  int rawFD = audioipc_server_new_client(sServerHandle);
+  ipc::FileDescriptor::PlatformHandleType rawFD = audioipc_server_new_client(sServerHandle);
   ipc::FileDescriptor fd(rawFD);
+  if (!fd.IsValid()) {
+    MOZ_LOG(gCubebLog, LogLevel::Error, ("audioipc_server_new_client failed"));
+    return ipc::FileDescriptor();
+  }
+  // Close rawFD since FileDescriptor's ctor cloned it.
+  // TODO: Find cleaner cross-platform way to close rawFD.
+#ifdef XP_WIN
+  CloseHandle(rawFD);
+#else
   close(rawFD);
+#endif
   return fd;
 #else
   return ipc::FileDescriptor();
 #endif
 }
 
 cubeb* GetCubebContextUnlocked()
 {