1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 01:17:30 -05:00

segment.releasable

This commit is contained in:
v2ray 2016-06-27 22:54:59 +02:00
parent 41b230994e
commit aa6726a6d0
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -1,6 +1,7 @@
package kcp package kcp
import ( import (
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc" "github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/serial" "github.com/v2ray/v2ray-core/common/serial"
) )
@ -20,6 +21,7 @@ const (
) )
type ISegment interface { type ISegment interface {
common.Releasable
ByteSize() int ByteSize() int
Bytes([]byte) []byte Bytes([]byte) []byte
} }
@ -54,6 +56,10 @@ func (this *DataSegment) ByteSize() int {
return 2 + 1 + 1 + 4 + 4 + 4 + 4 + 2 + this.Data.Len() return 2 + 1 + 1 + 4 + 4 + 4 + 4 + 2 + this.Data.Len()
} }
func (this *DataSegment) Release() {
this.Data.Release()
}
type ACKSegment struct { type ACKSegment struct {
Conv uint16 Conv uint16
Opt SegmentOption Opt SegmentOption
@ -81,6 +87,8 @@ func (this *ACKSegment) Bytes(b []byte) []byte {
return b return b
} }
func (this *ACKSegment) Release() {}
type TerminationSegment struct { type TerminationSegment struct {
Conv uint16 Conv uint16
Opt SegmentOption Opt SegmentOption
@ -96,6 +104,8 @@ func (this *TerminationSegment) Bytes(b []byte) []byte {
return b return b
} }
func (this *TerminationSegment) Release() {}
func ReadSegment(buf []byte) (ISegment, []byte) { func ReadSegment(buf []byte) (ISegment, []byte) {
if len(buf) <= 12 { if len(buf) <= 12 {
return nil, nil return nil, nil