METADAPT-A handles closing messages
This commit is contained in:
parent
5b42030f9d
commit
a0b49e950e
10
metadapta.go
10
metadapta.go
@ -7,6 +7,7 @@ import "sync"
|
||||
import "git.tebibyte.media/sashakoshka/hopp/tape"
|
||||
import "git.tebibyte.media/sashakoshka/go-util/sync"
|
||||
|
||||
const closeMethod = 0xFFFF
|
||||
const int64Max = int64((^uint64(0)) >> 1)
|
||||
|
||||
// Party represents a side of a connection.
|
||||
@ -169,6 +170,7 @@ func (this *transA) Close() error {
|
||||
}
|
||||
|
||||
func (this *transA) closeDontUnlist() error {
|
||||
this.Send(closeMethod, nil)
|
||||
return this.incoming.Close()
|
||||
}
|
||||
|
||||
@ -184,10 +186,14 @@ func (this *transA) Receive() (method uint16, data []byte, err error) {
|
||||
receive := this.incoming.Receive()
|
||||
if receive != nil {
|
||||
if message, ok := <- receive; ok {
|
||||
return message.method, message.payload, nil
|
||||
if message.method != closeMethod {
|
||||
return message.method, message.payload, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// close and return error on failure
|
||||
this.Close()
|
||||
if this.parent.err == nil {
|
||||
return 0, nil, fmt.Errorf("could not receive message: %w", io.EOF)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user