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

📄 t_listen.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, fd, s, s2;	int	ret;	struct sockaddr_in name;	int	namelen;	int	num;	int testno, testno2, result[6];	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) {		goto testend;	}	name.sin_family = AF_INET;	name.sin_port = 0;	name.sin_addr.s_addr = INADDR_ANY;	name.sin_len = sizeof(struct sockaddr_in);	namelen = sizeof(name);		errno = 0;	if ((ret = unix_bind(s, (struct sockaddr *)&name, namelen)) < 0) {		printf("bind fail\n");		unix_close(s);		goto testend;	}			/* Test 1 */	printf("Listen Test %d: \n",num++);	errno = 0;testno = 1;	ret = unix_listen(-1, 3);	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("Listen Test %d: \n",num++);	errno = 0;testno = 2;	ret = unix_listen(10, 3);	if (ret < 0) {		printf("OK! : Bad socket fd(10) EBADF errno=%d\n",errno);		result[testno] = 0;	}	else {		printf("Fail! : Bad socket fd(10) EBADF errno=%d\n",errno);		result[testno] = 1;	}	/* Test 3 */	printf("Listen Test %d: \n",num++);	errno = 0;	if ((s2 = unix_socket(AF_INET, SOCK_DGRAM, 0)) < 0) {		unix_close(s);		goto testend;	} else {		errno = 0;		if ((ret = unix_bind(s2, (struct sockaddr *)&name, namelen)) < 0) {			unix_close(s);			unix_close(s2);			goto testend;		} else {			errno = 0;testno = 3;			ret = unix_listen(s2, 3);			if (ret < 0) {				printf("OK! : Bad socket type(-1) EOPNOTSUPP errno=%d\n",errno);				result[testno] = 0;			}			else {				printf("Fail! : Bad socket type(-1) EOPNOTSUPP errno=%d\n",errno);				result[testno] = 1;			}		}	}	if (s2 > 0) {		unix_close(s2);	}	/* Test 4 */	printf("Listen Test %d: \n",num++);	errno = 0;testno = 4;	ret = unix_listen(s, -1);	if (ret < 0) {		printf("Fail! : listen(s, -1) backlog error check success. return = %d errno = %d\n", ret, errno);		result[testno] = 1;	} else {		printf("OK! : listen(s, -1) backlog error is not checked. but this may be specfication. return = %d errno = %d\n", ret, errno);		result[testno] = 0;	}	/* Test 5 */	printf("Listen Test %d: \n",num++);	errno = 0;testno = 5;	ret = unix_listen(s, 1000);	if (ret < 0) {		printf("Fail! : backlog(=1000) error check success. return = %d errno = %d\n", ret, errno);		result[testno] = 1;	} else {		printf("OK! : backlog(=1000) error is not checked. but this may be specfication. return = %d errno = %d\n", ret, errno);		result[testno] = 0;	}	unix_close(s);testend:	/* 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 + -