Commit c3fb7ea5 authored by AlexStocks's avatar AlexStocks

set the WritePkg timeout to 0

parent 5f02f740
......@@ -12,6 +12,10 @@
- 2018/03/17
> improvement
* set the timeout parameter of WritePkg 0 to send out package asap.
- 2018/03/17
> improvement
* UDP_ENDPOINT session should be long live.
- 2018/03/17
......
......@@ -165,7 +165,8 @@ func (this *EchoClient) heartbeat(session getty.Session) {
ctx.Pkg = &pkg
ctx.PeerAddr = &(this.serverAddr)
if err := session.WritePkg(ctx, WritePkgTimeout); err != nil {
//if err := session.WritePkg(ctx, WritePkgTimeout); err != nil {
if err := session.WritePkg(ctx, WritePkgASAP); err != nil {
log.Warn("session.WritePkg(session{%s}, context{%#v}) = error{%v}", session.Stat(), ctx, err)
session.Close()
......
......@@ -37,6 +37,7 @@ const (
const (
WritePkgTimeout = 1e9
WritePkgASAP = 0e9
)
var (
......
......@@ -76,7 +76,8 @@ func (this *EchoPackageHandler) Write(ss getty.Session, udpCtx interface{}) erro
return err
}
_, err = ss.Write(getty.UDPContext{Pkg: buf.Bytes(), PeerAddr: ctx.PeerAddr})
// _, err = ss.Write(getty.UDPContext{Pkg: buf.Bytes(), PeerAddr: ctx.PeerAddr})
err = ss.WritePkg(getty.UDPContext{Pkg: buf.Bytes(), PeerAddr: ctx.PeerAddr}, WritePkgASAP)
log.Info("WriteEchoPkgTimeMs = %s", time.Since(startTime).String())
return err
......
......@@ -23,6 +23,7 @@ import (
const (
WritePkgTimeout = 1e8
WritePkgASAP = 0e9
)
var (
......@@ -55,7 +56,8 @@ func (this *HeartbeatHandler) Handle(session getty.Session, ctx getty.UDPContext
rspPkg.B = echoHeartbeatResponseString
rspPkg.H.Len = uint16(len(rspPkg.B) + 1)
return session.WritePkg(getty.UDPContext{Pkg: &rspPkg, PeerAddr: ctx.PeerAddr}, WritePkgTimeout)
// return session.WritePkg(getty.UDPContext{Pkg: &rspPkg, PeerAddr: ctx.PeerAddr}, WritePkgTimeout)
return session.WritePkg(getty.UDPContext{Pkg: &rspPkg, PeerAddr: ctx.PeerAddr}, WritePkgASAP)
}
////////////////////////////////////////////
......@@ -67,7 +69,8 @@ type MessageHandler struct{}
func (this *MessageHandler) Handle(session getty.Session, ctx getty.UDPContext) error {
log.Debug("get echo ctx{%#v}", ctx)
// write echo message handle logic here.
return session.WritePkg(ctx, WritePkgTimeout)
// return session.WritePkg(ctx, WritePkgTimeout)
return session.WritePkg(ctx, WritePkgASAP)
}
////////////////////////////////////////////
......
......@@ -77,7 +77,8 @@ func (this *EchoPackageHandler) Write(ss getty.Session, udpCtx interface{}) erro
return err
}
_, err = ss.Write(getty.UDPContext{Pkg: buf.Bytes(), PeerAddr: ctx.PeerAddr})
// _, err = ss.Write(getty.UDPContext{Pkg: buf.Bytes(), PeerAddr: ctx.PeerAddr})
err = ss.WritePkg(getty.UDPContext{Pkg: buf.Bytes(), PeerAddr: ctx.PeerAddr}, WritePkgASAP)
log.Info("WriteEchoPkgTimeMs = %s", time.Since(startTime).String())
return err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment