Skip to content

Commit

Permalink
misc: add deadtime of connection(#master)
Browse files Browse the repository at this point in the history
  • Loading branch information
OhYee committed Jan 21, 2020
1 parent abf372d commit 12d1da1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions server/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"github.com/xtaci/kcp-go"
"time"
)

// Send data to addr
Expand All @@ -10,8 +11,10 @@ func Send(addr string, data []byte) (repBytes []byte, repErr error, err error) {
if err != nil {
return
}
conn.SetDeadline(time.Now().Add(time.Second * time.Duration(connDeadTime)))

conn.Write(data)
Log("Write %v", data)
repBytes, repErr, err = messageHandle(conn)
return
}
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"github.com/OhYee/ait/message"
"github.com/xtaci/kcp-go"
"net"
"time"
)

// Singleton Pattern
var (
closeThread = make([]chan bool, 0)
closeThread = make([]chan bool, 0)
connDeadTime = 5000
)

// Start server, blocking the process after returned
Expand Down Expand Up @@ -40,6 +42,7 @@ func thread(threadID int, listener net.Listener) {
Err(err)
continue
}
conn.SetDeadline(time.Now().Add(time.Second * time.Duration(connDeadTime)))
if handle(threadID, conn) != nil {
Err(err)
continue
Expand Down

0 comments on commit 12d1da1

Please sign in to comment.