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

📄 t_tcp_srv2.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"/* TCP server test () */voidtest_task(int stacd, void *exinf){        	int i, j, k, sd, newsd, len, size, total;	char ch, buf[SIZE];	struct sockaddr_in sinme, sindst;	int addrlen;	int stepno;stepno = 1;	size = SIZE;	ch = 'a';stepno = 2;	if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) {		goto err;	}	memset((char *)&sinme, 0, sizeof(struct sockaddr_in));	sinme.sin_family = AF_INET;	sinme.sin_addr.s_addr = inet_addr(IFRA_ADDR);	sinme.sin_port = htons(LOCALPORT);stepno = 3;	if (unix_bind(sd, (struct sockaddr *)&sinme, sizeof(struct sockaddr_in)) < 0) {		unix_close(sd);		goto err;	}	unix_listen(sd, 5);	for (j=1; j >= 1; j++) {		memset((char *)&sindst, 0, sizeof(struct sockaddr_in));		addrlen = sizeof(sindst);stepno = 4;		if ((newsd=unix_accept(sd, (struct sockaddr *)&sindst, &addrlen)) < 0) {			unix_close(sd);			break;		}		memset(buf, 0, size);		total = 0;		while (total < size) {stepno = 5;			if ((len = unix_recv(newsd, buf, size, 0)) < 0) {				unix_close(newsd);				unix_close(sd);				break;			}			if (len == 0) {				break;			}			total += len;			/* check data contents */			for (i=0; i < len; i++) {				if (buf[i] != ch) {					break;				}			}			if (i < len) {stepno = 6;				unix_close(newsd);				unix_close(sd);				goto err;			}		}		if (total == 0) {stepno = 11;			unix_close(newsd);			unix_close(sd);			break;		}		if (total != size) {stepno = 7;			unix_close(newsd);			unix_close(sd);			break;		}		memset(buf, ch, size);stepno = 8;		if ((len = unix_send(newsd, buf, size, 0)) < 0) {			unix_close(newsd);			unix_close(sd);			break;		}stepno = 9;		if (unix_shutdown(newsd, 0) < 0) {			unix_close(newsd);			unix_close(sd);			break;		}stepno = 10;		if (unix_close(newsd) < 0) {			unix_close(sd);			break;		}	}err:#if defined(T_KERNEL)	tk_slp_tsk(2000);#endif#if defined(PRINTF_ON)	if (stepno == 11) {		printf("Pass.\n");	}	else {		printf("Error at stepno-%d.\n", stepno);	}#endif	/* sleep task */#if defined(T_KERNEL)	tk_slp_tsk(TMO_FEVR);#endif}/* EOF */

⌨️ 快捷键说明

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