Refine the local socket closing logic

This commit is contained in:
Max Lv
2017-12-06 02:42:59 -08:00
parent f870093c94
commit 07a48bc20b
3 changed files with 32 additions and 11 deletions
@@ -70,4 +70,5 @@ public class JniHelper {
private static native Object getExitValueMutex(Process process);
public static native int sendFd(int fd, String path);
public static native void close(int fd);
public static native void unlink(String path);
}
+6
View File
@@ -72,6 +72,12 @@ JNIEXPORT void JNICALL Java_com_github_shadowsocks_JniHelper_close(JNIEnv *env,
close(fd);
}
JNIEXPORT void JNICALL Java_com_github_shadowsocks_JniHelper_unlink(JNIEnv *env, jobject thiz, jstring path) {
const char *sock_str = env->GetStringUTFChars(path, 0);
unlink(sock_str);
env->ReleaseStringUTFChars(path, sock_str);
}
JNIEXPORT jint JNICALL
Java_com_github_shadowsocks_JniHelper_sendFd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) {
int fd;