Skip to content

Instantly share code, notes, and snippets.

@gobwas
Last active February 18, 2019 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gobwas/85a591a21ad6fa9dedaecd8a86dbabac to your computer and use it in GitHub Desktop.
Save gobwas/85a591a21ad6fa9dedaecd8a86dbabac to your computer and use it in GitHub Desktop.
ch := NewChannel(conn)
// Make conn to be observed by netpoll instance.
poller.Start(conn, netpoll.EventRead, func() {
// We spawn goroutine here to prevent poller wait loop
// to become locked during receiving packet from ch.
go Receive(ch)
})
// Receive reads a packet from conn and handles it somehow.
func (ch *Channel) Receive() {
buf := bufio.NewReader(ch.conn)
pkt := readPacket(buf)
c.handle(pkt)
}
@brutella
Copy link

It should be go ch.Receive() right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment