コード例 #1
0
        public override void add(IMarshal marshal, ushort opcode, IData data, Action callback)
        {
            Packet packet = Packet.make(opcode, callback);

            data.pack(marshal, packet);
            add(packet);
        }
コード例 #2
0
        private static void EnsureHasMarshalProxy()
        {
            if (t_winRtMarshalProxy != null)
            {
                return;
            }

            try
            {
                IMarshal proxy;
                Int32    hr = Interop.mincore.RoGetBufferMarshaler(out proxy);
                t_winRtMarshalProxy = proxy;

                if (hr != __HResults.S_OK)
                {
                    Exception ex = new Exception(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
                    ex.SetErrorCode(hr);
                    throw ex;
                }

                if (proxy == null)
                {
                    throw new NullReferenceException(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
                }
            }
            catch (DllNotFoundException ex)
            {
                throw new NotImplementedException(SR.Format(SR.NotImplemented_NativeRoutineNotFound,
                                                            String.Format("{0}!RoGetBufferMarshaler", WinTypesDLL)),
                                                  ex);
            }
        }
コード例 #3
0
        public void Execute(string query)
        {
            if (pendingFuture != null)
            {
                throw new InvalidOperationException("The command is already active.");
            }

            IMarshal marshaledQuery = ExplicitString.CreateExecString(connection, query);

            queryType    = QueryType.QT_UNKNOWN;
            affectedRows = prefetchedRows = 0;
            isLastResult = isLastRow = isLastInBatch = false;
            prefetchRow  = currentRow = null;

            object[] parameterRows = new object[1];
            parameterRows[0] = parameterValues;
            Future future = new Future(Service.Execute, GetId(), marshaledQuery, GetId(), parameterRows, null, GetOptions());

            SendRequest(future);
            CLI.ReturnCode rc = ProcessResult(true);

            if (rc != CLI.ReturnCode.SQL_SUCCESS && rc != CLI.ReturnCode.SQL_NO_DATA)
            {
                if (rc != CLI.ReturnCode.SQL_SUCCESS_WITH_INFO)
                {
                    pendingFuture = null;
                    connection.futures.Remove(future);
                }
                Diagnostics.HandleResult(rc, this, connection.OuterConnection);
            }
        }
コード例 #4
0
        private static void EnsureHasMarshalProxy()
        {
            if (t_winRtMarshalProxy != null)
            {
                return;
            }

            try
            {
                int      hr    = RoGetBufferMarshaler(out IntPtr proxyPtr);
                IMarshal proxy = new ABI.Com.IMarshal(ObjectReference <ABI.Com.IMarshal.Vftbl> .Attach(ref proxyPtr));
                t_winRtMarshalProxy = proxy;

                if (hr != 0)
                {
                    Exception ex = new Exception(string.Format("{0} ({1}!RoGetBufferMarshaler)", global::Windows.Storage.Streams.SR.WinRtCOM_Error, WinTypesDLL));
                    ex.SetHResult(hr);
                    throw ex;
                }

                if (proxy == null)
                {
                    throw new NullReferenceException(string.Format("{0} ({1}!RoGetBufferMarshaler)", global::Windows.Storage.Streams.SR.WinRtCOM_Error, WinTypesDLL));
                }
            }
            catch (DllNotFoundException ex)
            {
                throw new NotImplementedException(string.Format(global::Windows.Storage.Streams.SR.NotImplemented_NativeRoutineNotFound,
                                                                string.Format("{0}!RoGetBufferMarshaler", WinTypesDLL)),
                                                  ex);
            }
        }
コード例 #5
0
        private void read_impl(IBaseClient client, SuperPacket <PQ> superpacket, IMarshal marshal)
        {
            SuperPacketReader reader = client.popPendingSuperPacket();

            // Handshake process skips all procedures, including order
            if (reader.HasFlag(SuperPacketFlags.Handshake))
            {
                // Nothing to do here, it's a handshake packet
                // TODO(gpascualg): We don't need to add them at all
                LastTickIdRead = reader.tickId();
                return;
            }

            Debug.Assert(!IsOutOfOrder(reader.tickId()), "Should never have out of order packets");

            if (Overflow.sub(ExpectedTickId, reader.tickId()) > Constants.MaximumBlocksUntilResync)
            {
                superpacket.SetFlag(SuperPacketFlags.Handshake);
            }

            if (LastTickIdRead > reader.tickId())
            {
                loopCounter = (byte)(loopCounter + 1);
            }

            LastTickIdRead = reader.tickId();
            reader.handlePackets <PQ, IBaseClient>(this, marshal, client);
        }
コード例 #6
0
        public void handlePackets <PQ, T>(Protocol <PQ> protocol, IMarshal marshal, T client) where PQ : IProtocolQueues where T : IBaseClient
        {
            int offset    = sizeof(ushort) * 2 + sizeof(byte) + sizeof(ushort) + sizeof(uint);
            int numBlocks = (int)_buffer.readByte((int)offset);
            int blockPos  = (int)offset + sizeof(byte);

            int remaining = 500 - blockPos;

            for (int i = 0; i < numBlocks; ++i)
            {
                ushort blockId    = _buffer.readUshort(blockPos);
                int    numPackets = (int)_buffer.readByte(blockPos + sizeof(ushort));
                if (numPackets == 0)
                {
                    return;
                }

                ulong blockTimestamp = protocol.blockTimestamp(blockId);
                blockPos  += sizeof(ushort) + sizeof(byte);
                remaining -= sizeof(ushort) + sizeof(byte);

                for (int j = 0; j < numPackets && remaining > 0; ++j)
                {
                    PacketReader packet = new PacketReader(new Buffer(_buffer, blockPos, Packet.DataStart), blockTimestamp);
                    if (protocol.resolve(packet, blockId))
                    {
                        switch (marshal.handlePacket(packet, client, blockId))
                        {
                        case MarshalParseState.ParsingFailed:
                            client.handlingError();
                            return;

                        case MarshalParseState.ParsingDone:
                            blockPos  += packet.bytesRead();
                            remaining -= packet.bytesRead();
                            break;

                        case MarshalParseState.ParsingSkipped:
                            var size = Packet.DataStart + marshal.PacketSize(packet);
                            blockPos  += size;
                            remaining -= size;
                            break;
                        }
                    }
                    else
                    {
                        var size = Packet.DataStart + marshal.PacketSize(packet);
                        blockPos  += size;
                        remaining -= size;
                    }
                }
            }
        }
コード例 #7
0
        public override void process(IMarshal marshal, ushort tickId, ushort blockId, ref ushort remaining, ref bool unfittingData, SortedDictionary <uint, List <Packet> > byBlock)
        {
            if (pending.Count == 0)
            {
                return;
            }

            G global = new G();

            global.initialize();
            ushort size = (ushort)(6 + 2 + newTickBlockCost(tickId, byBlock));

            foreach (PendingData <D> pnd in pending)
            {
                if (isPending(pnd.InternalTickList, tickId, false))
                {
                    break;
                }

                ushort nextSize = (ushort)(size + pnd.data.size(marshal));
                if (nextSize > remaining)
                {
                    unfittingData = true;
                    break;
                }

                size = nextSize;
                global.getData().Add(pnd.data);
                pnd.InternalTickList.Add(tickId);
                pnd.ClientAckIds.Add(blockId);
            }

            if (global.getData().Count == 0)
            {
                return;
            }

            Packet packet = Packet.make(_opcode);

            global.pack(marshal, packet);
            remaining = (ushort)(remaining - size);

            if (byBlock.ContainsKey(tickId))
            {
                byBlock[tickId].Add(packet);
            }
            else
            {
                byBlock.Add(tickId, new List <Packet>());
                byBlock[tickId].Add(packet);
            }
        }
コード例 #8
0
        public void process(IMarshal marshal, ushort tickId, ushort blockId, ref ushort remaining, ref bool unfittingData, SortedDictionary <uint, List <Packet> > byBlock)
        {
            packer.process(marshal, tickId, blockId, ref remaining, ref unfittingData, byBlock);

            if (maxRetries == 0)
            {
                packer.clear();
            }
            else
            {
                packer.removeByCount(maxRetries);
            }
        }
コード例 #9
0
ファイル: Client.cs プロジェクト: AErbis/Kaminari-csharp
        public Client(IMarshal marshal, IProtocol <PQ> protocol, PQ queues)
        {
            // Drop simulation
            random = new Random();
            PctSimulatedRecvDrop = 0;
            PctSimulatedSendDrop = 0;

            // Other
            pendingPackets   = new ConcurrentList();
            this.marshal     = marshal;
            this.protocol    = protocol;
            this.superPacket = new SuperPacket <PQ>(queues);
        }
コード例 #10
0
        public override void process(IMarshal marshal, ushort tickId, ushort blockId, ref ushort remaining, ref bool unfittingData, SortedDictionary <uint, List <Packet> > byBlock)
        {
            if (!isPending(tickId))
            {
                return;
            }

            int numInserted = 0;

            foreach (PendingData <Packet> pnd in pending)
            {
                uint   actualBlock = getActualTickId(pnd.InternalTickList, tickId);
                ushort size        = pnd.data.getSize();

                if (byBlock.ContainsKey(actualBlock))
                {
                    if (size > remaining)
                    {
                        unfittingData = true;
                        break;
                    }

                    byBlock[actualBlock].Add(pnd.data);
                }
                else
                {
                    size = (ushort)(size + 4);
                    if (size > remaining)
                    {
                        unfittingData = true;
                        break;
                    }

                    byBlock.Add(actualBlock, new List <Packet>());
                    byBlock[actualBlock].Add(pnd.data);
                }

                pnd.InternalTickList.Add(tickId);
                pnd.ClientAckIds.Add(blockId);
                remaining = (ushort)(remaining - size);
                ++numInserted;
            }

            if (numInserted > 0)
            {
                hasNewPacket = false;
                lastBlock    = tickId;
            }
        }
コード例 #11
0
        public override void process(IMarshal marshal, ushort tickId, ushort blockId, ref ushort remaining, ref bool unfittingData, SortedDictionary <uint, List <Packet> > byBlock)
        {
            foreach (PendingData <PacketWithOpcode> pnd in pending)
            {
                if (!isPending(pnd.InternalTickList, tickId, false))
                {
                    continue;
                }

                uint   actualBlock = getActualTickId(pnd.InternalTickList, tickId);
                ushort size        = (ushort)pnd.data.packet.getSize();

                if (byBlock.ContainsKey(actualBlock))
                {
                    if (size > remaining)
                    {
                        unfittingData = true;
                        break;
                    }

                    byBlock[actualBlock].Add(pnd.data.packet);
                }
                else
                {
                    size = (ushort)(size + 4);
                    if (size > remaining)
                    {
                        unfittingData = true;
                        break;
                    }

                    byBlock.Add(actualBlock, new List <Packet>());
                    byBlock[actualBlock].Add(pnd.data.packet);
                }

                pnd.InternalTickList.Add(tickId);
                pnd.ClientAckIds.Add(blockId);
                remaining = (ushort)(remaining - size);
            }
        }
コード例 #12
0
        public void Prepare(string query)
        {
            if (pendingFuture != null)
            {
                throw new InvalidOperationException("The command is already active.");
            }

            IMarshal marshaledQuery = ExplicitString.CreateExecString(connection, query);

            Future future = new Future(Service.Prepare, GetId(), marshaledQuery, 0, GetOptions());

            SendRequest(future);
            CLI.ReturnCode rc = ProcessResult(false);
            if (rc != CLI.ReturnCode.SQL_SUCCESS && rc != CLI.ReturnCode.SQL_NO_DATA)
            {
                if (rc != CLI.ReturnCode.SQL_SUCCESS_WITH_INFO)
                {
                    pendingFuture = null;
                    connection.futures.Remove(future);
                }
                Diagnostics.HandleResult(rc, this, connection.OuterConnection);
            }
        }
コード例 #13
0
        public bool read(IBaseClient client, SuperPacket <PQ> superpacket, IMarshal marshal)
        {
            timestampBlockId = ExpectedTickId;
            timestamp        = DateTimeExtensions.now();

            if (!client.hasPendingSuperPackets())
            {
                if (++sinceLastRecv >= Constants.MaxBlocksUntilDisconnection)
                {
                    client.disconnect();
                    return(false);
                }

                marshal.Update(client, ExpectedTickId);
                ExpectedTickId = Overflow.inc(ExpectedTickId);
                return(false);
            }

            sinceLastRecv = 0;
            ushort expectedId = ExpectedTickId;

            if (!Constants.UseKumoQueues)
            {
                ExpectedTickId = Overflow.sub(ExpectedTickId, bufferSize);
            }

            while (client.hasPendingSuperPackets() &&
                   !Overflow.ge(client.firstSuperPacketTickId(), expectedId))
            {
                read_impl(client, superpacket, marshal);
            }

            marshal.Update(client, ExpectedTickId);
            ExpectedTickId = Overflow.inc(ExpectedTickId);
            return(true);
        }
コード例 #14
0
        public void HandleAcks(ushort tickId, SuperPacketReader reader, SuperPacket <PQ> superpacket, IMarshal marshal)
        {
            // Ack packets
            foreach (ushort ack in reader.getAcks())
            {
                // Check if this ack > lastAck
                if (Kaminari.Overflow.ge(ack, processedAckBase))
                {
                    int displace = Kaminari.Overflow.sub(ack, processedAckBase);
                    processedAcks    = processedAcks << displace;
                    processedAckBase = ack;
                }

                // Now, check if the ack has already been processed
                int ackPosition = Overflow.sub(processedAckBase, ack);
                if (ackPosition >= 64)
                {
                    ackPosition      = 0;
                    processedAcks    = 0;
                    processedAckBase = ack;
                }

                // If it is already masked, it means it has already been processed
                ulong ackMask = (ulong)1 << ackPosition;
                if ((processedAcks & ackMask) > 0)
                {
                    continue;
                }
                processedAcks = processedAcks | ackMask;

                // Otherwise, let superpacker handle the ack
                superpacket.Ack(ack);

                // Update lag estimation
                if (Overflow.geq(lastConfirmedTimestampId, ack) && Overflow.sub(timestampsHeadId, lastConfirmedTimestampId) < 100)
                {
                    // TODO(gpascualg): This can be used as a connection quality estimate
                    continue;
                }

                lastConfirmedTimestampId = ack;
                ushort position = Overflow.mod(Overflow.sub(timestampsHeadPosition, Overflow.sub(timestampsHeadId, ack)), ResolutionTableSize);
                ulong  diff     = reader.Timestamp - timestamps[position];
                UnityEngine.Debug.Log($"> ACK {ack} AT {position} +{diff}");
                const float w = 0.99f;
                estimatedRTT = estimatedRTT * w + diff * (1.0f - w);
            }

            // Schedule ack if necessary
            bool is_handshake = reader.HasFlag(SuperPacketFlags.Handshake);

            if (is_handshake || reader.hasData() || reader.isPingPacket())
            {
                superpacket.scheduleAck(reader.id());
            }

            // Handle flags already
            if (is_handshake)
            {
                // Check if there was too much of a difference, in which case, flag handshake again
                // TODO(gpascualg): Remove re-handshake max diff magic number
                if (Overflow.abs_diff(reader.tickId(), tickId) > 10)
                {
                    superpacket.SetFlag(SuperPacketFlags.Handshake);
                }

                // During handshake, we update our tick to match the other side
                ExpectedTickId = reader.tickId();
                LastServerId   = reader.tickId();

                // Reset all variables related to packet parsing
                timestampBlockId = ExpectedTickId;
                timestamp        = DateTimeExtensions.now();
                loopCounter      = 0;

                // Reset marshal
                ResetResolutionTable(reader.tickId());
                marshal.Reset();

                if (!reader.HasFlag(SuperPacketFlags.Ack))
                {
                    superpacket.SetFlag(SuperPacketFlags.Ack);
                    superpacket.SetFlag(SuperPacketFlags.Handshake);
                }
            }
        }
コード例 #15
0
 public abstract void add(IMarshal marshal, ushort opcode, D data, Action callback);
コード例 #16
0
 public Reader(IMarshal marshal, INativeMethods nativeMethods, IEdidFactory edidFactory)
 {
     _marshal       = marshal ?? throw new ArgumentNullException(nameof(marshal));
     _nativeMethods = nativeMethods ?? throw new ArgumentNullException(nameof(nativeMethods));
     _edidFactory   = edidFactory ?? throw new ArgumentNullException(nameof(edidFactory));
 }
コード例 #17
0
 public abstract void process(IMarshal marshal, ushort tickId, ushort blockId, ref ushort remaining, ref bool unfittingData, SortedDictionary <uint, List <Packet> > byBlock);
コード例 #18
0
 public override void add(IMarshal marshal, ushort opcode, IHasId data, Action callback)
 {
     Debug.Assert(false, "Unsupported operation");
 }
コード例 #19
0
 public void process(IMarshal marshal, ushort tickId, ushort blockId, ref ushort remaining, ref bool unfittingData, SortedDictionary <uint, List <Packet> > byBlock)
 {
     packer.process(marshal, tickId, blockId, ref remaining, ref unfittingData, byBlock);
 }
コード例 #20
0
 public void add(IMarshal marshal, ushort opcode, D data, Action callback)
 {
     packer.add(marshal, opcode, data, callback);
 }
コード例 #21
0
ファイル: FakeObject.cs プロジェクト: sasqwatch/LethalHTA
 public FakeObject(IMoniker moniker)
 {
     this._marshal = (IMarshal)moniker;
 }
コード例 #22
0
 public override void add(IMarshal marshal, ushort _opcode, D data, Action callback)
 {
     pending.Add(new PendingData <D>(data));
 }
コード例 #23
0
 internal static extern Int32 RoGetBufferMarshaler(out IMarshal bufferMarshalerPtr);
コード例 #24
0
ファイル: WindowsRuntimeBuffer.cs プロジェクト: SGuyGe/corefx
        private static void EnsureHasMarshalProxy()
        {
            if (s_winRtMarshalProxy != null)
                return;

            try
            {
                IMarshal proxy;
                Int32 hr = Interop.mincore.RoGetBufferMarshaler(out proxy);
                s_winRtMarshalProxy = proxy;

                if (hr != HResults.S_OK)
                {
                    Exception ex = new Exception(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
                    ex.SetErrorCode(hr);
                    throw ex;
                }

                if (proxy == null)
                    throw new NullReferenceException(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
            }
            catch (DllNotFoundException ex)
            {
                throw new NotImplementedException(SR.Format(SR.NotImplemented_NativeRoutineNotFound,
                                                               String.Format("{0}!RoGetBufferMarshaler", WinTypesDLL)),
                                                  ex);
            }
        }
コード例 #25
0
 public OctetsStream Unmarshal(IMarshal m)
 {
     return(m.Unmarshal(this));
 }