1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 22:36:12 -04: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
import (
"github.com/v2ray/v2ray-core/common"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/common/serial"
)
@ -20,6 +21,7 @@ const (
)
type ISegment interface {
common.Releasable
ByteSize() int
Bytes([]byte) []byte
}
@ -54,6 +56,10 @@ func (this *DataSegment) ByteSize() int {
return 2 + 1 + 1 + 4 + 4 + 4 + 4 + 2 + this.Data.Len()
}
func (this *DataSegment) Release() {
this.Data.Release()
}
type ACKSegment struct {
Conv uint16
Opt SegmentOption
@ -81,6 +87,8 @@ func (this *ACKSegment) Bytes(b []byte) []byte {
return b
}
func (this *ACKSegment) Release() {}
type TerminationSegment struct {
Conv uint16
Opt SegmentOption
@ -96,6 +104,8 @@ func (this *TerminationSegment) Bytes(b []byte) []byte {
return b
}
func (this *TerminationSegment) Release() {}
func ReadSegment(buf []byte) (ISegment, []byte) {
if len(buf) <= 12 {
return nil, nil