Esempio n. 1
0
int main(){
	
	#if 0
	printf("Test  popen start**************\n");
	testPopen();
	printf("Test popen end **************\n");
	#endif

	#if 0
	printf("Test epoll with pipe start **************\n");
	testEpollWithPipe();
	printf("Test epoll with pipe end **************\n");
	#endif

	#if 0
	printf("Test named pipe start **************\n");
	testNamedPipe();
	printf("Test named pipe end **************\n");
	#endif

	#if 0
	printf("Test socket pair start **************\n");
	testSocket(1);
	printf("Test socket pair end **************\n");
	#endif

	#if 0
	printf("Test socket start **************\n");
	testSocket(2);
	printf("Test socket end **************\n");
	#endif

	#if 1
	printf("Test signal start **************\n");
	//testSignal(1);
	testSignal(2);
	printf("Test signal end **************\n");
	#endif


	return 1;
}
Esempio n. 2
0
bool ConnectionServerSocketUnix::bind(int connectionQueueSize)
{
	ConnectionSocketUnix testSocket(mLocal.sun_path);
	if (testSocket.connect() == 0) {
		// Socket is alive. Return error - we can't bind.
		return false;
	} else {
		// Socket is not alive. Remove its file entry to avoid EINVAL.
		::unlink(mLocal.sun_path);
	}
	
	mBound = bindInternal((sockaddr*)&mLocal, sizeof(mLocal), connectionQueueSize);
	return mBound;
}
Esempio n. 3
0
int iGetPort()
{
    long int iMaxPortNum = 6500;    // Stores the maximum value of chosen port 
                                    // number

    int iNumTries = 0;            // Number of socket port attempts

    // A range of socket ports are tested for availability.  The loop 
    // continues until an available port is found or until the entire 
    // range of ports has been attempted
    do
    {       
        try
        {
            // Create a socket using the next port in the range
            XPCTcpSocket testSocket(iMaxPortNum);

            // Bind the socket
            testSocket.vBindSocket();

            // The socket is closed
            testSocket.vCloseSocket();    

            // If the port number is available, the socket can be bound and an
            // exception is NOT thrown.  The port number is returned
            return iMaxPortNum;
        }
        catch(XPCException &exceptOb)
        {
            // If a socket cannot be bound to the given port,
            // an exception is thrown.  The port number is 
            // decremented for another try
            cout << "Failed Port #:" << iMaxPortNum << endl;
            iMaxPortNum--;
            iNumTries++;
            if (iMaxPortNum < 5000)
                iMaxPortNum = 6500;
        }
    } while (iNumTries == iMaxPortNum - 5000);

    // Return -1 indicating an available port cannot be found
    return -1;
}