WIZlib Library API  ver 1.0
WIZlib Library API User Menual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
loopback.c
Go to the documentation of this file.
1 
12 //#define FILE_LOG_SILENCE
14 
15 #define TX_RX_MAX_BUF_SIZE 2048
16 
17 
18 int8 data_buf[TX_RX_MAX_BUF_SIZE];
19 
28 void loopback_tcps(uint8 sock, uint16 port)
29 {
30  int32 ret;
31  int32 SendLen, ReSendLen;
32 
33  ret = TCPRecv(sock, data_buf, TX_RX_MAX_BUF_SIZE);
34 
35  if(ret > 0){ // Received
36  SendLen = TCPSend(sock, data_buf, ret);
37 
38  if(SendLen < ret){
39  while(SendLen != ret){
40  ReSendLen = TCPReSend(sock);
41 
42  if(ReSendLen > 0){
43  SendLen += ReSendLen;
44 
45  } else if(ReSendLen == SOCKERR_WINDOW_FULL){
46  LOG("Window Full");
47  TCPClose(sock);
48  DBG("TCP Socket Close");
49  while(1);
50 
51  } else{
52  break;
53  }
54  }
55  }
56 
57  } else if(ret == SOCKERR_NOT_TCP){ // Not TCP Socket, It's UDP Socket
58  DBG("UDP Socket Close");
59  UDPClose(sock);
60  } else if(ret == SOCKERR_CLOSED){ // Socket Closed
61  LOGA("TCP Loop-Back Started - sock(%d)",(uint16)sock);
62  TCPServerOpen(sock, port);
63  }
64 
65  if(GetTCPSocketStatus(sock) == SOCKSTAT_CLOSE_WAIT){ // Close waiting
66  TCPClose(sock);
67  }
68 }
69 
78 void loopback_udp(uint8 sock, uint16 port)
79 {
80  int32 ret;
81  uint32 destip = 0;
82  uint16 destport;
83 
84  ret = UDPRecv(sock, data_buf, TX_RX_MAX_BUF_SIZE, (uint8*)&destip, &destport);
85 
86  if(ret > 0){ // Received
87  ret = UDPSend(sock, data_buf, ret, (uint8*)&destip ,destport);
88 
89  if(ret == SOCKERR_TIME_OUT){
90  ERR("Timeout");
91  UDPClose(sock);
92  DBG("UDP Socket Close");
93  }
94 
95  } else if(ret == SOCKERR_NOT_UDP){ // Not UDP Socket, It's TCP Socket
96  DBG("TCP Socket Close");
97  TCPClose(sock);
98  } else if(ret == SOCKERR_CLOSED){ // Socket Closed
99  LOGA("UDP Loop-Back Started - sock(%d)",(uint16)sock);
100  UDPOpen(sock, port);
101  }
102 }
103 
104 
105