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

📄 t_tcp_clt2.c

📁 T-kernel Tcp/ip Protocol Stack Sample
💻 C
字号:
/* *  Copyright (C) 1999-2006 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"/* TCP client test (unix_connect/unix_write/unix_read for LOOP times) */voidtest_task(int stacd, void *exinf){        	int i, j, sd, newsd, len;	char ch, buf[SIZE], buf2[SIZE];	struct sockaddr_in sinme, sindst;	ch = 'A' - 0x01;	for (i=0; i < sizeof(buf); i++) {		if (ch < 'z') ch += 0x01;		else ch = 'A';		buf[i] = ch;	}	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++) {		if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {			break;		}		if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) {			unix_close(sd);			break;		}		if ((len = unix_write(sd, buf, sizeof(buf))) < 0) {			unix_close(sd);			break;		}		memset(buf2, 0, sizeof(buf2));		if ((len = unix_read(sd, buf2, sizeof(buf2))) < 0) {			unix_close(sd);			break;		}		/* check data contents */		for (i=0; i < len; i++) {			if (buf2[i] != buf[i]) {				break;			}		}		if (i < len) {			unix_close(sd);			break;		}		if (unix_shutdown(sd, 0) < 0) {			unix_close(sd);			break;		}		unix_close(sd);		/* sleep 1 second */#if defined(T_KERNEL)		tk_slp_tsk(1000);#endif	}	if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {		goto err;	}	if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) {		unix_close(sd);		goto err;	}	if (unix_write(sd, buf, 0) < 0) {		unix_close(sd);		goto err;	}	if (unix_shutdown(sd, 0) < 0) {		unix_close(sd);		goto err;	}	unix_close(sd);#if defined(T_KERNEL)	tk_slp_tsk(1000);#endiferr:#if defined(T_KERNEL)	tk_slp_tsk(TMO_FEVR);#endif}/* EOF */

⌨️ 快捷键说明

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