net_transport.go
func (n *NetworkTransport) handleConn(connCtx context.Context, conn net.Conn) {
	defer conn.Close()
	r := bufio.NewReader(conn)
	w := bufio.NewWriter(conn)
	dec := codec.NewDecoder(r, &codec.MsgpackHandle{})
	enc := codec.NewEncoder(w, &codec.MsgpackHandle{})

	for {
		select {
		case <-connCtx.Done():
			n.logger.Println("[DEBUG] raft-net: stream layer is closed")
			return
		default:
		}

		if err := n.handleCommand(r, dec, enc); err != nil {
			if err != io.EOF {
				n.logger.Printf("[ERR] raft-net: Failed to decode incoming command: %v", err)
			}
			return
		}
		if err := w.Flush(); err != nil {
			n.logger.Printf("[ERR] raft-net: Failed to flush response: %v", err)
			return
		}
	}
}
func (n *NetworkTransport) handleConn(connCtx context.Context, conn net.Conn) {
	defer conn.Close()
	r := bufio.NewReader(conn)
	w := bufio.NewWriter(conn)
	dec := codec.NewDecoder(r, &codec.MsgpackHandle{})
	enc := codec.NewEncoder(w, &codec.MsgpackHandle{})

	for {
		select {
		case <-connCtx.Done():
			n.logger.Println("[DEBUG] raft-net: stream layer is closed")
			return
		default:
		}

		if err := n.handleCommand(r, dec, enc); err != nil {
			if err != io.EOF {
				n.logger.Printf("[ERR] raft-net: Failed to decode incoming command: %v", err)
			}
			return
		}
		if err := w.Flush(); err != nil {
			n.logger.Printf("[ERR] raft-net: Failed to flush response: %v", err)
			return
		}
	}
}
func ( n * NetworkTransport ) handleConn ( connCtx context . Context , conn net . Conn ) { defer conn . Close ( ) r := bufio . NewReader ( conn ) w := bufio . NewWriter ( conn ) dec := codec . NewDecoder ( r , & codec . MsgpackHandle { } ) enc := codec . NewEncoder ( w , & codec . MsgpackHandle { } ) for { select { case <- connCtx . Done ( ) : n . logger . Println ( " " ) return default : } if err := n . handleCommand ( r , dec , enc ) ; err != nil { if err != io . EOF { n . logger . Printf ( " " , err ) } return } if err := w . Flush ( ) ; err != nil { n . logger . Printf ( " " , err ) return } } }
// handleConn is used to handle an inbound connection for its lifespan. The
// handler will exit when the passed context is cancelled or the connection is
// closed.
handleConn is used to handle an inbound connection for its lifespan . The handler will exit when the passed context is cancelled or the connection is closed .