在线时间0 小时
UID109929
注册时间2009-2-17
NXP金币0
该用户从未签到
新手上路

- 积分
- 35
- 最后登录
- 1970-1-1
|
新人,请教,MQX中如果判断网络是通的还是断的,我的程序运行时,网线拔了很长时间才能判断出网络断了。我程序的初始化代码如下:
if( RTCS_OK != RTCS_create() )
{
InUartPrint( "\nRTCS Create Error!\n", strlen( "\nRTCS Create Error!\n" ) );
_mqx_exit( -1 );
}
if( ENET_OK!= ENET_initialize( BSP_DEFAULT_ENET_DEVICE, m_enetaddress, 0, &m_hEnet ) )
{
InUartPrint( "\nEnet Initial Error!\n", strlen( "\nEnet Initial Error!\n" ) );
_mqx_exit( -1 );
}
if( RTCS_OK != RTCS_if_add( m_hEnet, RTCS_IF_ENET, &m_hRtcsIf ) )
{
InUartPrint( "\nRtcs If Add Error!\n", strlen( "\nRtcs If Add Error!\n" ) );
_mqx_exit( -1 );
}
if( RTCS_OK != RTCS_if_bind( m_hRtcsIf, m_ui32IpAddress, m_ui32Mask ) )
{
InUartPrint( "\nRtcs If Bind Error!\n", strlen( "\nRtcs If Bind Error!\n" ) );
_mqx_exit( -1 );
}
if( RTCS_OK != RTCS_gate_add( m_ui32GateWay, INADDR_ANY, INADDR_ANY ) )
{
InUartPrint( "\nRtcs Gate Add Error!\n", strlen( "\nRtcs Gate Add Error!\n" ) );
_mqx_exit( -1 );
}
InUartPrint( "Waiting Fec Cable Plug In...\n", strlen( "Waiting Fec Cable Plug In...\n" ) );
while( !ENET_link_status( m_hEnet ) ); 这里面网线插不插都能直接过去,郁闷。。。
InUartPrint( "Fec Cable connected!\n", strlen( "Fec Cable connected!\n" ) );
m_hSockServer = socket( PF_INET, SOCK_STREAM, 0 );
if( m_hSockServer == RTCS_SOCKET_ERROR )
{
InUartPrint( "\nServer Socket Create Error!\n", strlen( "\nServer Socket Create Error!\n" ) );
_mqx_exit( -1 );
}
m_ui32Temp = 3000; 这里面的值怎么改都没用
if( RTCS_OK != setsockopt( m_hSockServer, SOL_TCP, OPT_CONNECT_TIMEOUT, &m_ui32Temp, sizeof( m_ui32Temp ) ) )
{
InUartPrint( "\nSet Socket Opt OPT_CONNECT_TIMEOUT Error!\n", strlen( "\nSet Socket Opt OPT_CONNECT_TIMEOUT Error!\n" ) );
}
m_ui32Temp = 0; 这里面的值怎么改也没用
if( RTCS_OK != setsockopt( m_hSockServer, SOL_TCP, OPT_KEEPALIVE, &m_ui32Temp, sizeof( m_ui32Temp ) ) )
{
InUartPrint( "\nSet Socket Opt OPT_KEEPALIVE Error!\n", strlen( "\nSet Socket Opt OPT_KEEPALIVE Error!\n" ) );
}
再往下就是开读、写、工作线程,读线程在网线断很久后才能返回错误。
m_ui32RecvDataCount = recv( m_ptrFecData->m_hSockClient, m_ptrFecData->m_ptrReadTempBuffer, sizeof( PcFecDataStyle ), 0 );
if( m_ui32RecvDataCount == RTCS_ERROR )
{
就是这儿,网络断了很久才能进到这里面,不明白为什么?
break;
}
网络芯片用的是ksz8041nl
请版主指教,非常感谢!
|
|