t_tcp_clt5.c
来自「T-kernel Tcp/ip Protocol Stack Sample」· C语言 代码 · 共 171 行
C
171 行
/* * Copyright (C) 1999-2003 MITSUBISHI ELECTRIC CORPORATION and * RENESAS SOLUTIONS CORPORATION and * RENESAS TECHNOLOGY CORPORATION * All rights reserved. * * BSD socket communicatin 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, 0);#if defined(T_KERNEL) tk_ext_tsk();#endif}voidtest_task3(int stacd, void *exinf){ char buf3[SIZE]; proc(buf3, 1);#if defined(T_KERNEL) tk_slp_tsk(TMO_FEVR);#endif}/* TCP client test () */void proc(char *buf, int flag){ int i, j, k, sd, newsd, len, size, total; char ch; struct sockaddr_in sinme, sindst; int stepno, stepno2; stepno = 0; stepno2 = 0; 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=1; 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; }#ifdef TMP 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; }#endif /* TMP */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 }if (flag) {stepno2 = 1; if ((sd = unix_socket(AF_INET, SOCK_STREAM, 0)) < 0) { goto err; }stepno2 = 2; if (unix_connect(sd, (struct sockaddr *)&sindst, sizeof(sindst)) < 0) { unix_close(sd); goto err; }stepno2 = 3; if (unix_send(sd, buf, 0, 0) < 0) { unix_close(sd); goto err; }stepno2 = 4; if (unix_shutdown(sd, 0) < 0) { unix_close(sd); goto err; }stepno2 = 5; unix_close(sd);}err:#if defined(PRINTF_ON) if (flag && stepno2 == 5) printf("Pass.\n"); else if (!flag && stepno == 9) printf("Pass.\n"); else printf("Error at stepno-%d.\n", stepno);#endif}/* EOF */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?