15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CMonitorStatus

Maheshwar Gundelly -- gundelly@enuxsa.eas.asu.edu
Monday, April 15, 1996

Hi,

Environment : Windows NT 3.51 and 4.0 Beta / VC++ 4.0

Error  displayed is :
    
     Microsoft Visual C++ Debug Library

     Debug Assertion Failure
   
     Program : u:\gundelly\project\debug\project.exe
           
     File : afxwin.inl
     Line : 126

This problem is occuring when I include Invalidate() in the Start_Monitor1()
function of CMonitorStatus class.

Please give me suggestions as how to solve this problem with threads.

Thank you
	
Here is the code :

UINT MyThreadProc( LPVOID pParam )
{
	SOCKET	new_sock;
	SOCKADDR_IN	server_addr;
	char	server_mesg[1000];
	char	temp[80];
	int		ret;
	CMonitorStatus m_sts;
 	

	int	server_addr_len = sizeof( server_addr );


	new_sock = accept( sock, (struct sockaddr FAR *) &server_addr, ( 
int FAR *) &server_addr_len );
	if ( new_sock < 0 ) 
	{
		::MessageBox(NULL, "Error in  Accept", "INFO", MB_OK);

		return  0;
	}
	ret = recv( new_sock, server_mesg, 1000, 0);
	sscanf(server_mesg, "%d %d", &server_port, &reporting_port);
	sprintf(temp, "Server : %d Report %d ", server_port, reporting_port);
    closesocket(sock);
    closesocket(new_sock);
  	m_sts.Start_Monitor1();
	return 1;


}

 
// CProjectView derived  from CFormView class
void CProjectView::OnStartServer() 
{

	// TODO: Add your control notification handler code here

 	char szcommand[200];
	char wtemp[30];
	BOOL	  ret;
	STARTUPINFO	startup;
	PROCESS_INFORMATION proc_info;

	WORD	wVersionRequested;
	WSADATA	wsaData;
	SOCKADDR_IN	report_addr, tmp_addr;
	char		szHost_Name[40];
	int			tmp_len;
 
 
	int	err;
	void (CProjectView::*fun_p)() = 0;

	wVersionRequested = MAKEWORD(1,1);
	err = WSAStartup( wVersionRequested, &wsaData);
	if ( err != 0 )
	{
		MessageBox(" WsaStartup Error", "Error", MB_OK);
		return;
	}

	if ( LOBYTE( wsaData.wVersion ) != 1  ||
		 HIBYTE ( wsaData.wVersion ) != 1 ) 
	{
		WSACleanup();
		return;
	}

		 

	sock = socket( AF_INET, SOCK_STREAM, 0);
	if ( sock == INVALID_SOCKET )
	{
		MessageBox(" Invalid Socket", "S Error", MB_OK);
		return;
	}

	memset( (char *)&report_addr, NULL, sizeof(SOCKADDR_IN) );

	report_addr.sin_family	= AF_INET;
	report_addr.sin_addr.s_addr = INADDR_ANY;
	report_addr.sin_port = htons(0);

	ret = bind( sock, (struct sockaddr FAR *) &report_addr, sizeof( 
report_addr) );
	if ( ret == SOCKET_ERROR )
	{
		MessageBox("Error in binding report address", "Error", MB_OK);
		return;
	}

	ret = listen( sock, 5);
	if ( ret < 0 ) 
		MessageBox("Listen Error", "Error", MB_OK);


 
	
     
	startup.cb = sizeof ( STARTUPINFO);
	startup.lpReserved = NULL;
	startup.lpDesktop = NULL;
	startup.lpTitle = "Manager";
	startup.dwX = 100;
	startup.dwY = 100;
	startup.dwXSize = 100;
	startup.dwYSize = 100;
	startup.dwFlags =  0;
	startup.dwFlags = STARTF_USESIZE | STARTF_USEPOSITION;
  	startup.cbReserved2 = 0;
	startup.lpReserved2 = NULL;

	memset(szcommand, NULL, 200);
	CProjectDoc* pDoc = GetDocument();
	UpdateData(TRUE);
	pDoc->m_server.set_prog_name(m_Program_Name);
	pDoc->m_server.set_port_number(m_Port_Number);

 	buf_ptr = m_Program_Name.GetBuffer(40);

 	strcpy(szcommand,  buf_ptr);
	//MessageBox(buf_ptr, "buf value", MB_OK);

	gethostname(szHost_Name, sizeof(szHost_Name));
	tmp_len = sizeof( tmp_addr);
	if ( getsockname(sock, ( struct sockaddr FAR *) &tmp_addr, 
			( int FAR *) &tmp_len) == SOCKET_ERROR )
	{
		MessageBox("Error Retrieving the port number", 
"getsockname",MB_OK) ;
		return;
	}

 	strcat( szcommand, " -calypso-verbose  -calypso-report ");
 	strcat(szcommand   , szHost_Name);
	strcat(szcommand, "   ");
 	tmp_len = strlen(szcommand);
    port_number = ntohs(tmp_addr.sin_port);
 	sprintf(szcommand + tmp_len -1," %d", port_number );
 


	ret = CreateProcess(  NULL, szcommand, NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
				      NULL, NULL, &startup, &proc_info );

	if (!ret )
	{
		sprintf(wtemp," Check the input. Error return is %d 
errorno %d", ret, errno);
	 	MessageBox(wtemp, "Error " , MB_OK);
		return;
	}



	first = NULL;  // pointer to first element in the list of worker processes
	

	CProjectView *pNewObject;

 	pNewObject = new CProjectView;
	AfxBeginThread(MyThreadProc, pNewObject);

 	CButton *pButton = (CButton *) GetDlgItem(IDC_START_SERVER);

 	pButton->EnableWindow(FALSE);
 
 
 
}


void CMonitorStatus::Start_Monitor1()
{
	SOCKET msock;
	SOCKADDR_IN dest_addr;
	char	szHost_Name[40];
	PHOSTENT	phe;
	char	result[1000], *str;
	int	ret;
	int	len, i=0, j = 0, k = 0, index = 0, flag, step_number;
 
 
	msock = socket( AF_INET, SOCK_STREAM, 0);
	if ( msock == INVALID_SOCKET )
	{
		MessageBox(" Invalid Socket", "Socket Error", MB_OK);
		return;
	}

	memset( (char *)&dest_addr, NULL, sizeof(SOCKADDR_IN) );

	gethostname(szHost_Name, sizeof(szHost_Name));
	phe = gethostbyname(szHost_Name);
	if ( phe == NULL )
	{
		MessageBox("gethostbyname failure", "Error", MB_OK);
		return;
	}


	dest_addr.sin_family	= AF_INET;
	memcpy((char FAR *)&(dest_addr.sin_addr), phe->h_addr, phe->h_length);
	dest_addr.sin_port = htons(reporting_port);

	if ( connect(msock, (PSOCKADDR)&dest_addr, sizeof(dest_addr)) < 0 )
	{
		MessageBox("Connect failure", "Error", MB_OK);
		return;
	}
		
	FILE *fp;
	fp = fopen("u:\\gundelly\\out.txt", "w");

	if ( fp == NULL )
		MessageBox("Error Opening file", "Err", MB_OK);
	else
	{
    	while ( 1 )
	{
	   memset( result, NULL, sizeof( result));
	/* ********************
		this statement gives error. With out this appl works ok expect
		no redrawing takes place.
	****************************/

 	   Invalidate();
	/*****************/
	   ret = recv(msock, (char *)&len, sizeof(int), 0);
 	   ret = recv(msock, (char FAR *) result, len, 0);
	   if ( ret > 0 ) 
	   {
		str = result;
		start_of_data = 1;
		if ( *str != '\0' )
		{
			sscanf(result, "%d", &step_number);
			flag = 0;
			if ( i != 0 )
			{
				for ( k = 0; k < i ; k++ )
				{
				  if( monitor_data[k].step_number == step_number ) 
				  {
					flag = 1;
					break;
				  }
				}
			}
					
			if ( i == 0 ) 
			{
				index = 0;
				i++;
			}
			else if ( flag )
			{
				index = k;
				flag = 0;
			}
			else if ( !flag )
			{
				index = i;
				i++;
			}

			monitor_data[index].step_number = step_number;
			while ( *str++ != ' ');
			j = 0;
			while ( *str != '\0' )
			{
				if ( *str != ' ' && *str != '\n' )
				{
					monitor_data[index].status[j] = *str;
					j++;
					}
					str++;

				}
				monitor_data[index].number_of_steps = j;
				total_steps = i ;
					  
			}  // if str != NULL
		} // if ( ret > 0 )
		else
			end_of_data = 1;

		fprintf(fp, " %d %s",len,  result);
			 
 		if ( ret == 0 || ret == SOCKET_ERROR)
 		{
 			MessageBox( "recv done", "Done", MB_OK);
 			break; 
 		}
		
 	} // end of while true
	}  // end of file open
	fclose(fp);
}

void CMonitorStatus::OnDraw(CDC* pDC)
{  
 /* Code for drawing */

}



 














							Mahesh



Maheshwar Gundelly			Phone # : 602-894-6151
950 South Terrace Road			Email : gundelly@enuxsa.eas.asu.edu
#C343
Tempe Arizona - 85281.









Frederic Steppe -- FredericS@msn.com
Friday, April 19, 1996

>Environment : Windows NT 3.51 and 4.0 Beta / VC++ 4.0
>This problem is occuring when I include Invalidate() in the Start_Monitor1()
>function of CMonitorStatus class.
>	CMonitorStatus m_sts;
>  	m_sts.Start_Monitor1();
>void CMonitorStatus::Start_Monitor1()
>{
>	/* ********************
>		this statement gives error. With out this appl works ok expect
>		no redrawing takes place.
>	****************************/
>	   Invalidate();
>	/*****************/

As far as I can see, you never create the windows associated with your 
CMonitorStatus instance.  Remember that the constructor doesn't create the 
window, just the object.  Invalidate() is checking that your m_hWnd member is 
a valid window handle, what it isn't, so you get an assertion.
Just call the m_sts.Create(...) and anything should be OK.

Frederic Steppe (frederics@msn.com)












							Mahesh



Maheshwar Gundelly			Phone # : 602-894-6151
950 South Terrace Road			Email : gundelly@enuxsa.eas.asu.edu
#C343
Tempe Arizona - 85281.











| Вернуться в корень Архива |