Esempio n. 1
0
/*
 * Try to establish an active xpt connection
 * target is the server address and worker login data to use for connecting
 * Returns false on error or if already connected
 */
bool xptClient_connect(xptClient_t* xptClient, generalRequestTarget_t* target)
{
	// are we already connected?
	if( xptClient->disconnected == false )
		return false;
	// first try to connect to the given host/port
#ifdef _WIN32
	SOCKET clientSocket = xptClient_openConnection(target->ip, target->port);
	if( clientSocket == SOCKET_ERROR )
		return false;
#else
  int clientSocket = xptClient_openConnection(target->ip, target->port);
		if( clientSocket == 0 )
					return false;
#endif

#ifdef _WIN32
	// set socket as non-blocking
	unsigned int nonblocking=1;
	unsigned int cbRet;
	WSAIoctl(clientSocket, FIONBIO, &nonblocking, sizeof(nonblocking), NULL, 0, (LPDWORD)&cbRet, NULL, NULL);
#else
  int flags, err;
  flags = fcntl(clientSocket, F_GETFL, 0); 
  flags |= O_NONBLOCK;
  err = fcntl(clientSocket, F_SETFL, flags); //ignore errors for now..
#endif
	// initialize the connection details
	xptClient->clientSocket = clientSocket;

	strncpy(xptClient->username, target->authUser ,127);
	strncpy(xptClient->password, target->authPass, 127);
	// reset old work info
	memset(&xptClient->blockWorkInfo, 0x00, sizeof(xptBlockWorkInfo_t));
	// send worker login
	xptClient_sendWorkerLogin(xptClient);
	// mark as connected
	xptClient->disconnected = false;
	// return success
	return true;
}
Esempio n. 2
0
/*
 * Try to establish an active xpt connection
 * target is the server address and worker login data to use for connecting
 * Returns false on error or if already connected
 */
bool xptClient_connect(xptClient_t* xptClient, generalRequestTarget_t* target)
{
	// are we already connected?
	if( xptClient->disconnected == false )
		return false;
	// first try to connect to the given host/port
	SOCKET clientSocket = xptClient_openConnection(target->ip, target->port);
	if( clientSocket == SOCKET_ERROR )
		return false;
	// set socket as non-blocking
	unsigned int nonblocking=1;
	unsigned int cbRet;
	WSAIoctl(clientSocket, FIONBIO, &nonblocking, sizeof(nonblocking), NULL, 0, (LPDWORD)&cbRet, NULL, NULL);
	// initialize the connection details
	xptClient->clientSocket = clientSocket;
	strcpy_s(xptClient->username, 127, target->authUser);
	strcpy_s(xptClient->password, 127, target->authPass);
	// send worker login
	xptClient_sendWorkerLogin(xptClient);
	// mark as connected
	xptClient->disconnected = false;
	// return success
	return true;
}