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!谢谢
您可能也喜欢:
谢谢!
2015-03-20 11:06
回复
uuy
博主,坚持更新高质量博文,持续关注
2015-03-19 23:16
回复
@uuy:会的!
2015-03-20 11:06
回复
testify
很好?持续更新
2015-03-19 22:26
回复
@testify:会的
2015-03-20 11:06
回复
5
持续关注
2015-03-19 20:30
回复
@5:谢谢
2015-03-20 11:07
回复
发表评论:
发布
Hi,您需要填写昵称和邮箱!
必填项
必填项