Пример #1
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
socket_t *Net_ListenSocket(int port)
{
	int newsock;
	socket_t *sock;

	newsock = WINS_OpenReliableSocket(port);
	if (newsock == -1) return NULL;

	if (WINS_Listen(newsock) == -1)
	{
		WINS_CloseSocket(newsock);
		return NULL;
	} //end if
	sock = Net_AllocSocket();
	if (sock == NULL)
	{
		WINS_CloseSocket(newsock);
		return NULL;
	} //end if
	sock->socket = newsock;
	WINS_GetSocketAddr(newsock, &sock->addr);
	WinPrint("listen socket opened at %s\n", WINS_AddrToString(&sock->addr));
	//
	return sock;
} //end of the function Net_ListenSocket
Пример #2
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
socket_t *Net_Connect(address_t *address, int port)
{
	int newsock;
	socket_t *sock;
	sockaddr_t sendaddr;

	// see if we can resolve the host name
	WINS_StringToAddr(address->ip, &sendaddr);

  newsock = WINS_OpenReliableSocket(port);
	if (newsock == -1) return NULL;

	sock = Net_AllocSocket();
	if (sock == NULL)
	{
		WINS_CloseSocket(newsock);
		return NULL;
	} //end if
	sock->socket = newsock;

	//connect to the host
	if (WINS_Connect(newsock, &sendaddr) == -1)
	{
		Net_FreeSocket(sock);
		WINS_CloseSocket(newsock);
		WinPrint("Net_Connect: error connecting\n");
		return NULL;
	} //end if

	memcpy(&sock->addr, &sendaddr, sizeof(sockaddr_t));
	//now we can send messages
	//
	return sock;
} //end of the function Net_Connect
Пример #3
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void WINS_Shutdown( void ){
	//WINS_Listen(0);
	WINS_CloseSocket( net_controlsocket );
//	WSACleanup();
	//
	//WinPrint("Winsock Shutdown\n");
} //end of the function WINS_Shutdown
Пример #4
0
void WINS_Shutdown (void)
{
	WINS_Listen (false);
	WINS_CloseSocket (net_controlsocket);
	if (--winsock_initialized == 0)
		pWSACleanup ();
}
Пример #5
0
void WINS_Shutdown (void)
{
	WINS_Listen (false);
	WINS_CloseSocket (net_controlsocket);
	if (--winsock_initialized == 0)
	{
		pWSACleanup ();
		FreeLibrary(hInst);
		hInst=NULL;
	}
}
Пример #6
0
void WINS_Listen (qboolean state)
{
	// enable listening
	if (state)
	{
		if (net_acceptsocket != -1)
			return;
		if ((net_acceptsocket = WINS_OpenSocket (net_hostport)) == -1)
			Sys_Error ("WINS_Listen: Unable to open accept socket\n");
		return;
	}

	// disable listening
	if (net_acceptsocket == -1)
		return;
	WINS_CloseSocket (net_acceptsocket);
	net_acceptsocket = -1;
}
Пример #7
0
void
WINS_Listen(qboolean state)
{
    /* enable listening */
    if (state) {
	if (net_acceptsocket != -1)
	    return;
	if ((net_acceptsocket = WINS_OpenSocket(net_hostport)) == -1)
	    Sys_Error("%s: Unable to open accept socket", __func__);
	return;
    }

    /* disable listening */
    if (net_acceptsocket == -1)
	return;

    WINS_CloseSocket(net_acceptsocket);
    net_acceptsocket = -1;
}
Пример #8
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
socket_t *Net_Accept(socket_t *sock)
{
	int newsocket;
	sockaddr_t sendaddr;
	socket_t *newsock;

	newsocket = WINS_Accept(sock->socket, &sendaddr);
	if (newsocket == -1) return NULL;

	newsock = Net_AllocSocket();
	if (newsock == NULL)
	{
		WINS_CloseSocket(newsocket);
		return NULL;
	} //end if
	newsock->socket = newsocket;
	memcpy(&newsock->addr, &sendaddr, sizeof(sockaddr_t));
	//
	return newsock;
} //end of the function Net_Accept
Пример #9
0
void WINS_Listen (qboolean state)
{
#ifdef ID_PC
	// enable listening
	if (state)
	{
		if (net_acceptsocket != -1)
			return;
		WINS_GetLocalAddress();
		if ((net_acceptsocket = WINS_OpenSocket (net_hostport)) == -1)
			Sys_Error ("WINS_Listen: Unable to open accept socket\n");
		return;
	}

	// disable listening
	if (net_acceptsocket == -1)
		return;
	WINS_CloseSocket (net_acceptsocket);
	net_acceptsocket = -1;
#endif
}
Пример #10
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
void Net_Disconnect(socket_t *sock)
{
	WINS_CloseSocket(sock->socket);
	Net_FreeSocket(sock);
} //end of the function Net_Disconnect