rts에서 패킷을 못받거나 인식못하는경우

yurina의 이미지

rts를 써서 채팅 서버를 돌리고 있는데요..

얘가 잘돌아가다가 가끔..정말 가끔 패킷을 못받아요..

아무리 보내두 인식을 못하는건지 못받는건지

프로세스는 죽지 않았는데 패킷을 받지 못합니다.

프로세스를 죽였다 살려야만이 잘 돌아가구요..

왜 그런건지 감을 잡게 해주세요~~~

아래 소스는 소스중 RTS부분입니다~~~함 뭐가 잘못됐는지
봐주세요

int main(int argc, char *argv[])                                                             
{
	int	sockfd=0, resockfd=0, tempfd=0;
	int	port=0, rtn=0, clilen=0, len=0;
	int	n=0, serv=0, rnum=0, disflag=0;
	char	buff[1000], flag[2];

	struct 	siginfo 	si;
	sigset_t		set;
	pthread_t		p_thread;
	
	struct	pollfd		pfd;
	struct	sockaddr_in	clientaddr;
	struct	MESSAGE		message;
	struct	ROOM_NUM	room_num;
	
	if(argc != 2)
	{
		printf("usage : main_process [port]\n");
		exit(1);
	}

	_opendebug("damo_chat");

	port 	= atoi(argv[1]);
	
	/*--------------------------------------*/
	/*	방번호 초기값			*/
	/*--------------------------------------*/
	memset(&room_num, 0x00, SZ_ROOM_NUM);
	room_num.flag = '0';
	room_num.room_num = 1;
	
	room_number.push_back(room_num);

	/*---------------------------------------------------------------*/
	/*	Signal Handler						 */
	/*---------------------------------------------------------------*/
	init_signal_handler();

	signal(SIGCHLD, SIG_IGN);	//child process가 죽으면 다시 살린다.

	/*---------------------------------------------------------------*/
	/* 	Real Time Signal Setting				 */
	/*---------------------------------------------------------------*/
	sigemptyset(&set);
	sigaddset(&set, SIGRTMIN);
	sigprocmask(SIG_BLOCK, &set, NULL);

	/*---------------------------------------------------------------*/
	/*	Socket Create						 */
	/*---------------------------------------------------------------*/
	sockfd 	= get_listener_fd(port);
	setup_sigio(sockfd);
	
	while(1)
	{
		clilen = sizeof(clientaddr);

		_debug(_fl, " SIGNAL WAIT\n");
		
		rtn 	= sigwaitinfo(&set, &si);

		/*------------------------------------------------------*/
		/*	receive rts					*/
		/*------------------------------------------------------*/
		if(rtn == SIGRTMIN)
		{
			resockfd = si.si_fd;

			if(resockfd == sockfd)
			{
				tempfd = get_connect_fd(sockfd);
				
				pfd.events 	= POLLIN | POLLPRI;
				pfd.revents	= 0;
				pfd.fd		= tempfd;				
				
				if(poll(&pfd, 1, 1000) > 0)
				{			
					_debug(_fl, "poll function \n");
							
					if( pfd.revents & POLLIN )
					{
						_debug(_fl, "깜딱~!\n");
						while(1)
						{    								
							memset(&message, 0x00, SZ_MESSAGE);
												
							if(read(tempfd, &message, SZ_MESSAGE) <= 0)
								break;	
								
							message.user_fd = tempfd;
							
							/*----------------------------------------------*/
							/*	Create Thread				*/
							/*----------------------------------------------*/							
							pthread_mutex_lock(&mutex_lock); 			
							
							rtn = pthread_create(&p_thread, NULL, send_message, (void *)&message);
							if(rtn < 0)
							{
								_debug(_fl, "thread create error resockfd[%d]\n", resockfd);
								break;
							}
							
							pthread_detach(p_thread);
							pthread_cond_wait(&thread_cond, &mutex_lock);
							pthread_mutex_unlock(&mutex_lock);
						}
					}
				}
				else
					continue;
			}
			else
			{
				memset(&buff, 0x00, sizeof(buff));				
				memset(&message, 0x00, SZ_MESSAGE);
				
				if(read(resockfd, &buff, sizeof(buff)) <= 0)
				{	
					memcpy(&message, buff, SZ_MESSAGE);
					
					/*----------------------------------------------*/
					/*	FD_INFO Struct find			*/
					/*----------------------------------------------*/							
					list<struct FD_INFO>::iterator		e_info;
					e_info = fd_info.begin();
					
					while(e_info != fd_info.end())
					{
						if(e_info->user_fd == resockfd)
						{
							memcpy(message.option, LOGOUT, 2);
							memcpy(message.user_id, e_info->user_id, sizeof(e_info->user_id));
							message.categorize1 = e_info->cate1;	
							message.categorize2 = e_info->cate2;
							message.room_num = e_info->room_num;
							disflag = 1;					
							break;
						}
						
						e_info++;	
					}	
					
				}
				
				if(disflag == 1)
					disflag = 0;				
				else		
					memcpy(&message, buff, SZ_MESSAGE);
					
				message.user_fd = resockfd;
								
				rtn = pthread_create(&p_thread, NULL, send_message, (void *)&message);					
				if(rtn < 0)
				{
					_debug(_fl, "thread create error resockfd[%d]\n", resockfd);
					continue;
				}
								
				pthread_detach(p_thread);	
				pthread_cond_wait(&thread_cond, &mutex_lock);
				pthread_mutex_unlock(&mutex_lock);							
			}
		}	//end if()
	}		//end while()

	_closedebug();
	return 1;
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.