📄 noncopytcptestee.c
字号:
printf("Network Added: ");
else
printf("Network Removed: ");
// Print a message
IPTmp = ntohl( IPAddr );
printf("If-%d:%d.%d.%d.%d\n", IfIdx,
(UINT8)(IPTmp>>24)&0xFF, (UINT8)(IPTmp>>16)&0xFF,
(UINT8)(IPTmp>>8)&0xFF, (UINT8)IPTmp&0xFF );
TSK_sleep(100);
}
//
// Service Status Reports
//
// Here's a quick example of using service status updates
//
static char *TaskName[] = { "Telnet","HTTP","NAT","DHCPS","DHCPC","DNS" };
static char *ReportStr[] = { "","Running","Updated","Complete","Fault" };
static char *StatusStr[] = { "Disabled","Waiting","IPTerm","Failed","Enabled" };
static void ServiceReport( uint Item, uint Status, uint Report, HANDLE h )
{
printf( "Service Status: %-9s: %-9s: %-9s: %03d\n",
TaskName[Item-1], StatusStr[Status],
ReportStr[Report/256], Report&0xFF );
//
// Example of adding to the DHCP configuration space
//
// When using the DHCP client, the client has full control over access
// to the first 256 entries in the CFGTAG_SYSINFO space.
//
// Note that the DHCP client will erase all CFGTAG_SYSINFO tags except
// CFGITEM_DHCP_HOSTNAME. If the application needs to keep manual
// entries in the DHCP tag range, then the code to maintain them should
// be placed here.
//
// Here, we want to manually add a DNS server to the configuration, but
// we can only do it once DHCP has finished its programming.
//
if( Item == CFGITEM_SERVICE_DHCPCLIENT &&
Status == CIS_SRV_STATUS_ENABLED &&
(Report == (NETTOOLS_STAT_RUNNING|DHCPCODE_IPADD) ||
Report == (NETTOOLS_STAT_RUNNING|DHCPCODE_IPRENEW)) )
{
IPN IPTmp;
// Manually add the DNS server when specified
IPTmp = inet_addr(DNSServer);
if( IPTmp )
CfgAddEntry( 0, CFGTAG_SYSINFO, CFGITEM_DHCP_DOMAINNAMESERVER,
0, sizeof(IPTmp), (UINT8 *)&IPTmp, 0 );
}
}
//
// TCP Transmit Server Daemon Function
// (SOCK_STREAM @ port 1000)
//
int dtask_tcp_transmit_srv( SOCKET s, UINT32 unused )
{
struct timeval to;
int i, size, count, bytes;
UINT32 ts, tsMsec, ts1, ts1Msec, startMsec, endMsec;
UINT32 tn, totalBytes;
LgUns totalTime;
LgUns tskTime;
Uns load;
(void)unused;
// Configure our socket timeout to be 5 seconds
to.tv_sec = 5;
to.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
i = 1;
setsockopt( s, IPPROTO_TCP, TCP_NOPUSH, &i, 4 );
totalBytes = 0;
// There is data available on the active connection
i = (int)recv( s, (char *)&size, sizeof(int), 0 );
// Get timestamp
llEnter();
ts = llTimerGetTime(&tsMsec);
llExit();
for (count = 0; count < BENCH_FRAMES; count ++) {
if( i== sizeof(int) ) {
bytes = send( s, (char *)&size, size, 0 );
totalBytes = totalBytes + bytes;
if( bytes <= 0 ) {
printf("send failed\n");
goto leave;
}
}
else {
goto leave;
}
// Get TSK_idle time to compute CPU load half-way through
// number of packets transfers
if ( loop == count) {
THRLOAD_getTskTime(&TSK_idle, &tskTime, &totalTime);
}
}
// Get timestamp again!!
llEnter();
ts1 = llTimerGetTime(&ts1Msec);
llExit();
// Compute CPU load
load = 100 - tskTime / (totalTime / 100);
// Compute total time in milliseconds
startMsec = (ts * 1000) + tsMsec;
endMsec = (ts1 * 1000) + ts1Msec;
tn = endMsec - startMsec;
#ifdef BENCH_CSV
printf("Transmit,%d,%u,%d\n", size, ((totalBytes*8)/tn), load );
#else
printf("Transmitted %d frames of %d bytes for a total of %u\n", count, size, totalBytes);
printf("at a rate of %u kb/s with a CPU load of %d%%\n\n", ((totalBytes*8)/tn), load);
#endif
#ifdef _64P_
/* Write back and invalidate all cache for C64P devices */
BCACHE_wbInvAll();
#else
CACHE_clean(CACHE_L2ALL, 0, 0);
#endif
leave:
// Return "1" since the socket is still open
return(1);
}
//
// TCP Receive Server Daemon Function
// (SOCK_STREAMNC @ port 1001)
//
int dtask_tcp_receive_srv( SOCKET s, UINT32 unused )
{
struct timeval to;
char *pBuf;
HANDLE hBuffer;
UINT32 tsMsec, ts1Msec, startMsec, endMsec;
UINT32 ts, ts1, tn, totalBytes;
int bytes, count, i, size, cache;
LgUns totalTime;
LgUns tskTime;
Uns load;
(void)unused;
//THRLOAD_update();
// Configure our socket timeout to be 5 seconds
to.tv_sec = 5;
to.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
// Check for data size on the active connection
(int)recv( s, (char *)&size, sizeof(int), 0 );
totalBytes = 0;
// Get timestamp
llEnter();
ts = llTimerGetTime(&tsMsec);
llExit();
// Process all data for expected frames
for (count = 0; count < BENCH_FRAMES; count++ ) {
i = 0;
while (i < (int)size) {
// There is data available on the active connection
bytes = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );
// If the connection is closed or got an error, break
if (bytes <= 0) {
break;
}
else {
recvncfree( hBuffer );
}
i += bytes;
}
// Accumulate total bytes received
totalBytes += i;
// If the connection is closed or got an error, break
if (bytes <= 0) {
break;
}
// Get TSK_idle time to compute CPU load half-way through
// number of packets transfers
if ( loop == count) {
THRLOAD_getTskTime(&TSK_idle, &tskTime, &totalTime);
}
}
// Get timestamp again!!
llEnter();
ts1 = llTimerGetTime(&ts1Msec);
llExit();
// Compute CPU load
load = 100 - tskTime / (totalTime / 100);
// Compute total time in milliseconds
startMsec = (ts * 1000) + tsMsec;
endMsec = (ts1 * 1000) + ts1Msec;
tn = endMsec - startMsec;
if (flag == FALSE) {
flag = TRUE;
#ifdef _64P_
switch ( bcacheSize.l2size ) {
case BCACHE_L2_0K :
cache = 0;
break;
case BCACHE_L2_32K :
cache = 32;
break;
case BCACHE_L2_64K :
cache = 64;
break;
case BCACHE_L2_128K :
cache = 128;
break;
case BCACHE_L2_256K :
cache = 256;
break;
default:
printf("Unknown cache setup\n");
}
#else // DM642
switch (l2CacheSize) {
case CACHE_0KCACHE :
cache = 0;
break;
case CACHE_32KCACHE :
cache = 32;
break;
case CACHE_64KCACHE :
cache = 64;
break;
case CACHE_128KSRAM :
cache = 128;
break;
case CACHE_256KCACHE :
cache = 256;
break;
default:
printf("Unknown cache setup\n");
}
#endif
#ifdef BENCH_CSV
printf("DSP Operating at %u MHz with %dk L2 Cache \n", GBL_getFrequency()/1000, cache );
printf("Results are shown as:\n");
printf("Operation,Frame Size(bytes),Measured throughput(kbits/sec),CPU Load(+/-1%%)\n");
}
printf ("Receive,%d,%u,%d\n",size,(totalBytes*8)/tn , load);
#else
printf("DSP Operating at %u MHz with %dk L2 Cache \n\n", GBL_getFrequency()/1000, cache );
}
printf ("Received packets of %d bytes for a total of %u bytes \n",size, totalBytes);
printf ("for a throughput of %u kb/s at a CPU load of %d%% \n\n", (((totalBytes/tn)*1000)*8)/1000, load);
#endif
#ifdef _64P_
/* Write back and invalidate all cache for C64P devices */
BCACHE_wbInvAll();
#else
CACHE_clean(CACHE_L2ALL, 0, 0);
#endif
// Return "1" since the socket is still open
return(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -