linux__select__조작하다

4227 단어
select                         ,          ,func1(select();) func2(select();)           ,         ,           。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/poll.h>
#include <linux/soundcard.h>
#include <string.h>
 #include <signal.h>
#include <time.h>
#include <pthread.h>


#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#include <stdlib.h>

#include <pthread.h>

#include <errno.h>
#include <string.h>

 /*--------------------------------------------------------------------------------------------*/



void  CTcpServer::findMaxClientsockId()
 {
     CycleList *pList=CmdSockList.GetHead();
     int maxid=0;
     maxid=m_ServerSockId;
                         while(pList!=NULL)
                         {
                                   if(pList->lSocket>=maxid)
                                   {
                                          maxid=pList->lSocket;
                                   }
    	                   pList=CmdSockList.GetNext(pList);
                         }
     
        m_maxClientsockId = maxid;
}
extern int gTcpSvrQuit;
 int   CTcpServer::  CreateTcpServer()
 {
            
                fd_set  acp_fdsr; //         
                

                  
                    
         
                struct timeval tv;
                m_CurrentConnCnt =0;
                 sin_size = sizeof(client_addr);
                  m_maxClientsockId = m_ServerSockId;
                 CycleList *pList=CmdSockList.GetHead(); 

              while(gTcpSvrQuit)
               {                             
                            FD_ZERO(&fdsr);/// acp_fdsr
                            FD_SET(m_ServerSockId,&fdsr);                       
                           tv.tv_sec = 30;
                           tv.tv_usec =0;    
                           pList=CmdSockList.GetHead();
                          while(pList!=NULL)
                          {
    	                        FD_SET(pList->lSocket,&fdsr);
                                     ///   printf("lSocket is %d
",pList->lSocket); pList=CmdSockList.GetNext(pList); } ret = select(m_maxClientsockId +1,&fdsr,NULL,NULL,&tv); if(ret <0) { perror("select error!
"); break; } else if(ret ==0) { /// printf("timeout
"); continue; } while(pList!=NULL) { if(FD_ISSET(pList->lSocket,&fdsr)) { } pList=pList->lNext; } if(FD_ISSET(m_ServerSockId,&fdsr)) { new_fd = accept(m_ServerSockId,(struct sockaddr *)&client_addr,&sin_size); if(new_fd <=0) { perror("accept error::"); continue; } } } return 0; }
    。。。

좋은 웹페이지 즐겨찾기