Ejemplo n.º 1
0
void CIntGraph::Connect (DWORD dwFromID, DWORD dwToID)

//	Connect
//
//	Connects the two nodes

	{
	SNode *pFrom = GetNode((int)dwFromID);
	SNode *pTo = GetNode((int)dwToID);

	//	Add the forward connection

	int iConnection = AllocConnection();
	SConnection *pConnection = GetConnection(iConnection);
	pConnection->iFrom = (int)dwFromID;
	pConnection->iTo = (int)dwToID;
	pConnection->iNext = pFrom->iFirstForward;
	pFrom->iFirstForward = iConnection;

	//	Add the backwards connection

	iConnection = AllocConnection();
	pConnection = GetConnection(iConnection);
	pConnection->iFrom = (int)dwToID;
	pConnection->iTo = (int)dwFromID;
	pConnection->iNext = pTo->iFirstBackward;
	pTo->iFirstBackward = iConnection;
	}
Ejemplo n.º 2
0
static int CompletionLoop(SOCKET acceptor)
{
    struct sockaddr_in addr;
    int addrlen = sizeof(addr);
    SOCKET socknew = accept(acceptor, (struct sockaddr*)&addr, &addrlen);
    if (socknew != INVALID_SOCKET)
    {
        connection_t* data = AllocConnection(socknew);
        fprintf(stderr, ("socket %d accepted at %s.\n"), socknew, Now());
        if (data)
        {
            PostRecvRequest(data);
        }
    }
    else
    {
        if (WSAGetLastError() != WSAEWOULDBLOCK)
        {
            fprintf(stderr, ("accept() failed, %s"), LAST_ERROR_MSG);
            return -1;
        }
        else
        {
            SleepEx(50, TRUE); /* make current thread alertable */
        }
    }
    return 0;
}