Nothing being received on a channel

Written by
Link to Post by 

Hello – I am trying to read on a connection and then pass off work to be done in different channels. Since I have many different connections I have a map of connectionInfo’s. On opening a connection I initialize the below struct with a bunch of empty channels (make(chan [512]byte).

type connectionInfo struct { conn net.Conn initiatedConnection bool openChan chan [512]byte openRespChan chan [512]byte etc. } 

I then start up go routines that listen to their respective channel in the struct and process information afterwards.

 // ci is a ConnectionInfo go handleOpen(ci.conn, ci.openChan) go handleCreate(ci.conn, ci.createChan) etc. 

After starting the go routines I sit in a loop reading from the connection and passing off the work to the appropriate go routine.

for { buf := make([]byte, 512) _, err := conn.Read(buf) header := Header{} err = binary.Read(bytes.NewBuffer(buf), binary.BigEndian, &header) if header.CellType == 1 { ci.openChan <- arrayBuf } else if header.CellType == 2 || header.CellType == 3 { ... } else { fmt.Println("Unknown cell type: ", header.CellType) } } 

This is what handleOpen looks like.

 for { select { case req := <-openChan: do something here } 

Even though I can see things being passed into the channel in the for loop the handler is always waiting.

Is there a way to print out the address of a channel to see if the channel that is taking things in the for loop is the same one as the one processing things in the goroutine?

submitted by /u/reiwaaa
[link] [comments]

Article Tags:
· ·
Article Categories:

Leave a Reply