From d865b27a9850465575bb064fadf7a964788c3d56 Mon Sep 17 00:00:00 2001 From: Ian Denhardt Date: Mon, 30 Jan 2023 18:33:42 -0500 Subject: [PATCH] rpc.questionFlags: Add .Contains() method Similar to the one for answerFlags --- rpc/question.go | 8 +++++++- rpc/rpc.go | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/rpc/question.go b/rpc/question.go index 1ea07efe..99116c42 100644 --- a/rpc/question.go +++ b/rpc/question.go @@ -43,6 +43,12 @@ const ( finishSent ) +// flags.Contains(flag) Returns true iff flags contains flag, which must +// be a single flag. +func (flags questionFlags) Contains(flag questionFlags) bool { + return flags&flag != 0 +} + // newQuestion adds a new question to c's table. func (c *lockedConn) newQuestion(method capnp.Method) *question { q := &question{ @@ -110,7 +116,7 @@ func (q *question) handleCancel(ctx context.Context) { q.c.withLocked(func(c *lockedConn) { // Promise already fulfilled? - if q.flags&finished != 0 { + if q.flags.Contains(finished) { return } q.flags |= finished diff --git a/rpc/rpc.go b/rpc/rpc.go index 075d3444..9a513152 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -487,7 +487,7 @@ func (c *lockedConn) releaseAnswers(rl *releaseList, answers map[answerID]*answe func (c *lockedConn) releaseQuestions(rl *releaseList, questions []*question) { for _, q := range questions { - canceled := q != nil && q.flags&finished != 0 + canceled := q != nil && q.flags.Contains(finished) if !canceled { // Only reject the question if it isn't already flagged // as finished; otherwise it was rejected when the finished @@ -1085,7 +1085,7 @@ func (c *Conn) handleReturn(ctx context.Context, ret rpccp.Return, release capnp "incoming return: question " + str.Utod(qid) + " does not exist", )) } - canceled := q.flags&finished != 0 + canceled := q.flags.Contains(finished) q.flags |= finished if canceled { // Wait for cancelation task to write the Finish message. If the @@ -1093,7 +1093,7 @@ func (c *Conn) handleReturn(ctx context.Context, ret rpccp.Return, release capnp // reuse the ID. select { case <-q.finishMsgSend: - if q.flags&finishSent != 0 { + if q.flags.Contains(finishSent) { c.lk.questionID.remove(uint32(qid)) } rl.Add(release) @@ -1104,7 +1104,7 @@ func (c *Conn) handleReturn(ctx context.Context, ret rpccp.Return, release capnp c := unlockedConn <-q.finishMsgSend c.withLocked(func(c *lockedConn) { - if q.flags&finishSent != 0 { + if q.flags.Contains(finishSent) { c.lk.questionID.remove(uint32(qid)) } })