Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6322d16 authored by Chiachang Wang's avatar Chiachang Wang Committed by android-build-merger
Browse files

Parse extra un-used TcpInfo am: 902842d3 am: 9fded9f6

am: 1c3f00a9

Change-Id: I4278cc743531c313365ae1a582ff8c6e54326a34
parents 9581e2fe 1c3f00a9
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -112,6 +112,10 @@ public class TcpInfo {
            }
            }
        }
        }
        mFieldsValues = Collections.unmodifiableMap(fields);
        mFieldsValues = Collections.unmodifiableMap(fields);
        // tcp_info structure grows over time as new fields are added. Jump to the end of the
        // structure, as unknown fields might remain at the end of the structure if the tcp_info
        // struct was expanded.
        bytes.position(Math.min(infolen + start, bytes.limit()));
    }
    }


    @VisibleForTesting
    @VisibleForTesting
+24 −0
Original line number Original line Diff line number Diff line
@@ -90,6 +90,13 @@ public class TcpInfoTest {
    private static final byte[] TCP_INFO_BYTES =
    private static final byte[] TCP_INFO_BYTES =
            HexEncoding.decode(TCP_INFO_HEX.toCharArray(), false);
            HexEncoding.decode(TCP_INFO_HEX.toCharArray(), false);


    private static final String EXPANDED_TCP_INFO_HEX = TCP_INFO_HEX
            + "00000000"         // tcpi_delivered
            + "00000000";        // tcpi_delivered_ce
    private static final byte[] EXPANDED_TCP_INFO_BYTES =
            HexEncoding.decode(EXPANDED_TCP_INFO_HEX.toCharArray(), false);
    private static final int EXPANDED_TCP_INFO_LENGTH =
            EXPANDED_TCP_INFO_BYTES.length - TCP_INFO_BYTES.length;
    @Test
    @Test
    public void testParseTcpInfo() {
    public void testParseTcpInfo() {
        final ByteBuffer buffer = ByteBuffer.wrap(TCP_INFO_BYTES);
        final ByteBuffer buffer = ByteBuffer.wrap(TCP_INFO_BYTES);
@@ -99,6 +106,23 @@ public class TcpInfoTest {
        assertEquals(parsedInfo, new TcpInfo(expected));
        assertEquals(parsedInfo, new TcpInfo(expected));
    }
    }


    @Test
    public void testParseTcpInfoExpanded() {
        final ByteBuffer buffer = ByteBuffer.wrap(EXPANDED_TCP_INFO_BYTES);
        final Map<TcpInfo.Field, Number> expected = makeTestTcpInfoHash();
        final TcpInfo parsedInfo =
                TcpInfo.parse(buffer, TCP_INFO_LENGTH_V1 + EXPANDED_TCP_INFO_LENGTH);

        assertEquals(parsedInfo, new TcpInfo(expected));
        assertEquals(buffer.limit(), buffer.position());

        // reset the index.
        buffer.position(0);
        final TcpInfo parsedInfoShorterLen = TcpInfo.parse(buffer, TCP_INFO_LENGTH_V1);
        assertEquals(parsedInfoShorterLen, new TcpInfo(expected));
        assertEquals(TCP_INFO_LENGTH_V1, buffer.position());
    }

    @Test
    @Test
    public void testValidOffset() {
    public void testValidOffset() {
        final ByteBuffer buffer = ByteBuffer.wrap(TCP_INFO_BYTES);
        final ByteBuffer buffer = ByteBuffer.wrap(TCP_INFO_BYTES);