Beispiel #1
0
func dorecv(session *Tcpsession) {
	for {
		header := make([]byte, 4)
		n, err := io.ReadFull(session.Conn, header)
		if n == 0 && err == io.EOF {
			close(session.Packet_que)
			break
		} else if err != nil {
			close(session.Packet_que)
			break
		}
		size := binary.LittleEndian.Uint32(header)
		if size > packet.Max_bufsize {
			close(session.Packet_que)
			break
		}

		body := make([]byte, size)
		n, err = io.ReadFull(session.Conn, body)
		if n == 0 && err == io.EOF {
			close(session.Packet_que)
			break
		} else if err != nil {
			close(session.Packet_que)
			break
		}
		pkbuf := make([]byte, size+4)
		copy(pkbuf[:], header[:])
		copy(pkbuf[4:], body[:])
		rpk := packet.NewRpacket(packet.NewBufferByBytes(pkbuf), false)
		session.Packet_que <- rpk
	}
}
Beispiel #2
0
func dorecv_raw(session *Tcpsession) {
	for {
		recvbuf := make([]byte, packet.Max_bufsize)
		_, err := session.Conn.Read(recvbuf)
		if err != nil {
			session.Packet_que <- "rclose"
			return
		}
		rpk := packet.NewRpacket(packet.NewBufferByBytes(recvbuf), true)
		session.Packet_que <- rpk
	}
}