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

📄 t_close.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"voidtest_task(int stacd, void *exinf){	int	i, s, s2, ret;	struct sockaddr_in name, addr;	int	namelen, addrlen;	int	num;	int testno, testno2, result[6];	num = 1;	testno = 0;	memset((char *)result, 0, sizeof(result));	/* Test 1 */	printf("Close Test %d: \n",num++);	errno = 0;testno = 1;	ret = unix_close(-1);    if (ret < 0) {        printf("OK! : Bad socket fd(-1) EBADF errno=%d\n",errno);		result[testno] = 0;	}    else {        printf("Fail! : Bad socket fd(-1) EBADF errno=%d\n",errno);		result[testno] = 1;	}	/* Test 2 */	printf("Close Test %d: \n",num++);	errno = 0;testno = 2;	ret = unix_close(10);    if (ret < 0) {        printf("OK! : Bad socket fd(-1) EBADF errno=%d\n",errno);		result[testno] = 0;	}    else {        printf("Fail! : Bad socket fd(-1) EBADF errno=%d\n",errno);		result[testno] = 1;	}	/* Test 3 */	printf("Close Test %d: \n",num++);	errno = 0;	if ((s2 = unix_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {		printf("socket fail\n");		goto testend;	} testno = 3;	ret = unix_close(s2);    if (ret == 0) {        printf("OK! : close SOCK_DGRAM socket \n");		result[testno] = 0;	}    else {        printf("Fail! : close SOCK_DGRAM socket \n");		result[testno] = 1;	}	/* Test 4 */	printf("Close Test %d: \n",num++);	/* for setup: get normal socket */	errno = 0;	if ((s = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {		printf("socket fail\n");		goto testend;	}	memset((char *)&name, 0, sizeof(name));	name.sin_family = AF_INET;	name.sin_port = htons(TGT_PORT);	name.sin_addr.s_addr = inet_addr(TGT_ADDR);	namelen = sizeof(name);		errno = 0;	if ((ret = unix_bind(s, (struct sockaddr *)&name, namelen)) < 0) {		printf("bind fail\n");		unix_close(s);		goto testend;	}	errno = 0;	if ((ret = unix_listen(s, 5)) < 0) {		printf("listen(s,5) fail \n");		unix_close(s);		goto testend;	}	errno = 0;	addrlen = sizeof(addr);			memset((char *)&addr, 0, addrlen);	s2  = unix_accept(s, (struct sockaddr *)&addr, &addrlen);	if (s2 < 0) {		printf("accept fail \n");		unix_close(s);		goto testend;	}	unix_shutdown(s2, SHUT_RDWR);	unix_shutdown(s, SHUT_RDWR);	errno = 0;testno = 4;	ret = unix_close(s2);    if (ret == 0) {        printf("OK! : close connected socket(s2) \n");		result[testno] = 0;	}    else {        printf("Fail! : close connected socket(s2) \n");		result[testno] = 1;	}testno = 5;	ret = unix_close(s);    if (ret == 0) {        printf("OK! : close connected socket(s) \n");		result[testno] = 0;	}    else {        printf("Fail! : close connected socket(s) \n");		result[testno] = 1;	}#if defined(T_KERNEL)	tk_slp_tsk(2000);#endiftestend:	/* check the results */	testno2 = 5;	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 + -