예제 #1
0
    int Connection::send(const inp::INFPacket& data){
        //  prepare packet for sending
        PacketList packList;
        splitForSend(data, packList);
        // if there is nothing to send, leave.
        if( packList.empty() ){ return 1; }

        ScopedMutexLock(pimpl_->dataAccess);
        if( pimpl_->userSocket != NULL ){
            //  Send packets in list
            for(size_t i = 0; i < packList.size(); ++i ){
                if( !packList[i].empty() ){
                    //check if everything went through
                    if( SDLNet_TCP_Send( pimpl_->userSocket, &packList[i][0], packList[i].size() ) < packList[i].size() )
                    {
                        SDLNet_TCP_Close( pimpl_->userSocket );
                        pimpl_->userSocket = NULL;
                        pimpl_->peer = NULL;
                        pimpl_->active = false;
                        pimpl_->connectTime = 0;
                        pimpl_->lastSent.clear();
                        return -1;
                    }
                }
            }
            pimpl_->lastSent = packList;
        } else {
            pimpl_->connectTime = 0;
            return -1;
        }
        return 1;
    }