close channels.
This commit is contained in:
parent
6bdfd1d1b1
commit
45a4ee92eb
14
nexgb/xgb.go
14
nexgb/xgb.go
|
@ -188,10 +188,13 @@ type xid struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateXids sends new Ids down the channel for NewId to use.
|
// generateXids sends new Ids down the channel for NewId to use.
|
||||||
|
// generateXids should be run in its own goroutine.
|
||||||
// This needs to be updated to use the XC Misc extension once we run out of
|
// This needs to be updated to use the XC Misc extension once we run out of
|
||||||
// new ids.
|
// new ids.
|
||||||
// Thanks to libxcb/src/xcb_xid.c. This code is greatly inspired by it.
|
// Thanks to libxcb/src/xcb_xid.c. This code is greatly inspired by it.
|
||||||
func (conn *Conn) generateXIds() {
|
func (conn *Conn) generateXIds() {
|
||||||
|
defer close(conn.xidChan)
|
||||||
|
|
||||||
// This requires some explanation. From the horse's mouth:
|
// This requires some explanation. From the horse's mouth:
|
||||||
// "The resource-id-mask contains a single contiguous set of bits (at least
|
// "The resource-id-mask contains a single contiguous set of bits (at least
|
||||||
// 18). The client allocates resource IDs for types WINDOW, PIXMAP,
|
// 18). The client allocates resource IDs for types WINDOW, PIXMAP,
|
||||||
|
@ -234,7 +237,8 @@ func (c *Conn) newSequenceId() uint16 {
|
||||||
return <-c.seqChan
|
return <-c.seqChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// generateSeqIds returns new sequence ids.
|
// generateSeqIds returns new sequence ids. It is meant to be run in its
|
||||||
|
// own goroutine.
|
||||||
// A sequence id is generated for *every* request. It's the identifier used
|
// A sequence id is generated for *every* request. It's the identifier used
|
||||||
// to match up replies with requests.
|
// to match up replies with requests.
|
||||||
// Since sequence ids can only be 16 bit integers we start over at zero when it
|
// Since sequence ids can only be 16 bit integers we start over at zero when it
|
||||||
|
@ -242,6 +246,8 @@ func (c *Conn) newSequenceId() uint16 {
|
||||||
// N.B. As long as the cookie buffer is less than 2^16, there are no limitations
|
// N.B. As long as the cookie buffer is less than 2^16, there are no limitations
|
||||||
// on the number (or kind) of requests made in sequence.
|
// on the number (or kind) of requests made in sequence.
|
||||||
func (c *Conn) generateSeqIds() {
|
func (c *Conn) generateSeqIds() {
|
||||||
|
defer close(c.seqChan)
|
||||||
|
|
||||||
seqid := uint16(1)
|
seqid := uint16(1)
|
||||||
for {
|
for {
|
||||||
c.seqChan <- seqid
|
c.seqChan <- seqid
|
||||||
|
@ -271,7 +277,11 @@ func (c *Conn) NewRequest(buf []byte, cookie *Cookie) {
|
||||||
|
|
||||||
// sendRequests is run as a single goroutine that takes requests and writes
|
// sendRequests is run as a single goroutine that takes requests and writes
|
||||||
// the bytes to the wire and adds the cookie to the cookie queue.
|
// the bytes to the wire and adds the cookie to the cookie queue.
|
||||||
|
// It is meant to be run as its own goroutine.
|
||||||
func (c *Conn) sendRequests() {
|
func (c *Conn) sendRequests() {
|
||||||
|
defer close(c.reqChan)
|
||||||
|
defer close(c.cookieChan)
|
||||||
|
|
||||||
for req := range c.reqChan {
|
for req := range c.reqChan {
|
||||||
// ho there! if the cookie channel is nearly full, force a round
|
// ho there! if the cookie channel is nearly full, force a round
|
||||||
// trip to clear out the cookie buffer.
|
// trip to clear out the cookie buffer.
|
||||||
|
@ -309,6 +319,8 @@ func (c *Conn) writeBuffer(buf []byte) {
|
||||||
// channel. (It is an error if no such cookie exists in this case.)
|
// channel. (It is an error if no such cookie exists in this case.)
|
||||||
// Finally, cookies that came "before" this reply are always cleaned up.
|
// Finally, cookies that came "before" this reply are always cleaned up.
|
||||||
func (c *Conn) readResponses() {
|
func (c *Conn) readResponses() {
|
||||||
|
defer close(c.eventChan)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err Error
|
err Error
|
||||||
event Event
|
event Event
|
||||||
|
|
Loading…
Reference in New Issue