⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_tcp_clt3.c

📁 T-kernel Tcp/ip Protocol Stack Sample
💻 C
字号:
/* *  Copyright (C) 1999-2003 MITSUBISHI ELECTRIC CORPORATION and *  RENESAS SOLUTIONS CORPORATION and *  RENESAS TECHNOLOGY CORPORATION *  All rights reserved. * *  BSD socket communication test program used for TCP/IP subsystem. */#include <tk/tkernel.h>#include <renesas_tcpip.h>#include <renesas_tcpip_common.h>#include "config.h"static int comm_size[] = {	1, 2, 4, 10, 16, 30, 32, 50, 64, 100, 128, 200, 256, 500, 512,	1000, 1024, 2000, 2048, 4000, 4096, 8000, 8192, 16000, 16384,	32000, 32768, 64000, 65536};/* TCP client test () */voidtest_task(int stacd, void *exinf){        	int i, j, k, sd, newsd, len, size, total;	char ch, buf[SIZE2];	struct sockaddr_in sinme, sindst;	int stepno, testno, testno2, result[31];	testno = 0;	testno2 = sizeof(comm_size)/sizeof(comm_size[0]);	memset((char *)result, 0, sizeof(result));for (testno=1; testno <= sizeof(comm_size)/sizeof(comm_size[0]); testno++) {	size = comm_size[testno -1];stepno = 1;	memset((char *)&sindst, 0, sizeof(struct sockaddr_in));	sindst.sin_family = AF_INET;	sindst.sin_addr.s_addr = inet_addr(DST_IPADDR);	sindst.sin_port = htons(DST_PORTNO);	for (j=0; j < LOOP; j++) {stepno = 2;		if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {			break;		}stepno = 3;		if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) {			unix_close(sd);			break;		}		ch = 'a';		memset(buf, ch, size);stepno = 4;		if ((len = unix_send(sd, buf, size, 0)) < 0) {			unix_close(sd);			break;		}		memset(buf, 0, size);		total = 0;		while (total < size) {stepno = 5;			if ((len = unix_recv(sd, buf, size, 0)) < 0) {				unix_close(sd);				break;			}			total += len;			/* check data contents */			for (i=0; i < len; i++) {				if (buf[i] != ch) {					break;				}			}			if (i < len) {stepno = 6;				unix_close(sd);				goto err;			}		}		if (total != size) {stepno = 7;			unix_close(sd);			break;		}stepno = 8;		if (unix_shutdown(sd, 0) < 0) {			unix_close(sd);			break;		}stepno = 9;		if (unix_close(sd) < 0) {			break;		}		/* sleep 1 second */#if defined(T_KERNEL)		tk_slp_tsk(1000);#endif	}err:	if (stepno == 9) {#if defined(PRINTF_ON)		printf("Pass. (size=%d)\n", size);#endif		result[testno] = 0;	}	else {#if defined(PRINTF_ON)		printf("Error at stepno-%d.\n", stepno);#endif		result[testno] = 1;		break;	}#if defined(T_KERNEL)	tk_slp_tsk(2000);#endif}	if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {		goto err2;	}	if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) {		goto err2;	}	if (unix_send(sd, buf, 0, 0) < 0) {		goto err2;	}	if (unix_shutdown(sd, 0) < 0) {		goto err2;	}err2:	unix_close(sd);#if defined(T_KERNEL)	tk_slp_tsk(1000);#endif	for (i=1; i <= testno; i++) {		if (result[i] == 1)			break;	}#if defined(PRINTF_ON)	if (i > testno2)		printf("All of Pass.\n");	else		printf("Error at testno-%d.\n", i);#endif#if defined(T_KERNEL)	tk_slp_tsk(TMO_FEVR);#endif}/* EOF */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -