This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

connect无反应



EVM6678le CCS5.3  导入例程D:\ti\BIOS_MCSDK_02_01_02_06_p1\mcsdk_2_01_02_06\examples\ndk\helloWorld\evmc6678l

原程序已经调通..但我不想用TI 本身的SERVER SUITE

想自己直接写SOCKET

修改代码如下.


int connect_nonb(SOCKET s, PSA sin, int msecs)
{
int nonb;
fd_set fdset;
struct timeval tv;

nonb = 0;
if ( setsockopt( s, SOL_SOCKET, SO_BLOCKING, (void*)&nonb, sizeof( int ) ) != 0 )
{
return -1;
}

if ( connect( s, ( PSA ) sin, sizeof( struct sockaddr ) ) != 0 )
{
FD_ZERO( &fdset );
FD_SET( s, &fdset );

tv.tv_sec = msecs / 1000;
tv.tv_usec = (msecs % 1000) * 1000;
if ( fdSelect( 0, 0, &fdset, 0, &tv ) != 1 )
{
return -1;
}
}

nonb = 1;
if ( setsockopt( s, SOL_SOCKET, SO_BLOCKING, (void*)&nonb, sizeof( int ) ) != 0 )
{
return -1;
}

return 0;
}

//
// Main Thread
//
int StackTest()
{
int rc;
int i;
HANDLE hCfg;
QMSS_CFG_T qmss_cfg;
CPPI_CFG_T cppi_cfg;

/* Get information about the platform so we can use it in various places */
memset( ( void* ) &gPlatformInfo, 0, sizeof( platform_info ) );
( void ) platform_get_info( &gPlatformInfo );

( void ) platform_uart_init();
( void ) platform_uart_set_baudrate( 115200 );
( void ) platform_write_configure( PLATFORM_WRITE_ALL );

/* Clear the state of the User LEDs to OFF */
for ( i = 0; i < gPlatformInfo.led[PLATFORM_USER_LED_CLASS].count; i++ )
{
( void ) platform_led( i, PLATFORM_LED_OFF, PLATFORM_USER_LED_CLASS );
}

/* Initialize the components required to run this application:
* (1) QMSS
* (2) CPPI
* (3) Packet Accelerator
*/
/* Initialize QMSS */
if ( platform_get_coreid() == 0 )
{
qmss_cfg.master_core = 1;
}
else
{
qmss_cfg.master_core = 0;
}
qmss_cfg.max_num_desc = MAX_NUM_DESC;
qmss_cfg.desc_size = MAX_DESC_SIZE;
qmss_cfg.mem_region = Qmss_MemRegion_MEMORY_REGION0;
if ( res_mgr_init_qmss ( &qmss_cfg ) != 0 )
{
platform_write ( "Failed to initialize the QMSS subsystem \n" );
goto main_exit;
}
else
{
platform_write ( "QMSS successfully initialized \n" );
}

/* Initialize CPPI */
if ( platform_get_coreid() == 0 )
{
cppi_cfg.master_core = 1;
}
else
{
cppi_cfg.master_core = 0;
}
cppi_cfg.dma_num = Cppi_CpDma_PASS_CPDMA;
cppi_cfg.num_tx_queues = NUM_PA_TX_QUEUES;
cppi_cfg.num_rx_channels = NUM_PA_RX_CHANNELS;
if ( res_mgr_init_cppi ( &cppi_cfg ) != 0 )
{
platform_write ( "Failed to initialize CPPI subsystem \n" );
goto main_exit;
}
else
{
platform_write ( "CPPI successfully initialized \n" );
}


if ( res_mgr_init_pass() != 0 )
{
platform_write ( "Failed to initialize the Packet Accelerator \n" );
goto main_exit;
}
else
{
platform_write ( "PA successfully initialized \n" );
}

//
// THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION before
// using the stack!!
//
rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
if ( rc )
{
platform_write( "NC_SystemOpen Failed (%d)\n", rc );
for ( ;; );
}

// Print out our banner
platform_write( VerStr );

//
// Create and build the system configuration from scratch.
//

//
// THIS MUST BE THE ABSOLUTE FIRST THING DONE IN AN APPLICATION!!
//
rc = NC_SystemOpen( NC_PRIORITY_LOW, NC_OPMODE_INTERRUPT );
if ( rc )
{
printf( "NC_SystemOpen Failed (%d)\n", rc );
for ( ;; );
}

// Print out our banner
printf( VerStr );

//
// Create and build the system configuration from scratch.
//

// Create a new configuration
hCfg = CfgNew();
if ( !hCfg )
{
printf( "Unable to create configuration\n" );
goto main_exit;
}

// We better validate the length of the supplied names
if ( strlen( DomainName ) >= CFG_DOMAIN_MAX ||
strlen( HostName ) >= CFG_HOSTNAME_MAX )
{
printf( "Names too long\n" );
goto main_exit;
}

// Add our global hostname to hCfg (to be claimed in all connected domains)
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_HOSTNAME, 0,
strlen( HostName ), ( UINT8* )HostName, 0 );


//if ( !platform_get_switch_state( 1 ) )
CI_IPNET NA;
CI_ROUTE RT;
IPN IPTmp;

// Setup manual IP address
bzero( &NA, sizeof( NA ) );
NA.IPAddr = inet_addr( LocalIPAddr );
NA.IPMask = inet_addr( LocalIPMask );
strcpy( NA.Domain, DomainName );
//NA.NetType = 0;
NA.NetType = AF_INET;

// Add the address to interface 1
CfgAddEntry( hCfg, CFGTAG_IPNET, 1, 0,
sizeof( CI_IPNET ), ( UINT8* )&NA, 0 );

// Add the default gateway. Since it is the default, the
// destination address and mask are both zero (we go ahead
// and show the assignment for clarity).
bzero( &RT, sizeof( RT ) );
RT.IPDestAddr = 0;
RT.IPDestMask = 0;
RT.IPGateAddr = inet_addr( GatewayIP );

// Add the route
CfgAddEntry( hCfg, CFGTAG_ROUTE, 0, 0,
sizeof( CI_ROUTE ), ( UINT8* )&RT, 0 );

// Manually add the DNS server when specified
IPTmp = inet_addr( DNSServer );
if ( IPTmp )
CfgAddEntry( hCfg, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
0, sizeof( IPTmp ), ( UINT8* )&IPTmp, 0 );

//
// Configure IPStack/OS Options
//

// We don't want to see debug messages less than WARNINGS
rc = DBG_WARN;
CfgAddEntry( hCfg, CFGTAG_OS, CFGITEM_OS_DBGPRINTLEVEL,
CFG_ADDMODE_UNIQUE, sizeof( uint ), ( UINT8* )&rc, 0 );

//
// This code sets up the TCP and UDP buffer sizes
// (Note 8192 is actually the default. This code is here to
// illustrate how the buffer and limit sizes are configured.)
//

// UDP Receive limit
rc = 8192;
CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_SOCKUDPRXLIMIT,
CFG_ADDMODE_UNIQUE, sizeof( uint ), ( UINT8* )&rc, 0 );

//
// Boot the system using this configuration
//
// We keep booting until the function returns 0. This allows
// us to have a "reboot" command.
//
/*do
{
rc = NC_NetStart( hCfg, NetworkOpen, NetworkClose, NetworkIPAddr );
}
while ( rc > 0 );*/


SOCKET s;
struct sockaddr_in sin;
struct timeval tv;
int k, tms, nbytes;


rc = fdOpenSession(TaskSelf());

bzero(&sin, sizeof(struct sockaddr_in));
sin.sin_len = sizeof(struct sockaddr_in);
sin.sin_family = AF_INET;
sin.sin_port = htons( 3456 );
sin.sin_addr.s_addr = inet_addr( "192.168.1.100" );

s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

rc = connect_nonb(s, (PSA)&sin, 1000);
if (rc == 0)
{
tv.tv_sec = 0;
tv.tv_usec = 800000;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, sizeof( tv ) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, sizeof( tv ) );

tms = 0;
for ( k = 0; k < 300; k ++ )
{
nbytes = send(s, (void *)"Hello World!", 12, 0);
if (nbytes <= 0)
{
if (++ tms == 100)
{
break;
}
}
}
}

fdClose(s);

fdCloseSession(TaskSelf());

// Delete Configuration
CfgFree( hCfg );

// Close the OS
main_exit:
NC_SystemClose();
return( 0 );
}

其它没动...每次执行到connect  程序就动不了.....非阻塞也没用