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

📄 t_write.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. * *  TCP/IP Test Application program [API]. */#include <tk/tkernel.h>#include <renesas_tcpip.h>#include <renesas_tcpip_common.h>#include "config.h"EXPORT int printf( const char *format, ... );voidtest_task(int stacd, void *exinf){	int	i, s, s2, ret;	int	len, flags;	struct sockaddr_in name, addr;	int	addrlen, namelen;	char	buf[2048];	int 	num, nonblock, tcpopt;	int testno, testno2, result[8];	num = 1;	testno = 0;	memset((char *)result, 0, sizeof(result));	/* for setup: get normal socket */	errno = 0;	if ((s = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {		printf("socket(AF_INET,SOCK_STREAM,0) fail errno =%d\n",errno);		goto testend;	}	/* Test 1 */	printf("Write Test %d: \n",num++);	errno = 0;testno = 1;	ret = unix_write(s, buf, sizeof(buf));	if (ret < 0) {		printf("OK! :write(s(no connection), buf,2048), ENOTCONN, errno =%d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! :write(s(no connection), buf,2048), ENOTCONN, errno =%d\n",errno);		result[testno] = 1;	}	memset((char *)&name, 0, sizeof(name));	name.sin_family = AF_INET;	name.sin_addr.s_addr = inet_addr(SUN_ADDR);	name.sin_port = htons(SUN_PORT);	namelen = sizeof(name);	errno = 0;	if ((ret = unix_connect(s, (struct sockaddr *)&name, namelen)) < 0) {		printf("connect(s,&name,namelen) fail errno=%d\n",errno);		unix_close(s);		goto testend;	}	/* Test 2 */	printf("Write Test %d: \n",num++);	errno = 0;testno = 2;	ret = unix_write(-1, buf, sizeof(buf));	if (ret < 0) {		printf("OK! :write(-1, buf, 1024*2), EBADF, errno = %d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! :write(-1, buf, 1024*2), EBADF, errno = %d\n",errno);		result[testno] = 1;	}	/* Test 3 */	printf("Write Test %d: \n",num++);	errno = 0;testno = 3;	ret = unix_write(10, buf, sizeof(buf));	if (ret < 0) {		printf("OK! :write(10, buf, 1024*2), EBADF, errno = %d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! :write(10, buf, 1024*2), EBADF, errno = %d\n",errno);		result[testno] = 1;	}	/* Test 4 */	printf("Write Test %d: \n",num++);	errno = 0;testno = 4;	ret = unix_write(s, (char *)NULL, sizeof(buf));	if (ret < 0) {		printf("OK! :write(s, NULL, 2048), EFAULT,errno = %d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! :write(s, NULL, 2048), EFAULT,errno = %d\n",errno);		result[testno] = 1;	}	/* Test 5 */	printf("Write Test %d: \n",num++);	errno = 0;testno = 5;	ret = unix_write(s, (char *)-1, sizeof(buf));	if (ret < 0) {		printf("OK! :write(s, -1, 2048), EFAULT,errno = %d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! :write(s, -1, 2048), EFAULT,errno = %d\n",errno);		result[testno] = 1;	}	/* Test 6 */	printf("Write Test %d: \n",num++);	errno = 0;testno = 6;	ret = unix_write(s, buf, -1);	if (ret < 0) {		printf("OK! :write(s, buf, -1), EINVAL,errno = %d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! :write(s, buf, -1), EINVAL,errno = %d\n",errno);		result[testno] = 1;	}	/* Test 7 */	printf("Write Test %d: \n",num++);testno = 7;	for (i=0; i < 10; i++) {		errno = 0;		ret = unix_write(s, buf, sizeof(buf));		if (ret < 0) {			result[testno] = 1;			break;		} 		printf("write data size %d\n",ret);	}	ret = unix_write(s, buf, 0);	if (ret < 0) {		result[testno] = 1;	}	unix_shutdown(s, SHUT_RDWR);	unix_close(s);#if defined(T_KERNEL)	tk_slp_tsk(2000);#endiftestend:	/* check the results */	testno2 = 7;	for (i=1; i <= testno; i++) {		if (result[i] == 1)			break;	}	if (i > testno2)		printf("Pass.\n");	else		printf("Error.\n");#if defined(T_KERNEL)	tk_slp_tsk(TMO_FEVR);#endif}/* EOF */

⌨️ 快捷键说明

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