📄 t_tcp_clt1.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"extern int printf( const char *format, ... );/* TCP client 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 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 < LOOP; 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, ch, size);stepno = 4; if ((len = unix_send(sd, buf, size, 0)) < 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; } 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 != 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 }stepno = 10; if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) { goto err; }stepno = 11; if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) { unix_close(sd); goto err; }stepno = 12; if (unix_send(sd, buf, 0, 0) < 0) { unix_close(sd); goto err; }stepno = 13; if (unix_shutdown(sd, 0) < 0) { unix_close(sd); goto err; }stepno = 14; unix_close(sd);#if defined(T_KERNEL) tk_slp_tsk(1000);#endiferr:#if defined(PRINTF_ON) if (stepno == 14) 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 + -