METADAPT-A handles closing messages

This commit is contained in:
Sasha Koshka 2025-01-28 17:06:23 -05:00
parent 5b42030f9d
commit a0b49e950e

View File

@ -7,6 +7,7 @@ import "sync"
import "git.tebibyte.media/sashakoshka/hopp/tape" import "git.tebibyte.media/sashakoshka/hopp/tape"
import "git.tebibyte.media/sashakoshka/go-util/sync" import "git.tebibyte.media/sashakoshka/go-util/sync"
const closeMethod = 0xFFFF
const int64Max = int64((^uint64(0)) >> 1) const int64Max = int64((^uint64(0)) >> 1)
// Party represents a side of a connection. // Party represents a side of a connection.
@ -169,6 +170,7 @@ func (this *transA) Close() error {
} }
func (this *transA) closeDontUnlist() error { func (this *transA) closeDontUnlist() error {
this.Send(closeMethod, nil)
return this.incoming.Close() return this.incoming.Close()
} }
@ -184,10 +186,14 @@ func (this *transA) Receive() (method uint16, data []byte, err error) {
receive := this.incoming.Receive() receive := this.incoming.Receive()
if receive != nil { if receive != nil {
if message, ok := <- receive; ok { 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 { if this.parent.err == nil {
return 0, nil, fmt.Errorf("could not receive message: %w", io.EOF) return 0, nil, fmt.Errorf("could not receive message: %w", io.EOF)
} else { } else {