📄 t_tcp_clt10.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"int sd; /* a common socket descriptor *//* TCP client test () */voidtest_task(int stacd, void *exinf){ int i, j, k, len, size, total; char ch, buf[SIZE]; struct sockaddr_in sinme, sindst; int stepno; size = SIZE; ch = 'a';stepno = 1; memset((char *)&sindst, 0, sizeof(struct sockaddr_in)); sindst.sin_family = AF_INET; sindst.sin_addr.s_addr = inet_addr(DST_IPADDR); sindst.sin_port = htons(DST_PORTNO); for (j=0; j < LOOP1; j++) {stepno = 2; if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) { break; }stepno = 3; if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) { unix_close(sd); break; } memset(buf, 0, size); total = 0; while (total < size) {stepno = 5; if ((len = unix_recv(sd, buf, size, 0)) < 0) { 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(sd); goto err; } } if (total != 0 && total != size) {stepno = 7; unix_close(sd); break; }stepno = 8; if (unix_shutdown(sd, 0) < 0) { unix_close(sd); break; }stepno = 9; if (unix_close(sd) < 0) { break; } /* sleep 1 second */#if defined(T_KERNEL) tk_slp_tsk(1000);#endif }err:#if defined(PRINTF_ON) if (stepno == 9) printf("Pass.\n"); else printf("Error at stepno-%d.\n", stepno);#endif /* sleep task */#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}#ifndef OLDvoidtest_task2(int stacd, void *exinf){ int i, j, k, sd2, len, size, total; char ch, buf[SIZE]; struct sockaddr_in sinme, sindst; int stepno2; size = SIZE; ch = 'a'; memset((char *)&sindst, 0, sizeof(struct sockaddr_in)); sindst.sin_family = AF_INET; sindst.sin_addr.s_addr = inet_addr(DST_IPADDR); sindst.sin_port = htons(DST_PORTNO); for (j=0; j < LOOP1; j++) { memset((char *)buf, ch, sizeof(buf));stepno2 = 4; if ((len = unix_send(sd, buf, size, 0)) < 0) { unix_close(sd); break; }#ifdef OLDstepno2 = 8; if (unix_shutdown(sd, 0) < 0) { unix_close(sd); break; }stepno2 = 9; if (unix_close(sd) < 0) { break; }#endif /* OLD */ /* sleep 1 second */#if defined(T_KERNEL) tk_slp_tsk(1000);#endif }stepno2 = 10; if ((sd2 = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) { goto err; }stepno2 = 11; if (unix_connect(sd2, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) { unix_close(sd2); goto err; }stepno2 = 12; if (unix_send(sd2, buf, 0, 0) < 0) { unix_close(sd2); goto err; }stepno2 = 13; if (unix_shutdown(sd2, 0) < 0) { unix_close(sd2); goto err; }stepno2 = 14; unix_close(sd2);#if defined(T_KERNEL) tk_slp_tsk(1000);#endiferr:#if defined(PRINTF_ON) if (stepno2 == 14) printf("Pass.\n"); else printf("Error at stepno2-%d.\n", stepno2);#endif#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}#endif /* !OLD *//* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -