hopp: Add SetDeadline methods to Conn and Trans

This commit is contained in:
2025-09-05 18:48:12 -04:00
parent 44fb561758
commit 12fbfa6293
3 changed files with 92 additions and 11 deletions

View File

@@ -2,7 +2,7 @@ package hopp
import "io"
import "net"
// import "time"
import "time"
const defaultSizeLimit int64 = 1024 * 1024 // 1 megabyte
@@ -23,6 +23,9 @@ type Conn interface {
// be called in a loop to avoid the connection locking up.
AcceptTrans() (Trans, error)
// SetDeadline operates is [net.Conn.SetDeadline] but for OpenTrans
// and AcceptTrans calls.
SetDeadline(t time.Time) error
// SetSizeLimit sets a limit (in bytes) for how large messages can be.
// By default, this limit is 1 megabyte. Note that this is only
// enforced when sending and receiving byte slices, and it does not
@@ -41,8 +44,6 @@ type Trans interface {
// ID returns the transaction ID. This must not change, and it must be
// unique within the connection. This method is safe for concurrent use.
ID() int64
// TODO: add methods for setting send and receive deadlines
// Send sends a message. This method is not safe for concurrent use.
Send(method uint16, data []byte) error
@@ -59,4 +60,12 @@ type Trans interface {
// previously opened through this function will be discarded. This
// method is not safe for concurrent use, and neither is its result.
ReceiveReader() (method uint16, data io.Reader, err error)
// See the documentation for [net.Conn.SetDeadline].
SetDeadline(time.Time) error
// TODO
// // See the documentation for [net.Conn.SetReadDeadline].
// SetReadDeadline(t time.Time) error
// // See the documentation for [net.Conn.SetWriteDeadline].
// SetWriteDeadline(t time.Time) error
}