closedir에관한 질문입니다.

liebeym의 이미지

pthread를 이용해서 네트워크 프로그램을 만들고 있습니다.
아래 코드는 내부에 지정한 directory 를 읽어서 vectror contatiner로 저장하고 있습니다.
Receive에 관한건 callback형식으로 만들었습니다.

문제는 "" closedir()""을 부르면 Receive함수를 부르지 못하고 그냥 끝나 버립니다.
그래서 "" closedir()"을 제거하니 Receive함수가 불립니다.

이것이 어떤 signal을 발생시켜 막는걸까요..
여러분의 조언을 구합니다.

1. 내부에 지정한 디렉토리를 읽어서 Vector container로 저장

 void CFileManager::getSharedFileInfo()
     39 {
     40   struct dirent *dirp;
     41   int nsize = 0;
     42     DIR *dp;
     43 
     44   // 공유 디렉터리를 연다
     45   if( (dp = opendir(m_strshareddir)) == NULL)
     46   {
     47     fputs("shared dir open error\n", stderr);
     48     return ;
     49   }
     50 
     51   // 디렉터리에 있는 내용을 읽어서 vector에 집어 넣는다.
     52   while((dirp = readdir(dp)) != NULL)
     53   {
     54     nsize = 0;
     55 
     56     // 디렉터리가 아니고 일반 파일이 인지 검사, 파일 용량도 가지고 옴
     57     if(checkFile(1, dirp->d_name, &nsize) < 0)
     58     {
     59       continue;
     60     }
     58     {
     59       continue;
     60     }
     61 
     62     // File 정보를 저장할 구조체를 선언하여 해당 값을 셋팅 한다
     63    struct file_info *file = (struct file_info*)malloc(sizeof(file_info));
     64     file->strfname = strdup(dirp->d_name);
     65     file->strexpand = tokenfile(dirp->d_name);
     66     file->strdir = strdup(m_strshareddir);
     67     file->nfsize = nsize;
     68 
     69     m_asharedfiles.push_back(file);
     70   } // end while  
     71   //여기서 Closedir을 부르면 문제가 있습니다.
     72       if(closedir(dp) <0 )
     73         fprintf(stdout,"Can'tclosedirecotry%s\n",m_strshareddir);
     75   
     76 
     77 
     78 }

위에 코드를 부르는곳

void CkMuleClient::DirectoryInfo(void)
    146 {
    147    fileinfo->getSharedFileInfo(); /* shared directory 정보를 읽어옮 */
    148     
    149         /* 현재 Client의 공유파일 개수를 저장 */
    150         m_CurShareFilecount = fileinfo->m_asharedfiles.size();
    151 }

실제 메인에서 쓰이는 코드

 CkMuleClient  theApp;
    theApp.fileinfo = new CFileManager(theApp.prefer->M_SHAREDDIR,               
                                             theApp.prefer->M_DOWNDIR,NULL);
     theApp.DirectoryInfo();
     theApp.Socketinit(port); /* Socket 초기화 */
     theApp.SendPacket(..........); /*Packet 을 보냄 */
     /* Pakcet을 받길 기다림 */
     

2. 이함수가 호출됨으로서 callback함수를 부른다.

     124 int CkMuleClient::SocketInit( uint32 UDPport)
    125 {   
    126         //UDP server socket생성
    127         m_udp_sock= new CUDPSocket( UDPport );
    128         m_udp_sock->InitClient();
    129         m_udp_sock->SetCallBack(this);
    130         return 0;
    131 }

 void CUDPSocket:: SetCallBack(CAbstractApp *call)
    134 {
    135   m_theApp= call;
    136 }   
    137 

pthread에서 create할때 넣어주는 function pointer

  
   140 {
                .........
    141     str_len= recvfrom(sock, BUFF, BUFFSIZE, 0, (struct sockaddr *)&(temp_addr), &clnt_addr_size);
    142 
    143     if( str_len> 0){
    144 
    145       fprintf(stderr, "패킷 수신!!!n");
    146       //패킷이 수신된 경우이므로 할일을 하면된다.
    147       
    148       fprintf(stderr, "콜백 호출전!!!n");
             [color=red]  //여기서 callback함수를 부른다.
    149       sock_obj->m_theApp->OnReceive(str_len, BUFF, temp_addr);
    150   ............. [/color]
          }

위서서 호출되어지는 main class에 있는 callback 함수
139 virtual bool OnReceive(unsigned int size, char *rdata, struct sockaddr_in);

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.