sqldata/sqldata.cpp
// Start communication sessions with worker processes
Start communication sessions with worker processes
Start communication sessions with worker processes
int SqlData::StartSessions()
{
	HANDLE hp = CreateNamedPipe(SQLDATA_NAMED_PIPE, PIPE_ACCESS_DUPLEX, 
		PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 8192, 8192, 0, NULL);
	if(_workers > 0)
	{
		for(int i = 0; i < _max_sessions; i++)
			_spawnl(_P_NOWAIT, _worker_exe.c_str(), _worker_exe.c_str(), NULL);
	}
	bool more = true;
	while(more)
	{
		BOOL cn = ConnectNamedPipe(hp, NULL);
		bool connected = (cn == TRUE) ? true : false;
		if(cn == FALSE)
		{
			size_t err = GetLastError();
			if(err == ERROR_PIPE_CONNECTED)
				connected = true;
		}
		if(connected == false)
			CloseHandle(hp);
		if(connected == true)
		{
			SqlDataPipe *dp = new SqlDataPipe();
			dp->sd = this;
			dp->hp = hp;
			_beginthreadex(NULL, 0, &SqlData::StartWorkerS, dp, 0, NULL);
		}
		hp = CreateNamedPipe(SQLDATA_NAMED_PIPE, PIPE_ACCESS_DUPLEX, 
			PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 8192, 8192, 0, NULL);
	}
	return 0;
}
int SqlData :: StartSessions ( ) { HANDLE hp = CreateNamedPipe ( SQLDATA_NAMED_PIPE , PIPE_ACCESS_DUPLEX , PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT , PIPE_UNLIMITED_INSTANCES , 8192 , 8192 , 0 , NULL ) ; if ( _workers > 0 ) { for ( int i = 0 ; i < _max_sessions ; i ++ ) _spawnl ( _P_NOWAIT , _worker_exe . c_str ( ) , _worker_exe . c_str ( ) , NULL ) ; } bool more = true ; while ( more ) { BOOL cn = ConnectNamedPipe ( hp , NULL ) ; bool connected = ( cn == TRUE ) ? true : false ; if ( cn == FALSE ) { size_t err = GetLastError ( ) ; if ( err == ERROR_PIPE_CONNECTED ) connected = true ; } if ( connected == false ) CloseHandle ( hp ) ; if ( connected == true ) { SqlDataPipe * dp = new SqlDataPipe ( ) ; dp -> sd = this ; dp -> hp = hp ; _beginthreadex ( NULL , 0 , & SqlData :: StartWorkerS , dp , 0 , NULL ) ; } hp = CreateNamedPipe ( SQLDATA_NAMED_PIPE , PIPE_ACCESS_DUPLEX , PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT , PIPE_UNLIMITED_INSTANCES , 8192 , 8192 , 0 , NULL ) ; } return 0 ; }
Start communication sessions with worker processes
Start communication sessions with worker processes
// Create the first instance of the communication pipe // Launch worker processes // Connection loop // Wait for client connection // A connection error // if ERROR_PIPE_CONNECTED is returned, it is normal (client connected before ConnectNamedPipe called) // If connection failed, for example, ERROR_NO_DATA means that client closed pipe on its end, reopen // A client connected, start a worker thread // Create another instance for further connections