示例#1
0
文件: connection.go 项目: gemrs/gem
func (c *Connection) Init(conn net.Conn, parentLogger log.Log) {
	c.ReadBuffer = encoding.NewBuffer()
	c.WriteBuffer = encoding.NewBuffer()
	c.Read = make(chan encoding.Decodable, 16)
	c.Write = make(chan encoding.Encodable, 16)
	c.DisconnectChan = make(chan bool)

	c.log = parentLogger.Child("connection", log.MapContext{"addr": conn.RemoteAddr().String()})
	c.conn = conn
}
示例#2
0
文件: recover.go 项目: gemrs/gem
// recover captures panics in the game client handler and prints a stack trace
func Recover(log log.Log) {
	if err := recover(); err != nil {
		if Unsafe {
			log.Notice("github.com/gemrs/gem/gem/safe: Unsafe mode enabled; not recovering")
			panic(err)
		}
		stack := make([]byte, 1024*10)
		runtime.Stack(stack, true)
		log.Error("Recovered from panic in game client handler: %v", err)
		log.Debug(string(stack))
	}
}