2 Windows version of the OOB Receive application
4 Copyright (c) 2011-2012, Intel Corporation. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
15 Run the OOB receive application
17 @param [in] ArgC Argument count
18 @param [in] ArgV Argument value array
20 @retval 0 Successfully operation
29 ssize_t BytesReceived
;
30 struct sockaddr_in LocalPort
;
33 struct timeval ReceiveTimeout
;
34 struct sockaddr_in RemotePort
;
35 socklen_t RemotePortLength
;
38 UINT32 TransmittedBefore
;
39 UINT32 TransmittedDuring
;
40 UINT32 TransmittedOob
;
41 UINT32 TransmittedAfter
;
42 UINT32
* pTransmittedBytes
;
47 s
= socket ( AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
50 printf ( "ERROR - socket error, errno: %d\r\n", RetVal
);
54 // Use for/break; instead of goto
58 // Bind the socket to a known port
60 PortNumber
= OOB_RX_PORT
;
61 memset ( &LocalPort
, 0, sizeof ( LocalPort
));
62 SIN_LEN ( LocalPort
) = sizeof ( LocalPort
);
63 SIN_FAMILY ( LocalPort
) = AF_INET
;
64 SIN_ADDR ( LocalPort
) = 0;
65 SIN_PORT ( LocalPort
) = htons ( PortNumber
);
67 (struct sockaddr
*)&LocalPort
,
68 sizeof ( LocalPort
));
71 printf ( "ERROR - bind error, errno: %d\r\n", RetVal
);
76 // Make the port available on the server
78 RetVal
= listen ( s
, 2 );
81 printf ( "ERROR - listen error, errno: %d\r\n", RetVal
);
86 // Wait for a connection to the known port
88 RemotePortLength
= sizeof ( RemotePort
);
90 (struct sockaddr
*)&RemotePort
,
94 printf ( "ERROR - accept error, errno: %d\r\n", RetVal
);
99 // Use for/break instead of goto
103 // Set the receive timeout
105 ReceiveTimeout
.tv_sec
= 0;
106 ReceiveTimeout
.tv_usec
= 20 * 1000;
107 RetVal
= setsockopt ( a
,
110 (char *)&ReceiveTimeout
,
111 sizeof ( ReceiveTimeout
));
112 if ( -1 == RetVal
) {
114 printf ( "ERROR - setsockopt RCVTIMEO error, errno: %d\r\n", RetVal
);
119 // Select the OOB processing
121 OobInLine
= ( 1 < ArgC
);
122 RetVal
= setsockopt ( s
,
126 sizeof ( OobInLine
));
127 if ( -1 == RetVal
) {
129 printf ( "ERROR - setsockopt OOBINLINE error, errno: %d\r\n", RetVal
);
132 printf ( "%s\r\n", ( 0 != OobInLine
) ? "OOB messages are in-line"
133 : "OOB messages move to the head of the queue" );
136 // Receive data from the remote system
138 TransmittedBefore
= 0;
140 TransmittedDuring
= 0;
141 TransmittedAfter
= 0;
142 pTransmittedBytes
= &TransmittedBefore
;
145 // Attempt to receive OOB data
147 BytesReceived
= recv ( a
, &mBuffer
[0], sizeof ( mBuffer
), MSG_OOB
);
148 RetVal
= (UINT32
)BytesReceived
;
149 if ( 0 < BytesReceived
) {
151 // Display the received OOB data
153 printf ( "%5Ld OOB bytes received\r\n", (UINT64
)BytesReceived
);
156 // Account for the bytes received
158 TransmittedOob
+= RetVal
;
159 *pTransmittedBytes
+= TransmittedAfter
;
160 TransmittedAfter
= 0;
161 pTransmittedBytes
= &TransmittedDuring
;
163 else if ( -1 == BytesReceived
) {
165 // Check for connection timeout
168 if ( RX_TIMEOUT_ERROR
!= RetVal
) {
172 printf ( "ERROR - recv OOB error, errno: %d\r\n", RetVal
);
177 // Ignore the timeout
178 // Try to receive normal data instead
180 BytesReceived
= recv ( a
, &mBuffer
[0], sizeof ( mBuffer
), 0 );
181 RetVal
= (UINT32
)BytesReceived
;
182 if ( 0 < BytesReceived
) {
184 // Display the received data
186 printf ( "%4Ld bytes received\r\n", (UINT64
)BytesReceived
);
189 // Account for the bytes received
191 TransmittedAfter
+= RetVal
;
193 else if ( -1 == BytesReceived
) {
195 // Check for a timeout
198 if ( RX_TIMEOUT_ERROR
!= RetVal
) {
199 printf ( "ERROR - recv error, errno: %d\r\n", RetVal
);
204 } while ( 0 != RetVal
);
207 // Display the bytes received
210 printf ( "Bytes before OOB: %8d\r\n", TransmittedBefore
);
211 if ( 0 != TransmittedDuring
) {
212 printf ( "Bytes during OOB: %8d\r\n", TransmittedDuring
);
214 printf ( "Out-of-band bytes: %8d\r\n", TransmittedOob
);
215 printf ( "Bytes after OOB: %8d\r\n", TransmittedAfter
);
216 printf ( " --------\r\n" );
217 printf ( "Total Bytes: %8d\r\n", TransmittedBefore
220 + TransmittedAfter
);
230 // Close the test socket
240 printf ( "Socket closed\r\n" );
244 // Return the operation status