diff options
author | Bryan Matsuo <bryan.matsuo@gmail.com> | 2014-12-04 18:09:24 -0800 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-09-08 16:49:23 +0200 |
commit | dd00568d44383890cff03d566c014252e096fbfc (patch) | |
tree | e5806149de2061f76576b5ac3692fec6a1c4d128 | |
parent | a1d1151017ada36a0431969e3e05f35f1dd6204f (diff) | |
download | haven-dd00568d44383890cff03d566c014252e096fbfc.tar.gz haven-dd00568d44383890cff03d566c014252e096fbfc.tar.xz haven-dd00568d44383890cff03d566c014252e096fbfc.zip |
assign a sequence id to the cookie before returning from Conn.NewRequest
-rw-r--r-- | nexgb/xgb.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/nexgb/xgb.go b/nexgb/xgb.go index 4403ea0..e7f2411 100644 --- a/nexgb/xgb.go +++ b/nexgb/xgb.go @@ -290,6 +290,9 @@ func (c *Conn) generateSeqIds() { type request struct { buf []byte cookie *Cookie + + // seq is closed when the request (cookie) has been sequenced by the Conn. + seq chan struct{} } // NewRequest takes the bytes and a cookie of a particular request, constructs @@ -311,7 +314,9 @@ type request struct { // In all likelihood, you should be able to copy and paste with some minor // edits the generated code for the request you want to issue. func (c *Conn) NewRequest(buf []byte, cookie *Cookie) { - c.reqChan <- &request{buf: buf, cookie: cookie} + seq := make(chan struct{}) + c.reqChan <- &request{buf: buf, cookie: cookie, seq: seq} + <-seq } // sendRequests is run as a single goroutine that takes requests and writes @@ -329,6 +334,7 @@ func (c *Conn) sendRequests() { c.noop() } req.cookie.Sequence = c.newSequenceId() + close(req.seq) c.cookieChan <- req.cookie c.writeBuffer(req.buf) } |