AEPerr(AEP_F_AEP_INIT,AEP_R_SETBNCALLBACK_FAILURE);
AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_SETBNCALLBACK_FAILURE);
static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection)	{	int count;	AEP_RV rv = AEP_R_OK;	/*Get the current process id*/	pid_t curr_pid;	CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);	curr_pid = getpid();	/*Check if this is the first time this is being called from the current	  process*/	if (recorded_pid != curr_pid)		{		/*Remember our pid so we can check if we're in a new process*/		recorded_pid = curr_pid;		/*Call Finalize to make sure we have not inherited some data		  from a parent process*/		p_AEP_Finalize();     		/*Initialise the AEP API*/		rv = p_AEP_Initialize(NULL);		if (rv != AEP_R_OK)			{			AEPerr(AEP_F_AEP_INIT,AEP_R_INIT_FAILURE);			recorded_pid = 0;			goto end;			}		/*Set the AEP big num call back functions*/		rv = p_AEP_SetBNCallBacks(&GetBigNumSize, &MakeAEPBigNum,			&ConvertAEPBigNum);		if (rv != AEP_R_OK)			{			AEPerr(AEP_F_AEP_INIT,AEP_R_SETBNCALLBACK_FAILURE);			recorded_pid = 0;			goto end;			}#ifdef AEPRAND		/*Reset the rand byte count*/		rand_block_bytes = 0;#endif		/*Init the structures*/		for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)			{			aep_app_conn_table[count].conn_state = NotConnected;			aep_app_conn_table[count].conn_hndl  = 0;			}		/*Open a connection*/		rv = p_AEP_OpenConnection(phConnection);		if (rv != AEP_R_OK)			{			AEPerr(AEP_F_AEP_INIT,AEP_R_UNIT_FAILURE);			recorded_pid = 0;			goto end;			}		aep_app_conn_table[0].conn_state = InUse;		aep_app_conn_table[0].conn_hndl = *phConnection;		goto end;		}	/*Check the existing connections to see if we can find a free one*/	for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)		{		if (aep_app_conn_table[count].conn_state == Connected)			{			aep_app_conn_table[count].conn_state = InUse;			*phConnection = aep_app_conn_table[count].conn_hndl;			goto end;			}		}	/*If no connections available, we're going to have to try	  to open a new one*/	for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)		{		if (aep_app_conn_table[count].conn_state == NotConnected)			{			/*Open a connection*/			rv = p_AEP_OpenConnection(phConnection);			if (rv != AEP_R_OK)				{	      				AEPerr(AEP_F_AEP_INIT,AEP_R_UNIT_FAILURE);				goto end;				}			aep_app_conn_table[count].conn_state = InUse;			aep_app_conn_table[count].conn_hndl = *phConnection;			goto end;			}		}	rv = AEP_R_GENERAL_ERROR; end:	CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);	return rv;	}