Exemplo n.º 1
0
// Stop all links
void StopAllLink(HUB *h)
{
	LINK **link_list;
	UINT num_link;
	UINT i;
	// Validate arguments
	if (h == NULL)
	{
		return;
	}

	LockList(h->LinkList);
	{
		link_list = ToArray(h->LinkList);
		num_link = LIST_NUM(h->LinkList);
		for (i = 0;i < num_link;i++)
		{
			AddRef(link_list[i]->ref);
		}
	}
	UnlockList(h->LinkList);

	for (i = 0;i < num_link;i++)
	{
		StopLink(link_list[i]);
		ReleaseLink(link_list[i]);
	}

	Free(link_list);
}
Exemplo n.º 2
0
BOOL CNetSock::AttachSocket(SOCKET hSocket, SOCKADDR_IN *pClientAddress)
{
	StopLink();
	
	m_hSocket = hSocket;
	m_Addr = *pClientAddress;
	
	m_bAttached = TRUE;
	
	m_Thread.SetName(_T("NetSock_AttachSocket"));
	return m_Thread.Create(this, THREAD_ID_SOCK);
}
Exemplo n.º 3
0
// リンクをオフラインにする
void SetLinkOffline(LINK *k)
{
	// 引数チェック
	if (k == NULL)
	{
		return;
	}

	if (k->Offline)
	{
		return;
	}

	StopLink(k);
	k->Offline = true;
}
Exemplo n.º 4
0
// Make the link off-line
void SetLinkOffline(LINK *k)
{
	// Validate arguments
	if (k == NULL)
	{
		return;
	}

	if (k->Offline)
	{
		return;
	}

	StopLink(k);
	k->Offline = true;
}
Exemplo n.º 5
0
BOOL CNetSock::CreateLink(LPCTSTR ServerName, int ServerPort)
{
	StopLink();
	
	m_hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(m_hSocket == INVALID_SOCKET)
		return FALSE;

//	int flag = 1;
//	setsockopt(m_hSocket,
//							IPPROTO_TCP,
//							TCP_NODELAY,
//							(char *) &flag,
//							sizeof(int));

	m_bEncryption = FALSE;
	m_ServerName = ServerName;
	m_ServerPort = ServerPort;
	
	m_Thread.SetName(_T("NetSock_CreateLink"));
	return m_Thread.Create(this, THREAD_ID_SOCK);
}
Exemplo n.º 6
0
	/* \fn  DetachProcessor
	  \brief Delete device from link,
	         but device object is not delete in function
	  \return void
	*/
	virtual bool DetachProcessor()
	{
		if (StopLink())
		{
			bool rtVal = true;
			if (m_section.try_lock())
			{
				p_Processor = 0;
				//p_Producer->p_LinkOn = NULL_POINTER;
				m_section.unlock();
			}
			else
			{
				rtVal = false;
				WRITE_LOG(severity_level::warning, "");
			}
			return rtVal;
		}
		else
		{
			WRITE_LOG(severity_level::error, "");
		}
		return false;
	}
Exemplo n.º 7
0
	/* \fn  DetachConsumer
	  \brief Delete device from link,
	         but device object is not delete in function
	  \return void
	*/
	virtual bool DetachConsumer()
	{
		if (StopLink())
		{
			bool rtVal = true;
			if (m_section.try_lock())
			{
				p_Consumer = 0;
				//p_Producer->linkInPool.Del((void*)this);
				m_section.unlock();
			}
			else
			{
				rtVal = false;
				WRITE_LOG(severity_level::warning, "");
			}
			return rtVal;
		}
		else
		{
			WRITE_LOG(severity_level::error, "");
		}
		return false;
	}
Exemplo n.º 8
0
	/* \fn  AttachProcessor
	  \brief Add device to link
	  \param[in] IProcessor<T1, T2>* pProcessor = (IProcessor<T1, T2>*)&processorObj;
	  \return bool
	*/
	virtual bool AttachProcessor(IProcessor<T1, T2>* pProcessor)
	{
		if (StopLink())
		{
			bool rtVal = true;
			if (m_section.try_lock())
			{
				p_Processor = pProcessor;
				//p_Producer->p_LinkOn = (void*)this;
				m_section.unlock();
			}
			else
			{
				rtVal = false;
				WRITE_LOG(severity_level::warning, "");
			}
			return rtVal;
		}
		else
		{
			WRITE_LOG(severity_level::error, "");
		}
		return false;
	}
Exemplo n.º 9
0
	/* \fn  AttachProducer
	  \brief Add producer to link
	  \param[in] IProducer<T1>* pProducer = (IProducer<T1>*)&producerObj;
	  \return bool
	*/
	virtual bool AttachProducer(IProducer<T1>* pProducer) 
	{
		if (StopLink())
		{
			bool rtVal = true;
			if (m_section.try_lock())
			{
				p_Producer = pProducer;
				//p_Producer->linkOutPool.Add((void*)this);
				m_section.unlock();
			}
			else
			{
				rtVal = false;
				WRITE_LOG(severity_level::warning, "");
			}
			return rtVal;
		}
		else
		{
			WRITE_LOG(severity_level::error, "");
		}
		return false;
	}
Exemplo n.º 10
0
	/* \fn  Unitial
	  \brief Unitial Link
	*/
	virtual void Unitial()
	{
		try
		{
			if (m_handle != INVALID_HANDLE)
			{
				//Do something here
				//...
				StopLink();
				DetachProducer();
				DetachConsumer();
				DetachProcessor();
				ForceEnd();
				m_handle = INVALID_HANDLE;
			}
			m_status = LK_UNITIALED;
		}
		catch (...)
		{
			WRITE_LOG(severity_level::error, "");
			return;
		}
		return;
	}
Exemplo n.º 11
0
CNetSock::~CNetSock()
{
	StopLink();
	delete []m_pTempBuf;
}