增加主动断开

This commit is contained in:
boyce
2019-03-06 09:22:14 +08:00
parent c74a8a5318
commit 3e5a288de7
2 changed files with 21 additions and 0 deletions

View File

@@ -5,6 +5,9 @@ import (
"net/http"
"os"
"time"
"github.com/duanhf2012/origin/service"
"github.com/duanhf2012/origin/sysmodule"
)
type HttpServer struct {
@@ -54,6 +57,7 @@ func (slf *HttpServer) startListen() error {
}
if err != nil {
service.GetLogger().Printf(sysmodule.LEVER_FATAL, "http.ListenAndServe(%d, nil) error:%v\n", listenPort, err)
fmt.Printf("http.ListenAndServe(%d, %v) error\n", slf.port, err)
os.Exit(1)
}

View File

@@ -7,6 +7,9 @@ import (
"sync"
"time"
"github.com/duanhf2012/origin/service"
"github.com/duanhf2012/origin/sysmodule"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/gotoxu/cors"
@@ -15,6 +18,7 @@ import (
type IWebsocketServer interface {
SendMsg(clientid uint64, messageType int, msg []byte) bool
CreateClient(conn *websocket.Conn) *WSClient
Disconnect(clientid uint64)
ReleaseClient(pclient *WSClient)
}
@@ -116,6 +120,7 @@ func (slf *WebsocketServer) startListen() {
}
if err != nil {
service.GetLogger().Printf(sysmodule.LEVER_FATAL, "http.ListenAndServe(%d, nil) error:%v\n", slf.port, err)
fmt.Printf("http.ListenAndServe(%d, nil) error\n", slf.port)
os.Exit(1)
}
@@ -145,6 +150,18 @@ func (slf *WebsocketServer) SendMsg(clientid uint64, messageType int, msg []byte
return true
}
func (slf *WebsocketServer) Disconnect(clientid uint64) {
slf.locker.Lock()
defer slf.locker.Unlock()
value, ok := slf.mapClient[clientid]
if ok == false {
return
}
value.conn.Close()
//slf.ReleaseClient(value)
}
func (slf *WebsocketServer) Stop() {
}