From d9367efb2d5103cbfacafba2eb353272e0b18f7c Mon Sep 17 00:00:00 2001 From: v2ray Date: Tue, 26 Apr 2016 01:08:41 +0200 Subject: [PATCH] comments --- common/signal/close.go | 6 ++++++ common/uuid/uuid.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/common/signal/close.go b/common/signal/close.go index dd28978ad..c654ff178 100644 --- a/common/signal/close.go +++ b/common/signal/close.go @@ -1,10 +1,12 @@ package signal +// CancelSignal is a signal passed to goroutine, in order to cancel the goroutine on demand. type CancelSignal struct { cancel chan struct{} done chan struct{} } +// NewCloseSignal creates a new CancelSignal. func NewCloseSignal() *CancelSignal { return &CancelSignal{ cancel: make(chan struct{}), @@ -12,18 +14,22 @@ func NewCloseSignal() *CancelSignal { } } +// Cancel signals the goroutine to stop. func (this *CancelSignal) Cancel() { close(this.cancel) } +// WaitForCancel should be monitored by the goroutine for when to stop. func (this *CancelSignal) WaitForCancel() <-chan struct{} { return this.cancel } +// Done signals the caller that the goroutine has completely finished. func (this *CancelSignal) Done() { close(this.done) } +// WaitForDone is used by caller to wait for the goroutine finishes. func (this *CancelSignal) WaitForDone() <-chan struct{} { return this.done } diff --git a/common/uuid/uuid.go b/common/uuid/uuid.go index 01abec2ff..d58b64abf 100644 --- a/common/uuid/uuid.go +++ b/common/uuid/uuid.go @@ -16,14 +16,17 @@ var ( type UUID [16]byte +// String returns the string representation of this UUID. func (this *UUID) String() string { return bytesToString(this.Bytes()) } +// Bytes returns the bytes representation of this UUID. func (this *UUID) Bytes() []byte { return this[:] } +// Equals returns true if this UUID equals another UUID by value. func (this *UUID) Equals(another *UUID) bool { if this == nil && another == nil { return true @@ -61,12 +64,14 @@ func bytesToString(bytes []byte) string { return result } +// New creates an UUID with random value. func New() *UUID { uuid := new(UUID) rand.Read(uuid.Bytes()) return uuid } +// PraseBytes converts an UUID in byte form to object. func ParseBytes(b []byte) (*UUID, error) { if len(b) != 16 { return nil, ErrorInvalidID @@ -76,6 +81,7 @@ func ParseBytes(b []byte) (*UUID, error) { return uuid, nil } +// ParseString converts an UUID in string form to object. func ParseString(str string) (*UUID, error) { text := []byte(str) if len(text) < 32 {