Exemple #1
0
void UDPClose(HSOCKET hSocket)
{
    UDPSOCKET *     pSocket     = (UDPSOCKET *) hSocket;
    UDPSOCKET *     pSocketCur  = NULL;

    // loop thru all listening sockets looking for this one
    while((pSocketCur = FFNext(&g_ffptListeningUDPSockets, pSocketCur)) != NULL)
    {
        // see if we found it
        if(pSocket == pSocketCur)
        {
            SMGR *      pSMGR = alloca(pSocket->cbRxSMGR);

            // remove it from the listening list
            FFRemove(&g_ffptListeningUDPSockets, pSocket);

            if(pSMGR != NULL && (SMGRRead((HSMGR) &pSocket->smgrRxBuff, 0, pSMGR, pSocket->cbRxSMGR) == pSocket->cbRxSMGR))
            {
                // free the datastream
                SMGRFree((HSMGR) pSMGR);
                // don't need to write back because these pages are all getting freed as well
            }

            // free what is in the socket as well
            // this is why we don't have to write back
            SMGRFree((HSMGR) &pSocket->smgrRxBuff);

            // clear the socket
            IPSReleaseSocket((TCPSOCKET *) pSocket);
            return;
        }
    }

    return;
}
/***	void TCPServer::close(void)
**
**	Synopsis:   
**      Stops Listening and closes all unaccepted sockets/connections
**      and clears everything back to it's originally constructed state.
**
**	Parameters:
**      None
**
**	Return Values:
**      None
**
**	Errors:
**      None
**
**  Notes:
**
**      Returns the TCPServer instance to
**      a state just as if the instance had just been
**      constructed. It also, Close all connections
**      and releases all resources (sockets).
**
*/
void TCPServer::close(void)
{
    FFLL * pffll = NULL;

    // pull this off the listening list
    FFRemove(&_ffptPeriodTask, &_ffptInfo);

    // close and sockets added to the server
    while((pffll = (FFLL *) FFOutPacket(&_ffptSockets)) != NULL)
    {
        ((TCPSocket *) (pffll->_this))->close();
    }
    
    clear();
}
// We can get errors, you passed me a NULL, or an opened TCPSocket, or index out of range.
TCPSocket *  TCPServer::acceptClient(int index)
{
    FFLL *      pffllSocket = NULL;
    int         c = 0;

    while((pffllSocket = (FFLL *) FFNext(&_ffptSockets, pffllSocket)) != NULL)
    {
        TCPSocket& tcpSocket = *((TCPSocket *) (pffllSocket->_this));   // for syntax sake

        if(TCPIsEstablished(&tcpSocket._socket, NULL) && c == index)
        {
            FFRemove(&_ffptSockets, pffllSocket);
            tcpSocket._classState = ipsInUseW;
            return(&tcpSocket);
        }
    }

    return(NULL);
}
Exemple #4
0
void TCPResetSocket(TCPSOCKET *  pSocket)
{
    if(pSocket == NULL || pSocket->smgrRxTxBuff.pPMGR == NULL)
    {
        return;
    }

    // fixup the seq nbr generator to make sure we don't reissue seqnbr less than before in time
    TCPFixupSeqNumber(pSocket->s.pLLAdp, pSocket->sndISS + pSocket->sndNXT);

    // clean up the socket if we were not listening
    if(pSocket->tcpState != tcpSynReceivedWhileListening)
    {
        uint16_t    cb      = pSocket->cbRxSMGR + pSocket->cbTxSMGR;
        SMGR *      pSMGR   = (SMGR*)alloca(cb);

        // remove it from the listening list
        FFRemove(&g_ffptActiveTCPSockets, pSocket);

        // this works
//        pSocket->sndISS = 0;
//          pSocket->tcpState = tcpUnassigned;
//        pSocket->fSocketOpen = false;
        
        // if this does not pass, we will have a memory leak
        // the alloca should always work.
        // this frees the Rx and Tx socket buffers
        if(SMGRRead((HSMGR) &pSocket->smgrRxTxBuff, 0, pSMGR, cb) == cb)
        {
            SMGRFree((HSMGR) pSMGR);
            SMGRFree((HSMGR) (((uint8_t *) pSMGR) + pSocket->cbRxSMGR));
        }

        // free the pointer to the RxTx streams.
        SMGRFree((HSMGR) &pSocket->smgrRxTxBuff);

        // release it back to the global pool if we got it from there
        IPSReleaseSocket(pSocket);

        // clean the socket
        // I am assuming this will not break us anywhere.
        memset(pSocket, 0, sizeof(TCPSOCKET));

        return;
    }

    // if we were listening, go back to listening
    // restore the socket to the listening state
    pSocket->s.portRemote = portListen;
    memset(&pSocket->s.ipRemote, 0, sizeof(IPv4or6));
    memset(&pSocket->s.macRemote, 0, sizeof(MACADDR));
    pSocket->tcpState   = tcpListen;
    pSocket->sndISS     = 0;

    // initalize the socket info
    pSocket->sndISS         = TCPGetSeqNumber(pSocket->s.pLLAdp);
    pSocket->sndNXT         = 0;
    pSocket->sndUNA         = 0;
    pSocket->sndEND         = 0;
    pSocket->sndWND         = 0;
    pSocket->sndPSH         = 0;
//    pSocket->sndWL2     = 0;
    pSocket->sndUP          = 0;
    pSocket->sndRTTComplete = 0;
    
    pSocket->rcvIRS         = 0;
    // pSocket->rcvUNR     = 0;
    pSocket->rcvNXT         = 0;
    pSocket->rcvUP          = 0;
//    pSocket->rcvSeqAhead = 0;

    pSocket->fGotFin        = false;
    pSocket->fSocketOpen    = false;

    // Jacobson rule
    pSocket->RTTsa      = RTTsaINIT;
    pSocket->RTTsv      = RTTsvINIT;
    pSocket->tRTO_SET   = RTO(pSocket);
    pSocket->tRTOCur    = pSocket->tRTO_SET;

}