JNIEXPORT jint JNICALL setFd(
		JNIEnv *env, jobject obj, jobject socket) {

	JNIEnv e = *env;
	jclass clazz;
	jfieldID fid;
	jobject impl;
	jobject fdesc;
	/* get the SocketImpl from the Socket */
	if (!(clazz = e->GetObjectClass(env, socket))
			|| !(fid = e->GetFieldID(env, clazz, "impl",
					"Ljava/net/SocketImpl;"))
			|| !(impl = e->GetObjectField(env, socket, fid)))
		return -1;
	/* get the FileDescriptor from the SocketImpl */
	if (!(clazz = e->GetObjectClass(env, impl))
			|| !(fid = e->GetFieldID(env, clazz, "fd",
					"Ljava/io/FileDescriptor;"))
			|| !(fdesc = e->GetObjectField(env, impl, fid)))
		return -1;
	/* get the fd from the FileDescriptor */
	if (!(clazz = e->GetObjectClass(env, fdesc))
			|| !(fid = e->GetFieldID(env, clazz, "descriptor", "I")))
		return -1;
	/* return the descriptor*/
	jint fd= e->GetIntField(env, fdesc, fid);
	LOGE("fd=%d",fd);
	set_sock_fd((int) fd);
	return 0;
}
 
如有问题欢迎访问我的主页www.sitcoder.com 加我QQ!谢谢
  • 谢谢!

  • uuy

    博主,坚持更新高质量博文,持续关注

  • testify

    很好?持续更新

  • 5

    持续关注

  • 
    
    	
    色迷迷 哭 呕吐 大笑 口水 微笑 啵一个 发怒

    Hi,您需要填写昵称和邮箱!

    • 必填项
    • 必填项