OobRx.c revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Windows version of the OOB Receive application
Copyright (c) 2011, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <OobRx.h>
/**
Run the OOB receive application
@param [in] ArgC Argument count
@param [in] ArgV Argument value array
@retval 0 Successfully operation
**/
int
OobRx (
)
{
SOCKET a;
struct sockaddr_in LocalPort;
struct timeval ReceiveTimeout;
struct sockaddr_in RemotePort;
int RetVal;
SOCKET s;
//
// Create the socket
//
if ( -1 == s ) {
}
else {
//
//
for ( ; ; ) {
//
// Bind the socket to a known port
//
sizeof ( LocalPort ));
if ( -1 == RetVal ) {
break;
}
//
// Make the port available on the server
//
if ( -1 == RetVal ) {
break;
}
//
// Wait for a connection to the known port
//
RemotePortLength = sizeof ( RemotePort );
a = accept ( s,
(struct sockaddr *)&RemotePort,
&RemotePortLength );
if ( -1 == a ) {
break;
}
//
//
for ( ; ; ) {
//
// Set the receive timeout
//
ReceiveTimeout.tv_sec = 0;
RetVal = setsockopt ( a,
(char *)&ReceiveTimeout,
sizeof ( ReceiveTimeout ));
if ( -1 == RetVal ) {
break;
}
//
// Select the OOB processing
//
RetVal = setsockopt ( s,
(char *)&OobInLine,
sizeof ( OobInLine ));
if ( -1 == RetVal ) {
break;
}
: "OOB messages move to the head of the queue" );
//
// Receive data from the remote system
//
TransmittedBefore = 0;
TransmittedOob = 0;
TransmittedDuring = 0;
TransmittedAfter = 0;
do {
//
// Attempt to receive OOB data
//
if ( 0 < BytesReceived ) {
//
// Display the received OOB data
//
//
// Account for the bytes received
//
TransmittedOob += RetVal;
TransmittedAfter = 0;
}
else if ( -1 == BytesReceived ) {
//
// Check for connection timeout
//
if ( RX_TIMEOUT_ERROR != RetVal ) {
//
// Receive error
//
break;
}
//
// Ignore the timeout
// Try to receive normal data instead
//
if ( 0 < BytesReceived ) {
//
// Display the received data
//
//
// Account for the bytes received
//
}
else if ( -1 == BytesReceived ) {
//
// Check for a timeout
//
if ( RX_TIMEOUT_ERROR != RetVal ) {
break;
}
}
}
} while ( 0 != RetVal );
//
// Display the bytes received
//
if ( 0 == RetVal ) {
if ( 0 != TransmittedDuring ) {
}
printf ( " --------\r\n" );
+ TransmittedAfter );
}
//
// Test complete
//
break;
}
//
// Close the test socket
//
CLOSE_SOCKET ( a );
break;
}
//
// Close the socket
//
CLOSE_SOCKET ( s );
printf ( "Socket closed\r\n" );
}
//
// Return the operation status
//
return RetVal;
}