in src/server/simple_axis_server/SimpleAxisServer.cpp [134:268]
int main (int argc, char *argv[])
{
#ifdef WIN32
WSADATA wsaData; /* Structure for WinSock setup communication */
#else //Linux
#endif
fd_set sockSet; // Set of socket descriptors for select()
int maxDescriptor = -1; // Maximum socket descriptor value
struct timeval selTimeout; // Timeout for select()
long timeout = 1000; // Timeout value given on command-line
int running = 1;
int iServerPort;
int iPort;
int noPorts = 1; // Number of ports is argument count minus 2
int * servSock = new int[noPorts]; // Socket descriptors for server
if( argc < 2)
{
printf( "Problem occurred.\nUsage: %s <Server Port>", argv[0]);
exit( 1);
}
#ifdef WIN32
if( WSAStartup( MAKEWORD( 2, 0), &wsaData) != 0) /* Load Winsock 2.0 DLL */
{
fprintf( stderr, "WSAStartup() failed");
exit( 1);
}
#else //Linux
#endif
/////////////
iServerPort = atoi( argv[1]);
if( iServerPort == 0)
{
printf( "Problem occurred. Error in specified server port");
exit( 1);
}
else
{
servSock[0] = createTCPServerSocket( iServerPort);
// Determine if new descriptor is the largest
if( servSock[0] > maxDescriptor)
{
maxDescriptor = servSock[0];
}
}
// Ensure that configuration has the correct hostname
AxisCPPConfigDefaults config;
config.setListenPort( argv[1]);
int namelen = 128;
char * hostname = new char[namelen];
if( gethostname( hostname, namelen) == 0)
{
if( hostname!= NULL)
{
config.setNodeName( hostname);
}
}
config.apply();
//initializing Axis
initialize_module( 1);
while (Axis::isRunning())
{
FD_ZERO (&sockSet);
FD_SET (servSock[0], &sockSet);
/* Timeout specification */
/* This must be reset every time select() is called */
selTimeout.tv_sec = timeout; /* timeout (secs.) */
selTimeout.tv_usec = 0; /* 0 microseconds */
if (select (maxDescriptor + 1, &sockSet, NULL, NULL, &selTimeout) ==
0)
{
/*
* DEBUG line
* printf("No echo requests for %ld secs...Server still alive\n",
* timeout);
*/
}
else
{
if (FD_ISSET (servSock[0], &sockSet))
{
//initializeStuff ();
/*
* DEBUG line
* printf("Request on port %d (cmd-line position): \n", 0);
*/
handleTCPClient (acceptTCPConnection (servSock[0]));
}
}
}
//uninitializing Axis
uninitialize_module ();
delete [] hostname;
/* Close sockets */
for (iPort = 0; iPort < noPorts; iPort++)
{
#ifdef WIN32
closesocket (servSock[iPort]);
#else //Linux
close (servSock[iPort]);
#endif
}
/* Free list of sockets */
delete [] servSock;
#ifdef WIN32
WSACleanup (); /* Cleanup Winsock */
#else //Linux
#endif
return 0;
}