Ejemplo n.º 1
0
/*****************************************************************************
  Function:
	void TCPClose(SOCKET *  pSocket, IPSTATUS * pStatus)

  Description:
        This politely closes a socket, making sure no data is lost

  Parameters:
	pSocket:        The socket to close, it is always safe to close, closed sockets.
        pStatus:        A pointer to a status variable to recieve the state of the socket as a status

  Returns:
        None

  ***************************************************************************/
void TCPClose(HSOCKET hSocket, IPSTATUS * pStatus)
{
    TCPSOCKET * pSocket = (TCPSOCKET *) hSocket;

    if(pSocket == NULL)
    {
        AssignStatusSafely(pStatus, ipsSocketNULL);
        return;
    }

    switch(TCPState(pSocket))
    {
        case  tcpListen:
            // closes, releases the socket so it can be used again
            pSocket->tcpState = tcpClosed;
            break;

        case  tcpSynSent:
            // we do not update sndEND when we send a sndNXT, but we do update the sndNXT
            // this is because a syn is a phantom byte and we don't want to point beyond zero
            // in our output buffers and attempt to send a garbabe byte.
            // but in order to terminate properly we need sndNXT == sndEND or we will loop
            // attempting to send bytes from out buffer that we don't have to send
            pSocket->sndNXT = pSocket->sndEND;  // we may have sent a syn and sndNXT > sndEND
            pSocket->tcpState = tcpWaitUserClose;
            break;

        case  tcpSynReceived:
        case  tcpSynReceivedWhileListening:
            pSocket->sndNXT = pSocket->sndEND;  // we may have sent a syn and sndNXT > sndEND
            // fall thru

        case  tcpEstablished:
            pSocket->tcpState = tcpFinWait1;
            break;

        case  tcpFinWait1:
        case  tcpFinWait2:
        case  tcpCloseWait:
        case  tcpClosing:
        case  tcpLastAck:
        case  tcpInvalid:
        case  tcpUnassigned:
        case  tcpAllocated:
        case  tcpClosed:
        case  tcpWaitUserClose:
        default:
            break;
    }
    pSocket->fSocketOpen = false;

    // get the status
    AssignStatusSafely(pStatus, IPStatusFromTCPState(pSocket->tcpState));
}
Ejemplo n.º 2
0
/*****************************************************************************
  Function:
	uint32_t TCPAvailable(SOCKET *  pSocket, IPSTATUS * pStatus)

  Description:
            Returns the number of unread bytes in the socket receive buffer

  Parameters:
	pSocket:        The socket to get the number of unread bytes
        pStatus:        A pointer to a status variable to recieve the state of the socket as a status

  Returns:
        Number of unread bytes in the socket, or zero

  ***************************************************************************/
uint32_t TCPAvailable(HSOCKET hSocket, IPSTATUS * pStatus)
{
    TCPSOCKET * pSocket = (TCPSOCKET *) hSocket;
    uint32_t    rcvNXT  = 0;

    if(pSocket == NULL)
    {
        AssignStatusSafely(pStatus, ipsSocketNULL);
        return(0);
    }

    AssignStatusSafely(pStatus, IPStatusFromTCPState(pSocket->tcpState));

    switch(TCPState(pSocket))
    {
        // get rid of the FIN that is in the count
        case  tcpEstablished:
        case  tcpSynReceived:
        case  tcpSynReceivedWhileListening:
        case  tcpCloseWait:
        case  tcpLastAck:
        case  tcpWaitUserClose:
        case  tcpFinWait1:
        case  tcpFinWait2:
        case  tcpClosing:
            rcvNXT = pSocket->rcvNXT;
            if(pSocket->fGotFin)
            {
                rcvNXT--;
            }
            break;

        case  tcpListen:
        case  tcpSynSent:
        case  tcpInvalid:
        case  tcpUnassigned:
        case  tcpAllocated:
        case  tcpClosed:
        default:
            return(0);
            break;
    }

    // how much can we read
    return(rcvNXT);
}
Ejemplo n.º 3
0
int Workwidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: SwitchToCompleteWorkSignal(); break;
        case 1: SwitchToChooseCraftSignal(); break;
        case 2: SwitchToTimeSecretSignal(); break;
        case 3: SwitchToSensorSecretSignal(); break;
        case 4: SwitchToParaSecretSignal(); break;
        case 5: SwitchToSysEleSecretSignal(); break;
        case 6: ShutDownSignal(); break;
        case 7: SwitchToGThSignal(); break;
        case 8: UpdateShowSig(); break;
        case 9: UpdateNetWorkInfoSig(); break;
        case 10: ShowRecordStateSig(); break;
        case 11: SwitchToCompleteWorkSlot(); break;
        case 12: SwitchToChooseCraftSlot(); break;
        case 13: SwitchToTimeSecretSlot(); break;
        case 14: SwitchToSensorSecretSlot(); break;
        case 15: SwitchToParaSecretSlot(); break;
        case 16: SwitchToSysEleSecretSlot(); break;
        case 17: ShutDown(); break;
        case 18: SwitchToGThSecretSlot(); break;
        case 19: updatetime(); break;
        case 20: showMenu(); break;
        case 21: UpdateShowSlot(); break;
        case 22: TCPState((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 23: WorkFinished(); break;
        case 24: ToWorkWidget(); break;
        case 25: UpdateNetWorkInfoSlot(); break;
        case 26: ComIndexChange((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 27: ShowRecordState(); break;
        case 28: on_StartWorkBtn_clicked(); break;
        case 29: on_ManInputBtn_clicked(); break;
        case 30: on_QuPi_clicked(); break;
        default: ;
        }
        _id -= 31;
    }
    return _id;
}
Ejemplo n.º 4
0
int TGNetwork::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: sevIPPort((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< uint(*)>(_a[2]))); break;
        case 1: TestDataSignal((*reinterpret_cast< char*(*)>(_a[1]))); break;
        case 2: SwitchToWork(); break;
        case 3: on_NetBtn_clicked(); break;
        case 4: on_SendTestDataBtn_clicked(); break;
        case 5: on_NetBtn_2_clicked(); break;
        case 6: TCPState((*reinterpret_cast< bool(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 7;
    }
    return _id;
}