Exemple #1
0
    public unsafe void SendPacket(ref SoakStatisticsPoint stats, ref SoakJobContext ctx)
    {
        var message = new SoakMessage
        {
            id   = ctx.FrameId,
            time = fixedTime,

            sequence = ctx.NextSequenceNumber++,
            length   = packetData.Length
        };

        streamWriter.Clear();

        streamWriter.WriteBytes(message.data, SoakMessage.HeaderLength);
        streamWriter.WriteBytes((byte *)packetData.GetUnsafeReadOnlyPtr(), packetData.Length);

        stats.SentBytes += connection[0].Send(driver, streamWriter);
        stats.SentPackets++;

        pendingSoaks[message.id % pendingSoaks.Length] = message;
    }
Exemple #2
0
    public unsafe void Execute()
    {
        if (serverEP.IsValid && !connection[0].IsCreated)
        {
            connection[0] = driver.Connect(serverEP);
        }
        else if (!serverEP.IsValid && connection[0].IsCreated)
        {
            connection[0].Disconnect(driver);
        }

        var ctx   = jobContext[0];
        var stats = jobStatistics[0];

        if (ctx.Done == 1 || !connection[0].IsCreated)
        {
            return;
        }

        DataStreamReader strm;

        NetworkEvent.Type cmd;

        SoakMessage inbound = default(SoakMessage);

        while ((cmd = connection[0].PopEvent(driver, out strm)) != NetworkEvent.Type.Empty)
        {
            if (cmd == NetworkEvent.Type.Connect)
            {
                if (ctx.StartedAt == default(float))
                {
                    ctx.StartedAt = fixedTime;
                    ctx.Connected = 1;
                }
            }
            else if (cmd == NetworkEvent.Type.Data)
            {
                /*var state =*/ connection[0].GetState(driver);

                if (!strm.IsCreated)
                {
                    Debug.Log("stream failed?");
                    return;
                }

                stats.ReceivedBytes += strm.Length;
                var readerCtx = default(DataStreamReader.Context);
                strm.ReadBytes(ref readerCtx, inbound.data, strm.Length);

                if (inbound.sequence > ctx.LatestReceivedSequenceNumber)
                {
                    ctx.LatestReceivedSequenceNumber = inbound.sequence;
                    stats.ReceivedPackets           += 1;
                }
                else
                {
                    stats.DroppedOrStalePackets += 1;
                }

                stats.PingTimeMean += (fixedTime - pendingSoaks[inbound.id % pendingSoaks.Length].time) * 1000;
                stats.PingTimeMeanCount++;
            }
            else if (cmd == NetworkEvent.Type.Disconnect)
            {
                connection[0] = default(NetworkConnection);
                break;
            }
        }

        if (fixedTime - ctx.StartedAt > ctx.Duration)
        {
            ctx.Done = 1;
            connection[0].Disconnect(driver);
        }

        ctx.Accumulator += deltaTime;

        while (ctx.Connected == 1 && ctx.Done == 0 && ctx.Accumulator >= ctx.SendInterval)
        {
            ctx.FrameId++;
            ctx.Accumulator -= ctx.SendInterval;
            SendPacket(ref stats, ref ctx);
        }

        jobContext[0]    = ctx;
        jobStatistics[0] = stats;
    }
    public unsafe void Execute()
    {
        var ctx       = jobContext[0];
        var stats     = jobStatistics[0];
        var lastStats = jobStatistics[1];

        if (ctx.Done == 1 || !connection[0].IsCreated)
        {
            return;
        }

        DataStreamReader strm;

        NetworkEvent.Type cmd;

        SoakMessage inbound = default(SoakMessage);

        while ((cmd = connection[0].PopEvent(driver, out strm)) != NetworkEvent.Type.Empty)
        {
            if (cmd == NetworkEvent.Type.Connect)
            {
                if (ctx.StartedAt == default(float))
                {
                    ctx.StartedAt = fixedTime;
                    ctx.Connected = 1;
                }
            }
            else if (cmd == NetworkEvent.Type.Data)
            {
                stats.ReceivedBytes += strm.Length;
                strm.ReadBytes(inbound.data, strm.Length);

                if (inbound.sequence > ctx.LatestReceivedSequenceNumber)
                {
                    ctx.LatestReceivedSequenceNumber = inbound.sequence;
                    stats.ReceivedPackets           += 1;
                }
                else
                {
                    stats.DroppedOrStalePackets += 1;
                }

                stats.PingTimeMean += (fixedTime - pendingSoaks[inbound.id % pendingSoaks.Length].time) * 1000;
                stats.PingTimeMeanCount++;
            }
            else if (cmd == NetworkEvent.Type.Disconnect)
            {
                connection[0] = default(NetworkConnection);
                break;
            }
        }

        if (ctx.Connected == 0)
        {
            return;
        }

        if (fixedTime - ctx.StartedAt > ctx.Duration)
        {
            ctx.Done = 1;
        }

        if (fixedTime > ctx.NextStatsPrint)
        {
            ctx.NextStatsPrint = fixedTime + 10;
            //DumpSimulatorStatistics();
            //Util.DumpReliabilityStatistics(driver, pipeline, connection[0]);
        }

        ctx.Accumulator += deltaTime;

        while (ctx.Connected == 1 && ctx.Done == 0 && ctx.Accumulator >= ctx.SendInterval)
        {
            ctx.FrameId++;
            ctx.Accumulator -= ctx.SendInterval;
            SendPacket(ref stats, ref ctx);
        }

        Util.GatherReliabilityStats(ref stats, ref lastStats, driver, pipeline, reliableStageId, connection[0], timestamp);

        jobContext[0]    = ctx;
        jobStatistics[0] = stats;
        jobStatistics[1] = lastStats;
    }