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;
    }
    void splitForSend(const INFPacket& src, PacketList& destList){
        //clear out queue
        destList.clear();

        //segments
        std::vector<Uint8> tmp;
        tmp.reserve(maxSendSize);

        size_t dataIndex = 0;
        Uint16 len = 0;
        Uint8 len_buff[2];
        unsigned int remaining = 0;
        while( dataIndex < src.data.size() ){
            //  Packet header
            if( dataIndex == 0 ){
                tmp.push_back(ControlByte::START.getVal() );
            } else {
                tmp.push_back(ControlByte::CONTINUE.getVal() );
            }

            //  data
            //minus 2 from maxSendSize for the START/END
            //minus 2 again, becuase 2 bytes are used to store the length
            //  of this segment

            //how much of the input data is left to be packed
            remaining = src.data.size() - dataIndex;
            //the length of the next segment
            if( remaining > (maxSendSize-4) ){
                len = (maxSendSize-4);
            } else {
                len = remaining;
            }
            //insert the length of this segment
            SDLNet_Write16(len, len_buff);
            tmp.push_back( len_buff[0] );
            tmp.push_back( len_buff[1] );

            //write the actual data
            for(int i = 0; i < len; ++i){
                tmp.push_back( src.data[dataIndex] );
                ++dataIndex;
            }

            //  Packet footer
            if( dataIndex == src.getLength() ){
                tmp.push_back(ControlByte::END.getVal() );
            } else {
                tmp.push_back(ControlByte::WAIT_MORE.getVal() );
            }

            //  Put the packet on the list
            destList.push_back(tmp);
            tmp.clear();
        }
    }
Example #3
0
void CutupProtocol::FreePackets( PacketList& packetList ) const
{
	PacketList::iterator iter = packetList.begin();
	for (; iter != packetList.end(); iter++)
	{
		FreePacket(*iter);
	}

	packetList.clear();
}
Example #4
0
File: Demux.cpp Project: artcom/y60
void Demux::clearPacketCache()
{
    map<int, PacketList>::iterator it;
    for (it=_myPacketLists.begin(); it != _myPacketLists.end(); ++it) {
        PacketList::iterator it2;
        PacketList* thePacketList = &(it->second);
        for (it2=thePacketList->begin(); it2 != thePacketList->end(); ++it2) {
            av_free_packet(*it2);
            delete *it2;
        }
        thePacketList->clear();
    }
}
Example #5
0
void FFMpegDemuxer::clearPacketCache()
{
    map<int, PacketList>::iterator it;
    for (it = m_PacketLists.begin(); it != m_PacketLists.end(); ++it) {
        PacketList::iterator it2;
        PacketList* pPacketList = &(it->second);
        for (it2 = pPacketList->begin(); it2 != pPacketList->end(); ++it2) {
            av_free_packet(*it2);
            delete *it2;
        }
        pPacketList->clear();
    }
}
Example #6
0
File: Demux.cpp Project: artcom/y60
void Demux::clearPacketCache(const int theStreamIndex)
{
    if (_myPacketLists.find(theStreamIndex) == _myPacketLists.end()) {
        AC_ERROR << "Demux::clearPacketCache called with nonexistent stream index "
            << theStreamIndex << ".";
    }
    PacketList * myCurPacketList = &(_myPacketLists.find(theStreamIndex)->second);
    PacketList::iterator it;
    for (it=myCurPacketList->begin(); it != myCurPacketList->end(); ++it) {
        av_free_packet(*it);
        delete *it;
    }
    myCurPacketList->clear();
}
Example #7
0
void Outbound::send_info(PacketList &complete_list,Net::PTP::ServerDevice *ptp,PtrLen<const uint8> server_info)
 {
  Packet<uint8,InfoExt> packet2=packet.popExt().pushExt<InfoExt>(ptp,idx,server_info);

  packet2.pushCompleteFunction(InfoExt::Complete);

  complete_list.put(packet2);
 }
Example #8
0
void Outbound::send_cancel(PacketList &complete_list,Net::PTP::ServerDevice *ptp)
 {
  Packet<uint8,CancelExt> packet2=packet.popExt().pushExt<CancelExt>(ptp,idx);

  packet2.pushCompleteFunction(CancelExt::Complete);

  complete_list.put(packet2);
 }
Example #9
0
void Bridge::complete(PacketList &list)
 {
  while( PacketHeader *packet_=list.get() )
    {
     Packet<uint8,XPoint> packet=packet_;

     packet.popExt().complete();
    }
 }
Example #10
0
void CutupProtocol::MergePackets( const PacketList& packetList, ByteBuffer& byteData ) const
{
	DWORD dwDataSize = 0;
	PacketList::const_iterator iter = packetList.begin();
	for (; iter != packetList.end(); iter++)
	{
		dwDataSize += (*iter)->header.size;
	}
	
	byteData.Alloc(dwDataSize);
	LPBYTE pData = byteData;

	iter = packetList.begin();
	for (; iter != packetList.end(); iter++)
	{
		if ((*iter)->header.size > 0)
		{
			memcpy(pData, (*iter)->data, (*iter)->header.size);
			pData += (*iter)->header.size;
		}
	}
}