请问socket中select函数的用法是怎样的?它通常是用在什么地方?
int select(
  int nfds,                           
  fd_set FAR *readfds,               
  fd_set FAR *writefds,              
  fd_set FAR *exceptfds,             
  const struct timeval FAR *timeout  
);
它的每个参数又是怎样呢?请大虾们能不能详细地说一下select函数的问题!!!!
谢谢

解决方案 »

  1.   

    强烈建议你去看MSDN
    The Windows Sockets select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O.int select (
      int nfds,                           
      fd_set FAR * readfds,               
      fd_set FAR * writefds,              
      fd_set FAR * exceptfds,             
      const struct timeval FAR * timeout  
    );
     
    Parameters
    nfds 
    [in] This parameter is ignored; it is included only for compatibility with Berkeley sockets. 
    readfds 
    [in/out] An optional pointer to a set of sockets to be checked for readability. 
    writefds 
    [in/out] An optional pointer to a set of sockets to be checked for writability 
    exceptfds 
    [in/out] An optional pointer to a set of sockets to be checked for errors. 
    timeout 
    [in] The maximum time for select to wait, or NULL for blocking operation. Return Values
    The select function returns the total number of socket handles that are ready and contained in the FD_SET structures, zero if the time limit expired, or SOCKET_ERROR if an error occurred. If the return value is SOCKET_ERROR, WSAGetLastError can be used to retrieve a specific error code.Error Codes
    WSANOTINITIALISED 
    A successful WSAStartup must occur before using this function. 
    WSAEFAULT The Windows Sockets implementation was unable to allocate needed resources for its internal operations, or the readfds, writefds, exceptfds, or timeval parameters are not part of the user address space. WSAENETDOWN The network subsystem has failed. WSAEINVAL The timeout value is not valid, or all three descriptor parameters were NULL. WSAEINTR A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall. WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function. WSAENOTSOCK One of the descriptor sets contains an entry that is not a socket. 
      

  2.   

    select 也就是事件通知为了不让socket在那儿瞎忙。于是有了select,当有数据进来了,可读了,select就告诉你,你现在可以recv了。当有数据可写了,select就告诉你,你现在可以send了。
      

  3.   

    还有一个问题想问一下各位,如果创建了socket后,用send来发数据,用select来用为事件通知,但我不用recv来读数据行不行?如果行的话,有没有其它的api函数可以读取socket传过来的数据?或者是自己写的什么方法可以读取?
      

  4.   

    读取数据有很多中方法,
    可以用recieve,recievefrom,或者响应Onrecieve函数利用串行化读数据
      

  5.   

    因为某种原因吧,也想学习一下,就是说不用wsock里面的函数可不可以取到socket传过来的数据,还有请问:Caps77(二两指针) 你说提到的那三个函数是在那个库里面的?好像在msdn里面找不到
      

  6.   

    select 只能标志那个socket可以读或写,但是真正的判断那个具体的socket还要自己写代来实现,如果socket比较多的时候,遍历这些socket也是相当耗时的工作.
      

  7.   

    打错了一个字,应该是标记那个socket可写或可读,第四个参数是异常socket,目前一般只用来处理 out of bound data 另外还有一种并不常见,在winsock 中,由于对socket的标记方法不一样,这个要注意。
      

  8.   

    MSDN上这个讲的挺清楚的
    给你个具体的调用:
    struct   timeval stime;
    struct   fd_set  sdfds;
    stime.tv_sec=1000;
    stime.tv_usec=0;l_iFlag=select(sendSocket,(fd_set *)NULL,&sdfds,(fd_set *)NULL,(struct timeval *) &stime);不过这之前你要调用诸如bind、listen、accept之类的函数
      

  9.   

    recieve,recievefrom,Onrecieve这些函数是windows里面的那个动态库的函数?比如recv是wsock32.dll里面的函数