Exemplo n.º 1
0
func dorecv(session *Tcpsession) {
	for {
		if session.recv_timeout > 0 {
			t := time.Now()
			deadline := t.Add(time.Millisecond * time.Duration(session.recv_timeout))
			session.Conn.SetReadDeadline(deadline)
		}
		p, err := session.decoder.DoRecv(session.Conn)
		if 1 == atomic.LoadInt32(&session.socket_close) {
			break
		}
		if err != nil {
			session.Packet_que <- packet.NewEventPacket(err)
			break
		}
		session.Packet_que <- p
	}
	session.Packet_que <- RecvClose
}
Exemplo n.º 2
0
import (
	"fmt"
	packet "kendynet-go/packet"
	"net"
	"sync/atomic"
	"time"
)

var (
	ErrUnPackError = fmt.Errorf("TcpSession: UnpackError")
	ErrSendClose   = fmt.Errorf("send close")
	ErrSocketClose = fmt.Errorf("socket close")
)

var (
	SendClose   = packet.NewEventPacket(fmt.Errorf("SendClose"))
	RecvClose   = packet.NewEventPacket(fmt.Errorf("RecvClose"))
	NotifyClose = packet.NewEventPacket(fmt.Errorf("notifyClose"))
)

type Tcpsession struct {
	Conn         net.Conn
	Packet_que   chan packet.Packet
	Send_que     chan packet.Packet
	decoder      packet.Decoder
	socket_close int32
	send_close   int32
	ud           interface{}
	recv_timeout uint64 //in ms
	send_timeout uint64 //in ms
}