目标:
实现文件传输代码:  do
    {
        memset(m_chTranBuffer,0,sizeof(m_chTranBuffer));
        l_iReadLeng = fread(m_chTranBuffer,1,4096,m_pSourFile);
        l_iSendLeng = send(m_soClient,m_chTranBuffer,l_iReadLeng,0);        if(l_iSendLeng != 4096)
        {
            TRACE("Read:%d  Send:%d\n\n",l_iReadLeng,l_iSendLeng);
            TRACE("Error:%d\n",WSAGetLastError());
        }
        l_iSendTotal += l_iSendLeng;
    }while(l_iReadLeng == 4096);WSAGetLastError的返回值为10035.该怎么办??

解决方案 »

  1.   

    最好的帮助MSDN上的解释ioctlsocket
    The ioctlsocket function controls the I/O mode of a socket.int ioctlsocket(
      SOCKET s,
      long cmd,
      u_long* argp
    );Parameters

    [in] Descriptor identifying a socket. 
    cmd 
    [in] Command to perform on the socket s. 
    argp 
    [in, out] Pointer to a parameter for cmd. Res
    The ioctlsocket function can be used on any socket in any state. It is used to set or retrieve operating parameters associated with the socket, independent of the protocol and communications subsystem. Here are the supported commands to use in the cmd parameter and their semantics:FIONBIO 
    The argp parameter is a pointer to an unsigned long value. Set argp to a nonzero value if the nonblocking mode should be enabled, or zero if the nonblocking mode should be disabled. When a socket is created, it operates in blocking mode by default (nonblocking mode is disabled). This is consistent with BSD sockets. argp value Nonblocking mode 
    0 Disabled 
    nonzero Enabled The WSAAsyncSelect and WSAEventSelect functions automatically set a socket to nonblocking mode. If WSAAsyncSelect or WSAEventSelect has been issued on a socket, then any attempt to use ioctlsocket to set the socket back to blocking mode will fail with WSAEINVAL.To set the socket back to blocking mode, an application must first disable WSAAsyncSelect by calling WSAAsyncSelect with the lEvent parameter equal to zero, or disable WSAEventSelect by calling WSAEventSelect with the lNetworkEvents parameter equal to zero.FIONREAD 
    Use to determine the amount of data pending in the network's input buffer that can be read from socket s. The argp parameter points to an unsigned long value in which ioctlsocket stores the result. FIONREAD returns the amount of data that can be read in a single call to the recv function, which may not be the same as the total amount of data queued on the socket. If s is message oriented (for example, type SOCK_DGRAM), FIONREAD still returns the amount of pending data in the network buffer, however, the amount that can actually be read in a single call to the recv function is limited to the data size written in the send or sendto function call. 
    SIOCATMARK 
    Use to determine if all out of band (OOB) data has been read. (See Windows Sockets 1.1 Blocking Routines and EINPROGRESS for a discussion on OOB data.) This applies only to a stream oriented socket (for example, type SOCK_STREAM) that has been configured for in-line reception of any OOB data (SO_OOBINLINE). On sockets with the SO_OOBINLINE socket option set, SIOCATMARK always returns TRUE and the OOB data is returned to the user as normal data.
      

  2.   

    其实这个函数也可以,不过是高级版本了,好像是2.0版本以上的 WinSock才可以用吧。也复杂了许多。再看看MSDN的说明:WSAIoctl
    The WSAIoctl function controls the mode of a socket.int WSAIoctl(
      SOCKET s,
      DWORD dwIoControlCode,
      LPVOID lpvInBuffer,
      DWORD cbInBuffer,
      LPVOID lpvOutBuffer,
      DWORD cbOutBuffer,
      LPDWORD lpcbBytesReturned,
      LPWSAOVERLAPPED lpOverlapped,
      LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
    );Parameters

    [in] Descriptor identifying a socket. 
    dwIoControlCode 
    [in] Control code of operation to perform. 
    lpvInBuffer 
    [in] Pointer to the input buffer. 
    cbInBuffer 
    [in] Size of the input buffer, in bytes. 
    lpvOutBuffer 
    [out] Pointer to the output buffer. 
    cbOutBuffer 
    [in] Size of the output buffer, in bytes. 
    lpcbBytesReturned 
    [out] Pointer to actual number of bytes of output. 
    lpOverlapped 
    [in] Pointer to a WSAOVERLAPPED structure (ignored for nonoverlapped sockets). 
    lpCompletionRoutine 
    [in] Pointer to the completion routine called when the operation has been completed (ignored for nonoverlapped sockets). 
    Return Values
    Upon successful completion, the WSAIoctl returns zero. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.Error code Meaning 
    WSAENETDOWN The network subsystem has failed. 
    WSAEFAULT The lpvInBuffer, lpvOutBuffer, lpcbBytesReturned, lpOverlapped, or lpCompletionRoutine parameter is not totally contained in a valid part of the user address space, or the cbInBuffer or cbOutBuffer parameter is too small. 
    WSAEINVAL The dwIoControlCode oarameter is not a valid command, or a specified input parameter is not acceptable, or the command is not applicable to the type of socket specified. 
    WSAEINPROGRESS The function is invoked when a callback is in progress. 
    WSAENOTSOCK The descriptor s is not a socket. 
    WSAEOPNOTSUPP The specified ioctl command cannot be realized. (For example, the FLOWSPEC structures specified in SIO_SET_QOS or SIO_SET_GROUP_QOS cannot be satisfied.) 
    WSA_IO_PENDING An overlapped operation was successfully initiated and completion will be indicated at a later time. 
    WSAEWOULDBLOCK The socket is ed as nonblocking and the requested operation would block. 
    WSAENOPROTOOPT The socket option is not supported on the specified protocol. For example, an attempt to use the SIO_GET_BROADCAST_ADDRESS IOCTL was made on an IPv6 socket.
      

  3.   

    if(l_iSendLeng != 4096)   不对!
    应该是:
      if(l_iSendLeng != l_iReadLeng)!这样就不会出现上面的错误了!