----------------------------------------------------------------------------
然后在 lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset){} 的这里加了一行打印:
rt_kprintf("hello I/m here------------------->\n\r");
------------------------------------------------------------------------------
static int
lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
{
int i, nready = 0;
fd_set lreadset, lwriteset, lexceptset;
struct lwip_socket *p_sock;
FD_ZERO(&lreadset);
FD_ZERO(&lwriteset);
FD_ZERO(&lexceptset);
/* Go through each socket in each list to count number of sockets which
currently match */
for(i = 0; i < maxfdp1; i++) {
if (FD_ISSET(i, readset)) {
/* See if netconn of this socket is ready for read */
//这里是我自己添加的 add by myself
rt_kprintf("hello I/m here------------------->\n\r");
p_sock = get_socket(i);
if (p_sock && (p_sock->lastdata || (p_sock->rcvevent > 0))) {
FD_SET(i, &lreadset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i));
nready++;
//这里是我自己添加的 add by myself
rt_kprintf(""lwip_selscan: ready for reading\n\r");
}
}
if (FD_ISSET(i, writeset)) {
/* See if netconn of this socket is ready for write */
p_sock = get_socket(i);
if (p_sock && p_sock->sendevent) {
FD_SET(i, &lwriteset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i));
nready++;
}
}
}
*readset = lreadset;
*writeset = lwriteset;
FD_ZERO(exceptset);
return nready;
}
--------------------------------------------------------------------
但是最后发现,客户端连上以后,通过串口打印,根本就不执行 rt_kprintf("hello I/m here------------------->\n\r");也就是FD_ISSET()测试失败,然后就执行下面去了。最后就导致了 select()返回为0.
===========
如果,我去掉 if (FD_ISSET(i, readset)) 这个约束条件后,程序能够执行 rt_kprintf("hello I/m here------------------->\n\r");和 rt_kprintf(""lwip_selscan: ready for reading\n\r"); 通过串口打印,我已经观察到了这两个打印。
------
像这样:
------
for(i = 0; i < maxfdp1; i++) {
// if (FD_ISSET(i, readset)) {
/* See if netconn of this socket is ready for read */
rt_kprintf("hello I/m here------------------->\n\r");
p_sock = get_socket(i);
if (p_sock && (p_sock->lastdata || (p_sock->rcvevent > 0))) {
FD_SET(i, &lreadset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i));
nready++;
rt_kprintf(""lwip_selscan: ready for reading\n\r");
}
// }
if (FD_ISSET(i, writeset)) {
/* See if netconn of this socket is ready for write */
p_sock = get_socket(i);
if (p_sock && p_sock->sendevent) {
FD_SET(i, &lwriteset);
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i));
nready++;
}
}
}
----------
由于MDK没找到 FD_ISSET()的实现,不知道为什么无法检测到呢
THX !