[问题] 如何定位NDK Block issue

楼主: windows2k (程式宅 <囧>)   2018-10-20 11:29:10
这问题有点难描述...不是Crash, 所以不能用ndk-stack下去看
而是Native code的程式码被Blocked住了
同样的程式码, 在Android 6之前都运行正常, 在Android 7之后就出现了
由于是Linux based, Linux 我试不出来此Bug
程式码逻辑大概是这样
开一个 listen socket -> 设成 NonBlocking Mode
epoll -> 得到一个 Read Event -> Accept new socket
程式码来自于知名Network Library, 我想错误的机率不大
经过夹击之后, 我发现问题可能出在 Accept new socket这部分
Accept前后程式码没有System call, 并且没有Blocking的可能
根据 Linux Manual 上所写
If no pending connections are present on the queue, and the socket is not
marked as nonblocking, accept() blocks the caller until a connection is
present. If the socket is marked nonblocking and no pending connections are
present on the queue, accept() fails with the error EAGAIN or EWOULDBLOCK.
理论上根本不会有问题...
于是作了以下尝试
1. 在Accept之前再次将 Socket 设成 non-blocking => 没用
2. 在Accept前后加上 __android_log_print 做夹击 => 做不出来, 但不是我想要的解法
我的问题主要有两个
1. 如何证明 accept 会卡住
2. 如何避开这个问题
卡关了很久, 希望有人给我一点想法吧, 谢谢
作者: uorol (′‧ω‧‵)   2018-10-20 12:56:00
你的问题是accept()之后要再accept()新的socket时卡住?
楼主: windows2k (程式宅 <囧>)   2018-10-20 14:52:00
是epoll_wait丢出一个pollin event, 然后accept卡住不过这是只有在程式运行途中wifi关掉的情况下做出kernel中accept那段程式码跟wifi没关系就是了

Links booklink

Contact Us: admin [ a t ] ucptt.com