Exemplo n.º 1
0
        private void FindWritePacketOrCreate(PacketMap pm, WriteDataServiceRequest request)
        {
            //The data is already broken up into appropriately sized chunks, we just have
            //to find a place to put it...

            int rSize = request.Size;

            for (int i = 0; i < _writeMsrPackets.Count; i++)
            {
                if (_writeMsrPackets[i].Size + rSize < MAX_MSR_SIZE)
                {
                    //This one will fit the packet
                    int svc = _writeMsrPackets[i].AddService(request.Pack());
                    pm.PacketIndex.Add(i);
                    pm.ServiceIndex.Add(i);
                    return;
                }
            }

            //If we got here, we have to create a new one...
            MultiServiceRequest msr = new MultiServiceRequest();

            pm.PacketIndex.Add(_writeMsrPackets.Count);
            _writeMsrPackets.Add(msr);
            pm.ServiceIndex.Add(msr.AddService(request.Pack()));
        }
Exemplo n.º 2
0
        private int[] FindPacketOrCreate(byte[] request, ushort replySize)
        {
            //We'll go through all the packets and find one that can fit both the
            //request size and the reply size...
            int[] retVal = new int[2];      //Packet Number, Service Number

            for (int i = 0; i < _msrPackets.Count; i++)
            {
                if (_msrPackets[i].ReplySize + replySize <= MAX_MSR_SIZE)
                {
                    //Possible candidate, let's see if we can put the request in it...
                    if (_msrPackets[i].Size + request.Length <= MAX_MSR_SIZE)
                    {
                        //Got one!
                        retVal[0] = i;
                        retVal[1] = _msrPackets[i].AddService(request);
                        _msrPackets[i].ReplySize += replySize;
                        return(retVal);
                    }
                }
            }

            //If we got here, we need to create one...
            MultiServiceRequest newPacket = new MultiServiceRequest();

            retVal[0] = _msrPackets.Count;
            _msrPackets.Add(newPacket);
            retVal[1] = _msrPackets[retVal[0]].AddService(request);
            _msrPackets[retVal[0]].ReplySize += replySize;

            return(retVal);
        }