Commit fb3854d6 authored by Andrea Orlat's avatar Andrea Orlat
Browse files

avoid the addres already in use problem when restarting total power component...

avoid the addres already in use problem when restarting total power component after a not gracefull close. see issue#232
parent 5ca2dccd
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -130,9 +130,11 @@ public:
	 *        significant only for the server and receiving side. 
	 *        significant only for the server and receiving side. 
	 * @param IPAddr a string containing the network address used for binding the socket, such as "192.168.0.1". If the default
	 * @param IPAddr a string containing the network address used for binding the socket, such as "192.168.0.1". If the default
	 *        value of NULL is given, the socket is binded with any address (0.0.0.0)
	 *        value of NULL is given, the socket is binded with any address (0.0.0.0)
	 * @param froceBind this will force the operating system kernel to reuse a local address avoiding the "address already in use" error
	 *        during binding.
	 * @return SUCCESS if the operation succeeds, FAIL in case of a problem.
	 * @return SUCCESS if the operation succeeds, FAIL in case of a problem.
	*/
	*/
	OperationResult Create(CError& Err,SocketType Type=STREAM,WORD SocketPort=0,CString *IPAddr=NULL);
	OperationResult Create(CError& Err,SocketType Type=STREAM,WORD SocketPort=0,CString *IPAddr=NULL,bool forceBind=false);
	/**
	/**
	 * Before <i>Accept</i>ing connection this function expresses the willingness to accept for incoming connection requests.
	 * Before <i>Accept</i>ing connection this function expresses the willingness to accept for incoming connection requests.
	 * <i>Listen</i> specifies also the queue limit for incoming connections. This function applies only to STREAM sockets.
	 * <i>Listen</i> specifies also the queue limit for incoming connections. This function applies only to STREAM sockets.
+8 −1
Original line number Original line Diff line number Diff line
@@ -24,7 +24,7 @@ CSocket::~CSocket()
	Close(Tmp);
	Close(Tmp);
}
}


CSocket::OperationResult CSocket::Create(CError& Err,SocketType Type,WORD SocketPort,CString *IPAddr)
CSocket::OperationResult CSocket::Create(CError& Err,SocketType Type,WORD SocketPort,CString *IPAddr,bool forceBind)
{
{
	struct sockaddr_in addr;
	struct sockaddr_in addr;
	if (!Err.isNoError()) return FAIL;
	if (!Err.isNoError()) return FAIL;
@@ -54,6 +54,13 @@ CSocket::OperationResult CSocket::Create(CError& Err,SocketType Type,WORD Socket
		_SET_SYSTEM_ERROR(Err,CError::SocketType,CError::SockCreationError,"CSocket::Create()",errno);
		_SET_SYSTEM_ERROR(Err,CError::SocketType,CError::SockCreationError,"CSocket::Create()",errno);
		return FAIL;
		return FAIL;
	}
	}
	if (forceBind) {
		int optval=1;
		if (setsockopt(m_iSocket,SOL_SOCKET,SO_REUSEADDR,(const void *)&optval,sizeof(int))<0) {
			_SET_SYSTEM_ERROR(Err,CError::SocketType,CError::SockConfiguration,"CSocket::Create()",errno);
			return FAIL;
		}
	}
	// this associates a local address to the socket
	// this associates a local address to the socket
	if ((SocketPort!=0) || (IPAddr!=NULL)) {
	if ((SocketPort!=0) || (IPAddr!=NULL)) {
		if (bind(m_iSocket,(struct sockaddr*)&addr,sizeof(struct sockaddr))<0) {
		if (bind(m_iSocket,(struct sockaddr*)&addr,sizeof(struct sockaddr))<0) {
+19 −2
Original line number Original line Diff line number Diff line
@@ -1096,8 +1096,13 @@ void CRecvBossCore::park() throw (ManagementErrors::ParkingErrorExImpl)
{
{
	baci::ThreadSyncGuard guard(&m_mutex);
	baci::ThreadSyncGuard guard(&m_mutex);
	if (!CORBA::is_nil(m_currentRecv)) {
	if (!CORBA::is_nil(m_currentRecv)) {
		try {
			m_currentRecv->deactivate();
			m_currentRecv->deactivate();
		}
		}
		catch (...) {
			ACS_LOG(LM_FULL_INFO,"CRecvBossCore::park()",(LM_WARNING,"COULD_NOT_DEACTIVATE_CURRENT_RECEIVER"));
		}
	}
	unloadReceiver();
	unloadReceiver();
	m_currentRecvCode="";
	m_currentRecvCode="";
	m_currentRecvInstance="";
	m_currentRecvInstance="";
@@ -1935,8 +1940,13 @@ void CRecvBossCore::setup(const char * code) throw (ComponentErrors::CORBAProble
	}
	}
	//deactivate current receiver.....
	//deactivate current receiver.....
	if (!CORBA::is_nil(m_currentRecv)) {
	if (!CORBA::is_nil(m_currentRecv)) {
		try {
			m_currentRecv->deactivate();
			m_currentRecv->deactivate();
		}
		}
		catch (...) {
			ACS_LOG(LM_FULL_INFO,"CRecvBossCore::setup()",(LM_WARNING,"COULD_NOT_DEACTIVATE_CURRENT_RECEIVER"));
		}
	}
	unloadReceiver();
	unloadReceiver();
	try {
	try {
		derotatorPark();
		derotatorPark();
@@ -2024,6 +2034,13 @@ void CRecvBossCore::loadReceiver() throw (ComponentErrors::CouldntGetComponentEx
			changeBossStatus(Management::MNG_FAILURE);
			changeBossStatus(Management::MNG_FAILURE);
			throw Impl;
			throw Impl;
		}
		}
		catch (...) {
			_EXCPT(ComponentErrors::CouldntGetComponentExImpl,Impl,"CRecvBossCore::loadReceiver()");
			Impl.setComponentName((const char*)m_currentRecvInstance);
			m_currentRecv=Receivers::Receiver::_nil();
			changeBossStatus(Management::MNG_FAILURE);
			throw Impl;
		}
	}
	}
}
}


+1 −1
Original line number Original line Diff line number Diff line
@@ -69,7 +69,7 @@ void CCommandLine::Init(CConfiguration *config) throw (ComponentErrors::SocketEr
		throw impl;
		throw impl;
	}
	}
	// this will create the socket in blocking mode.....
	// this will create the socket in blocking mode.....
	if (Create(m_Error,STREAM)==FAIL) {
	if (Create(m_Error,STREAM,0,NULL,true)==FAIL) {
		_EXCPT_FROM_ERROR(ComponentErrors::IRALibraryResourceExImpl,dummy,m_Error);
		_EXCPT_FROM_ERROR(ComponentErrors::IRALibraryResourceExImpl,dummy,m_Error);
		dummy.setCode(m_Error.getErrorCode());
		dummy.setCode(m_Error.getErrorCode());
		dummy.setDescription((const char*)m_Error.getDescription());
		dummy.setDescription((const char*)m_Error.getDescription());
+2 −2
Original line number Original line Diff line number Diff line
@@ -86,7 +86,7 @@ void CSenderThread::runLoop()
			_IRA_LOGFILTER_LOG_EXCEPTION(dummy,LM_WARNING); //log as warn because this is the thread and no client is aware of that
			_IRA_LOGFILTER_LOG_EXCEPTION(dummy,LM_WARNING); //log as warn because this is the thread and no client is aware of that
		}
		}
		else {
		else {
			m_isConnected=true;  // the conneciton has been enstablished
			m_isConnected=true;  // the connection has been established
			IRA::CSecAreaResourceWrapper<CCommandLine> line=m_commandLine->Get();
			IRA::CSecAreaResourceWrapper<CCommandLine> line=m_commandLine->Get();
			line->clearStatusField(CCommandLine::DATALINERROR);
			line->clearStatusField(CCommandLine::DATALINERROR);
			ACS_LOG(LM_FULL_INFO,"CCSenderThread::runLoop()",(LM_INFO,"BACKEND_CONNECTED_TO_DATA_LINE"));
			ACS_LOG(LM_FULL_INFO,"CCSenderThread::runLoop()",(LM_INFO,"BACKEND_CONNECTED_TO_DATA_LINE"));
@@ -95,7 +95,7 @@ void CSenderThread::runLoop()
	}
	}
	else { //already connected...then try a new data reception
	else { //already connected...then try a new data reception
		res=m_backendSock.Receive(err,m_inputBuffer,DATABUFFERSIZE);
		res=m_backendSock.Receive(err,m_inputBuffer,DATABUFFERSIZE);
		if (res==0) { // backend disconnected...propably as a consequence of a terminate data transmission command.
		if (res==0) { // backend disconnected...probably as a consequence of a terminate data transmission command.
			// gets the access to the 
			// gets the access to the 
			IRA::CSecAreaResourceWrapper<CCommandLine> line=m_commandLine->Get();
			IRA::CSecAreaResourceWrapper<CCommandLine> line=m_commandLine->Get();
			line->clearStatusField(CCommandLine::DATALINERROR);
			line->clearStatusField(CCommandLine::DATALINERROR);
Loading