コード例 #1
0
void mySocket::setReuseAddr(int reuseToggle)
{
	try 
	{
		if ( setsockopt(socketId,SOL_SOCKET,SO_REUSEADDR,(char *)&reuseToggle,sizeof(reuseToggle)) == -1 )
		{
			#ifdef WINDOWS_XP
				int errorCode;
				string errorMsg = "REUSEADDR option:";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				myException* socketOptionException = new myException(errorCode,errorMsg);
				throw socketOptionException;
			#endif

			#ifdef UNIX
				myException* unixSocketOptionException = new myException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			#endif
        }
	}
    catch(myException* excp)
	{
		excp->response();
		delete excp;
		exit(1);
	}
} 
コード例 #2
0
void mySocket::setSendBufSize(int sendBufSize)
{
	try 
	{
		if ( setsockopt(socketId,SOL_SOCKET,SO_SNDBUF,(char *)&sendBufSize,sizeof(sendBufSize)) == -1 )
		{
			#ifdef WINDOWS_XP
				int errorCode;
				string errorMsg = "SENDBUFSIZE option:";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				myException* socketOptionException = new myException(errorCode,errorMsg);
				throw socketOptionException;
			#endif

			#ifdef UNIX
				myException* unixSocketOptionException = new myException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			#endif
        }
	}
    catch(myException* excp)
	{
		excp->response();
		delete excp;
		exit(1);
	}
} 
コード例 #3
0
void mySocket::setLingerOnOff(bool lingerOn)
{
	struct linger lingerOption;

	if ( lingerOn ) lingerOption.l_onoff = 1;
	else lingerOption.l_onoff = 0;

	try 
	{
		if ( setsockopt(socketId,SOL_SOCKET,SO_LINGER,(char *)&lingerOption,sizeof(struct linger)) == -1 )
		{
			#ifdef WINDOWS_XP
				int errorCode;
				string errorMsg = "LINGER option:";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				myException* socketOptionException = new myException(errorCode,errorMsg);
				throw socketOptionException;
			#endif

			#ifdef UNIX
				myException* unixSocketOptionException = new myException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			#endif
        }
	}
    catch(myException* excp)
	{
		excp->response();
		delete excp;
		exit(1);
	}
}
コード例 #4
0
void MySocket::setDebug(int debugToggle)
{
	try 
	{
		if ( setsockopt(m_nSocketId,SOL_SOCKET,SO_DEBUG,(char *)&debugToggle,sizeof(debugToggle)) == -1 )
		{
			#ifdef WINDOWS_XP
				int errorCode;
				string errorMsg = "DEBUG option:";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				MyException socketOptionException(errorCode,errorMsg);
				throw socketOptionException;
			#endif

			#ifdef UNIX
				MyException unixSocketOptionException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			#endif
        }
	}
    catch(MyException& excp)
	{
		excp.response();
		exit(1);
	}
}
コード例 #5
0
void MySocket::setReceiveBufSize(int receiveBufSize)
{
	try 
	{
		if ( setsockopt(m_nSocketId,SOL_SOCKET,SO_RCVBUF,(char *)&receiveBufSize,sizeof(receiveBufSize)) == -1 )
		{
			#ifdef WINDOWS_XP
				int errorCode;
				string errorMsg = "RCVBUF option:";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				MyException socketOptionException(errorCode,errorMsg);
				throw socketOptionException;
			#endif

			#ifdef UNIX
				MyException unixSocketOptionException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			#endif
        }
	}
    catch(MyException& excp)
	{
		excp.response();
		exit(1);
	}
}
コード例 #6
0
void MySocket::setLingerSeconds(int seconds)
{
	struct linger lingerOption;
	
	if ( seconds > 0 )
	{
		lingerOption.l_linger = seconds;
		lingerOption.l_onoff = 1;
	}
	else lingerOption.l_onoff = 0;
	 
	try 
	{
		if ( setsockopt(m_nSocketId,SOL_SOCKET,SO_LINGER,(char *)&lingerOption,sizeof(struct linger)) == -1 )
		{
			#ifdef WINDOWS_XP
				int errorCode;
				string errorMsg = "LINGER option:";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				MyException socketOptionException(errorCode,errorMsg);
				throw socketOptionException;
			#endif

			#ifdef UNIX
				MyException unixSocketOptionException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			#endif
        }
	}
    catch(MyException& excp)
	{
		excp.response();
		exit(1);
	}
}
コード例 #7
0
void mySocket::setSocketBlocking(int blockingToggle)
{
    if (blockingToggle)
    {
        if (getSocketBlocking()) return;
        else blocking = 1;
	}
	else
	{
		if (!getSocketBlocking()) return;
		else blocking = 0;
	}

	try 
	{
		#ifdef WINDOWS_XP
			if (ioctlsocket(socketId,FIONBIO,(unsigned long *)blocking) == -1)
			{
				int errorCode;
				string errorMsg = "Blocking option: ";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				myException* socketOptionException = new myException(errorCode,errorMsg);
				throw socketOptionException;
			}
		#endif

		#ifdef UNIX
			if (ioctl(socketId,FIONBIO,(char *)&blocking) == -1)
			{
				myException* unixSocketOptionException = new myException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			}
		#endif
	}
    catch(myException* excp)
	{
		excp->response();
		delete excp;
		exit(1);
	}
}
コード例 #8
0
void MySocket::setSocketBlocking(int blockingToggle)
{
    if (blockingToggle)
    {
        if (getSocketBlocking()) return;
        else m_nBlocking = 1;
	}
	else
	{
		if (!getSocketBlocking()) return;
		else m_nBlocking = 0;
	}

	try 
	{
		#ifdef WINDOWS_XP
			if (ioctlsocket(m_nSocketId,FIONBIO,(unsigned long *)&m_nBlocking) == -1)
			{
				int errorCode;
				string errorMsg = "Blocking option: ";
				detectErrorSetSocketOption(&errorCode,errorMsg);
				MyException socketOptionException(errorCode,errorMsg);
				throw socketOptionException;
			}
		#endif

		#ifdef UNIX
			if (ioctl(m_nSocketId,FIONBIO,(char *)&m_nBlocking) == -1)
			{
				MyException unixSocketOptionException(0,"unix: error getting host by name");
				throw unixSocketOptionException;
			}
		#endif
	}
    catch(MyException& excp)
	{
		excp.response();
		exit(1);
	}
}