// -------------------------------
// receiver coroutine run continuously until communication error
// ccmd chan is used to signal a crash
receiver coroutine run continuously until communication error
ccmd chan is used to signal a crash
// ------------------------------- // receiver coroutine run continuously until communication error // ccmd chan is used to signal a crash
func (a *Appliance) tcpReceiver(cnx net.Conn, ccmd chan int) {
	var bye = func() {
		ccmd <- 0
	}
	defer bye()
	var err error
	for {
		header := make([]byte, 4*4)
		if _, err = io.ReadFull(cnx, header); err != nil {
			log.Println("Rcv error:", err)
			return
		}
		if int(uiRd(header)) != 0x55aa {
			log.Println("Sync error:", err)
			return
		}
		code := int(uiRd(header[8:]))
		sz := int(uiRd(header[12:]))
		if sz > 10000 {
			log.Println("Dubious big response")
			return
		}
		response := make([]byte, sz)
		if _, err = io.ReadFull(cnx, response); err != nil {
			log.Println("Read failed", err)
			return
		}
		a.ProcessResponse(code, response[:sz-8])
	}
}
func ( a * Appliance ) tcpReceiver ( cnx net . Conn , ccmd chan int ) { var bye = func ( ) { ccmd <- 0 } defer bye ( ) var err error for { header := make ( [ ] byte , 4 * 4 ) if _ , err = io . ReadFull ( cnx , header ) ; err != nil { log . Println ( " " , err ) return } if int ( uiRd ( header ) ) != 0x55aa { log . Println ( " " , err ) return } code := int ( uiRd ( header [ 8 : ] ) ) sz := int ( uiRd ( header [ 12 : ] ) ) if sz > 10000 { log . Println ( " " ) return } response := make ( [ ] byte , sz ) if _ , err = io . ReadFull ( cnx , response ) ; err != nil { log . Println ( " " , err ) return } a . ProcessResponse ( code , response [ : sz - 8 ] ) } }
receiver coroutine run continuously until communication error
ccmd chan is used to signal a crash
receiver coroutine run continuously until communication error ccmd chan is used to signal a crash