📄 t_tcp_srv6.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"void proc(char *, int);voidtest_task1(int stacd, void *exinf){ char buf1[SIZE]; proc(buf1, 0);#if defined(T_KERNEL) tk_ext_tsk();#endif}voidtest_task2(int stacd, void *exinf){ char buf2[SIZE]; proc(buf2, 1);#if defined(T_KERNEL) tk_ext_tsk();#endif}voidtest_task3(int stacd, void *exinf){ char buf3[SIZE]; proc(buf3, 2);#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}void proc(char *buf, int flag){ int i, j, k, sd, newsd, len, size, total; char ch; 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 + flag);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#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -