ipc/android: Dup the socket fd in native side, close the fd on java side.

This commit is contained in:
zhibinw 2021-04-06 17:59:50 +08:00 committed by Ryan Pavlik
parent e7f82c297a
commit d7f0380f53
2 changed files with 16 additions and 2 deletions
src/xrt/ipc
android/src/main/java/org/freedesktop/monado/ipc
client

View file

@ -100,8 +100,14 @@ public class Client implements ServiceConnection {
}
intent = null;
//! @todo do we close this first?
fd = null;
if (fd != null) {
try {
fd.close();
} catch (IOException e) {
e.printStackTrace();
}
fd = null;
}
}
/**

View file

@ -28,6 +28,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/un.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
@ -91,6 +92,13 @@ ipc_connect(struct ipc_connection *ipc_c)
IPC_ERROR(ipc_c, "Service Connect error!");
return false;
}
// The ownership belongs to the Java object. Dup because the fd will be
// closed when client destroy.
socket = dup(socket);
if (socket < 0) {
IPC_ERROR(ipc_c, "Failed to dup fd with error %d!", errno);
return false;
}
ipc_c->imc.socket_fd = socket;
ipc_c->imc.ll = ipc_c->ll;