From 6efff7654c0ab2bc7b4e9df4dcd58e9dbd2d52e5 Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 5 Jul 2016 11:36:05 +0200 Subject: [PATCH] leverage pool functions --- transport/internet/kcp/segment.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/transport/internet/kcp/segment.go b/transport/internet/kcp/segment.go index 1e1b20cf..6676a535 100644 --- a/transport/internet/kcp/segment.go +++ b/transport/internet/kcp/segment.go @@ -186,10 +186,9 @@ func ReadSegment(buf []byte) (Segment, []byte) { buf = buf[2:] if cmd == SegmentCommandData { - seg := &DataSegment{ - Conv: conv, - Opt: opt, - } + seg := NewDataSegment() + seg.Conv = conv + seg.Opt = opt if len(buf) < 16 { return nil, nil } @@ -215,10 +214,9 @@ func ReadSegment(buf []byte) (Segment, []byte) { } if cmd == SegmentCommandACK { - seg := &AckSegment{ - Conv: conv, - Opt: opt, - } + seg := NewAckSegment() + seg.Conv = conv + seg.Opt = opt if len(buf) < 9 { return nil, nil } @@ -247,11 +245,10 @@ func ReadSegment(buf []byte) (Segment, []byte) { return seg, buf } - seg := &CmdOnlySegment{ - Conv: conv, - Cmd: cmd, - Opt: opt, - } + seg := NewCmdOnlySegment() + seg.Conv = conv + seg.Cmd = cmd + seg.Opt = opt if len(buf) < 8 { return nil, nil