我有pascal的代码,但不知怎么翻译成c++的。

解决方案 »

  1.   

    这可是最经典的代码哟!:)
    SOCKET  s;
    fd_set  fdread;
    int     ret;// Create a socket, and accept a connection// Manage I/O on the socket
    while(TRUE)
    {
        // Always clear the read set before calling 
        // select()
        FD_ZERO(&fdread);    // Add socket s to the read set
        FD_SET(s, &fdread);    if ((ret = select(0, &fdread, NULL, NULL, NULL)) 
            == SOCKET_ERROR) 
        {
            // Error condition
        }    if (ret > 0)
        {
            // For this simple case, select() should return
            // the value 1. An application dealing with 
            // more than one socket could get a value 
            // greater than 1. At this point, your 
            // application should check to see whether the 
            // socket is part of a set.        if (FD_ISSET(s, &fdread))
            {
                // A read event has occurred on socket s
            }
        }
    }
      

  2.   

    fd_set fdRecv;
            FD_ZERO(&fdRecv);
            FD_SET(SocketConnect,&fdRecv);
            timeval tm;
            tm.tv_sec=30;
            tm.tv_usec=0;        int rc=select(0,&fdRecv,NULL, NULL,&tm);
            if(rc==0)
            {
               return;
            } rc=recv(SocketConnect,pBuf,nBytes,0);
      

  3.   

    那个 SocketConnect 是 一个 什么?  FD_SET 的第一个 参数 是一个 Socket , 我的是 CAsyncSocket ,怎么赋值??