Пример #1
0
/***	int TCPSocket::available(void)
**
**	Synopsis:   
**      Returns the number of bytes available for reading.
**
**	Parameters:
**      None
**
**	Return Values:
**      The actual number of bytes available in the socket ready for reading, 0 if none or the connection is lost.
**
**	Errors:
**      None
**
**  Notes:
**
**      This call is safe to make without checking the connection status.
**
*/
int TCPSocket::available(void)
{
    return(TCPAvailable(&_socket, NULL));
}
Пример #2
0
/*****************************************************************************
  Function:
	bool TCPIsConnected(SOCKET * pSocket, IPSTATUS * pStatus)

  Description:
        This is sort of like TCPIsEstablished except it is for any connected state. Think
        of being connected as being in the process of getting or closing a connection and being established.
        Established is a fully connected duplex condtion where both sides are ready to send and receive data.

  Parameters:
	pSocket:        The socket to see if it is in the established state
        pStatus:        A pointer to a status variable to recieve the status of the connection
                        This may be NULL if you don't care about the status

  Returns:
        true if the connection is in the process of connecting, half or full duplex
        connection, or in the process of closing but not yet closed.
        false if the conneciton is not in any kind of active condition.
  ***************************************************************************/
bool TCPIsConnected(HSOCKET hSocket, IPSTATUS * pStatus)
{
    TCPSOCKET * pSocket = (TCPSOCKET *) hSocket;
    IPSTATUS    status  = ipsUnknowTCPState;

    // check to see if we are even connected
    if(pSocket == NULL)
    {
        AssignStatusSafely(pStatus, ipsSocketNULL);
        return(false);
    }

    // Otherwise, what is our state?
    switch(pSocket->tcpState)
    {
        case tcpListen:
        case tcpSynSent:
        case tcpSynReceivedWhileListening:
        case tcpSynReceived:
        case tcpEstablished:
        case tcpFinWait1:
        case tcpFinWait2:
        case tcpCloseWait:
        case tcpClosing:
        case tcpLastAck:
            status = IPStatusFromTCPState(pSocket->tcpState);
            break;

        case tcpWaitUserClose:
            if(TCPAvailable(pSocket, NULL) > 0)
            {
                status = IPStatusFromTCPState(pSocket->tcpState);
            }
            else
            {
                status = IPErrorFromTCPState(pSocket->tcpState);
            }
            break;

        case tcpUnassigned:
        case tcpAllocated:
        case tcpInvalid:
        case tcpClosed:
            status = IPErrorFromTCPState(pSocket->tcpState);
            break;

        default:
            status = ipsUnknowTCPState;
            break;
    }

    AssignStatusSafely(pStatus, status);
    if(IsIPStatusAnError(status))
    {
        return(false);
    }
    else if(!ILIsIPNetworkReady(pSocket->s.pLLAdp, &status))
    {
        AssignStatusSafely(pStatus, status);
        return(false);
    }
    else if(pSocket->tcpState == tcpListen)
    {
        return(false);
    }

    return(true);
}