Example #1
0
func (bridge *Bridge) RunBusLineRecv(conn net.Conn, connClosed chan int) {
	buf := leakybuf.Get()
	defer leakybuf.Put(buf)

	for {
		err := ReadAll(conn, buf[:MsgeaderLen])
		if err != nil {
			log.D("BuslineRecv: ", err)
			break
		}
		msg, dataLen := ParseMessageHeader(buf)
		msg.flow = bridge.flow
		msg.data = make([]byte, dataLen)
		err = ReadAll(conn, msg.data)
		if err != nil {
			log.D("BuslineRecv: ", err)
			break
		}

		msg.flow.RecvMsg(msg)
	}

	connClosed <- 1
	conn.Close()
}
Example #2
0
func ConnCopy(src, dst net.Conn) {
	defer dst.Close()

	buf := leakybuf.Get()
	defer leakybuf.Put(buf)

	for {
		ConnPrepareRead(src)
		count, err := src.Read(buf)
		if err != nil {
			return
		}

		err = WriteAll(dst, buf[:count])
		if err != nil {
			return
		}
	}
}
Example #3
0
func (bridge *Bridge) RunBusLineSend(conn net.Conn, connClosed chan int) {
	buf := leakybuf.Get()
	defer leakybuf.Put(buf)
	var msg *Message = nil

LOOP:
	for {
		select {
		case msg = <-bridge.highPrioSendBus:
		case msg = <-bridge.SendBus:
		case <-connClosed:
			break LOOP
		}

		msg.ack = msg.flow.Ack()
		msg.PacketHeader(buf)
		log.D("msg > seq:", msg.seq, " ack:", msg.ack,
			" channel:", msg.channel, " syn:", msg.syn, " fin:", msg.fin)
		log.D("msg > ", string(msg.data))
		err := WriteAll(conn, buf[:MsgeaderLen])
		if err != nil {
			log.D("BuslineSend: ", err)
			break
		}
		err = WriteAll(conn, msg.data)
		if err != nil {
			log.D("BuslineSend: ", err)
			break
		}

		msg = nil
	}

	conn.Close()
	if msg != nil {
		// resend the message
		bridge.highPrioSendBus <- msg
	}
}