2 Windows version of the OOB Receive application
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 Run the OOB receive application
23 @param [in] ArgC Argument count
24 @param [in] ArgV Argument value array
26 @retval 0 Successfully operation
35 ssize_t BytesReceived
;
36 struct sockaddr_in LocalPort
;
39 struct timeval ReceiveTimeout
;
40 struct sockaddr_in RemotePort
;
41 socklen_t RemotePortLength
;
44 UINT32 TransmittedBefore
;
45 UINT32 TransmittedDuring
;
46 UINT32 TransmittedOob
;
47 UINT32 TransmittedAfter
;
48 UINT32
* pTransmittedBytes
;
53 s
= socket ( AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
56 printf ( "ERROR - socket error, errno: %d\r\n", RetVal
);
60 // Use for/break; instead of goto
64 // Bind the socket to a known port
66 PortNumber
= OOB_RX_PORT
;
67 memset ( &LocalPort
, 0, sizeof ( LocalPort
));
68 SIN_LEN ( LocalPort
) = sizeof ( LocalPort
);
69 SIN_FAMILY ( LocalPort
) = AF_INET
;
70 SIN_ADDR ( LocalPort
) = 0;
71 SIN_PORT ( LocalPort
) = htons ( PortNumber
);
73 (struct sockaddr
*)&LocalPort
,
74 sizeof ( LocalPort
));
77 printf ( "ERROR - bind error, errno: %d\r\n", RetVal
);
82 // Make the port available on the server
84 RetVal
= listen ( s
, 2 );
87 printf ( "ERROR - listen error, errno: %d\r\n", RetVal
);
92 // Wait for a connection to the known port
94 RemotePortLength
= sizeof ( RemotePort
);
96 (struct sockaddr
*)&RemotePort
,
100 printf ( "ERROR - accept error, errno: %d\r\n", RetVal
);
105 // Use for/break instead of goto
109 // Set the receive timeout
111 ReceiveTimeout
.tv_sec
= 0;
112 ReceiveTimeout
.tv_usec
= 20 * 1000;
113 RetVal
= setsockopt ( a
,
116 (char *)&ReceiveTimeout
,
117 sizeof ( ReceiveTimeout
));
118 if ( -1 == RetVal
) {
120 printf ( "ERROR - setsockopt RCVTIMEO error, errno: %d\r\n", RetVal
);
125 // Select the OOB processing
127 OobInLine
= ( 1 < ArgC
);
128 RetVal
= setsockopt ( s
,
132 sizeof ( OobInLine
));
133 if ( -1 == RetVal
) {
135 printf ( "ERROR - setsockopt OOBINLINE error, errno: %d\r\n", RetVal
);
138 printf ( "%s\r\n", ( 0 != OobInLine
) ? "OOB messages are in-line"
139 : "OOB messages move to the head of the queue" );
142 // Receive data from the remote system
144 TransmittedBefore
= 0;
146 TransmittedDuring
= 0;
147 TransmittedAfter
= 0;
148 pTransmittedBytes
= &TransmittedBefore
;
151 // Attempt to receive OOB data
153 BytesReceived
= recv ( a
, &mBuffer
[0], sizeof ( mBuffer
), MSG_OOB
);
154 RetVal
= (UINT32
)BytesReceived
;
155 if ( 0 < BytesReceived
) {
157 // Display the received OOB data
159 printf ( "%5Ld OOB bytes received\r\n", (UINT64
)BytesReceived
);
162 // Account for the bytes received
164 TransmittedOob
+= RetVal
;
165 *pTransmittedBytes
+= TransmittedAfter
;
166 TransmittedAfter
= 0;
167 pTransmittedBytes
= &TransmittedDuring
;
169 else if ( -1 == BytesReceived
) {
171 // Check for connection timeout
174 if ( RX_TIMEOUT_ERROR
!= RetVal
) {
178 printf ( "ERROR - recv OOB error, errno: %d\r\n", RetVal
);
183 // Ignore the timeout
184 // Try to receive normal data instead
186 BytesReceived
= recv ( a
, &mBuffer
[0], sizeof ( mBuffer
), 0 );
187 RetVal
= (UINT32
)BytesReceived
;
188 if ( 0 < BytesReceived
) {
190 // Display the received data
192 printf ( "%4Ld bytes received\r\n", (UINT64
)BytesReceived
);
195 // Account for the bytes received
197 TransmittedAfter
+= RetVal
;
199 else if ( -1 == BytesReceived
) {
201 // Check for a timeout
204 if ( RX_TIMEOUT_ERROR
!= RetVal
) {
205 printf ( "ERROR - recv error, errno: %d\r\n", RetVal
);
210 } while ( 0 != RetVal
);
213 // Display the bytes received
216 printf ( "Bytes before OOB: %8d\r\n", TransmittedBefore
);
217 if ( 0 != TransmittedDuring
) {
218 printf ( "Bytes during OOB: %8d\r\n", TransmittedDuring
);
220 printf ( "Out-of-band bytes: %8d\r\n", TransmittedOob
);
221 printf ( "Bytes after OOB: %8d\r\n", TransmittedAfter
);
222 printf ( " --------\r\n" );
223 printf ( "Total Bytes: %8d\r\n", TransmittedBefore
226 + TransmittedAfter
);
236 // Close the test socket
246 printf ( "Socket closed\r\n" );
250 // Return the operation status