Commit 9f060ce2 authored by Mrs4s's avatar Mrs4s

fix lock & http server error.

parent 3709f5c7
......@@ -4,6 +4,7 @@ import (
"crypto/hmac"
"crypto/sha1"
"encoding/hex"
"os"
"strconv"
"strings"
"time"
......@@ -157,7 +158,13 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
go func() {
log.Infof("CQ HTTP 服务器已启动: %v", addr)
log.Fatal(s.engine.Run(addr))
err := s.engine.Run(addr)
if err != nil {
log.Error(err)
log.Infof("请检查端口是否被占用.")
time.Sleep(time.Second * 5)
os.Exit(1)
}
}()
}
......
......@@ -314,6 +314,8 @@ func (c *websocketConn) handleRequest(bot *coolq.CQBot, payload []byte) {
}
func (s *websocketServer) onBotPushEvent(m coolq.MSG) {
s.eventConnMutex.Lock()
s.eventConnMutex.Unlock()
pos := 0
for _, conn := range s.eventConn {
log.Debugf("向WS客户端 %v 推送Event: %v", conn.RemoteAddr().String(), m.ToJson())
......
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