Compare commits

...

4 Commits

3 changed files with 118 additions and 8 deletions

View File

@ -44,10 +44,12 @@ type Trans interface {
// Send sends a message. This method is not safe for concurrent use. // Send sends a message. This method is not safe for concurrent use.
Send(method uint16, data []byte) error Send(method uint16, data []byte) error
// SendWriter sends data written to an [io.Writer]. Any writer // SendWriter sends data written to an [io.Writer]. The writer must be
// previously opened through this function will be discarded. This // closed after use. Closing the writer flushes any data that hasn't
// method is not safe for concurrent use, and neither is its result. // been written yet. Any writer previously opened through this function
SendWriter(method uint16) (io.Writer, error) // will be discarded. This method is not safe for concurrent use, and
// neither is its result.
SendWriter(method uint16) (io.WriteCloser, error)
// Receive receives a message. This method is not safe for concurrent // Receive receives a message. This method is not safe for concurrent
// use. // use.
Receive() (method uint16, data []byte, err error) Receive() (method uint16, data []byte, err error)

View File

@ -9,7 +9,7 @@ import "git.tebibyte.media/sashakoshka/go-util/sync"
const closeMethod = 0xFFFF const closeMethod = 0xFFFF
const int64Max = int64((^uint64(0)) >> 1) const int64Max = int64((^uint64(0)) >> 1)
const defaultChunkSize = 0x1000
// Party represents a side of a connection. // Party represents a side of a connection.
type Party bool; const ( type Party bool; const (
@ -171,6 +171,8 @@ type transA struct {
id int64 id int64
incoming usync.Gate[incomingMessage] incoming usync.Gate[incomingMessage]
currentReader io.Reader currentReader io.Reader
currentWriter io.Closer
writeBuffer []byte
} }
func (this *transA) Close() error { func (this *transA) Close() error {