修改:1.日志记录连接编号 2.查看服务信息修改
git-svn-id: svn://47.119.165.148/zhub@124 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
@@ -345,7 +345,7 @@ func (c *Client) receive() {
|
|||||||
continue
|
continue
|
||||||
case "+": // +pong, +xxx
|
case "+": // +pong, +xxx
|
||||||
if strings.EqualFold("+ping", string(v)) {
|
if strings.EqualFold("+ping", string(v)) {
|
||||||
// c.send("+pong")
|
c.send("+pong")
|
||||||
}
|
}
|
||||||
case "-":
|
case "-":
|
||||||
fmt.Println("error:", string(v))
|
fmt.Println("error:", string(v))
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ func cleanup(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func info(w http.ResponseWriter, r *http.Request) {
|
func info(w http.ResponseWriter, r *http.Request) {
|
||||||
topics := zsub.Info()
|
info := zsub.Info()
|
||||||
renderJson(w, topics)
|
renderJson(w, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderJson(w http.ResponseWriter, d interface{}) {
|
func renderJson(w http.ResponseWriter, d interface{}) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func msgAccept(v Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if conf.LogDebug {
|
if conf.LogDebug {
|
||||||
log.Println("rcmd: " + strings.Join(rcmd, " "))
|
log.Println("[", v.Conn.sn, "] rcmd: "+strings.Join(rcmd, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(rcmd) == 1 {
|
if len(rcmd) == 1 {
|
||||||
|
|||||||
35
zsub/zsub.go
35
zsub/zsub.go
@@ -8,6 +8,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
"zhub/conf"
|
"zhub/conf"
|
||||||
@@ -21,6 +22,7 @@ var (
|
|||||||
locks: make(map[string][]*Lock),
|
locks: make(map[string][]*Lock),
|
||||||
conns: make([]*ZConn, 0),
|
conns: make([]*ZConn, 0),
|
||||||
}
|
}
|
||||||
|
SN int32 = 1000
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -73,6 +75,7 @@ type ZSub struct {
|
|||||||
|
|
||||||
type ZConn struct { //ZConn
|
type ZConn struct { //ZConn
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
|
sn int32 // 连接编号
|
||||||
conn *net.Conn
|
conn *net.Conn
|
||||||
groupid string
|
groupid string
|
||||||
topics []string
|
topics []string
|
||||||
@@ -94,6 +97,7 @@ type Lock struct {
|
|||||||
|
|
||||||
func NewZConn(conn *net.Conn) *ZConn {
|
func NewZConn(conn *net.Conn) *ZConn {
|
||||||
return &ZConn{
|
return &ZConn{
|
||||||
|
sn: atomic.AddInt32(&SN, 1), // 连接编号
|
||||||
conn: conn,
|
conn: conn,
|
||||||
topics: []string{},
|
topics: []string{},
|
||||||
timers: []string{},
|
timers: []string{},
|
||||||
@@ -272,9 +276,9 @@ func ServerStart(addr string) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Println("conn start: ", conn.RemoteAddr())
|
|
||||||
|
|
||||||
zConn := NewZConn(&conn)
|
zConn := NewZConn(&conn)
|
||||||
|
|
||||||
|
log.Println("conn start:", conn.RemoteAddr(), "[", zConn.sn, "]")
|
||||||
go zsub.acceptHandler(zConn)
|
go zsub.acceptHandler(zConn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,6 +289,7 @@ func (s *ZSub) acceptHandler(c *ZConn) {
|
|||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log.Println("acceptHandler Recovered:", r)
|
log.Println("acceptHandler Recovered:", r)
|
||||||
}
|
}
|
||||||
|
log.Println("conn closed:", (*c.conn).RemoteAddr(), "[", c.sn, "]")
|
||||||
}()
|
}()
|
||||||
defer func() {
|
defer func() {
|
||||||
// conn remove to conns
|
// conn remove to conns
|
||||||
@@ -442,8 +447,8 @@ func (s *ZSub) shutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Info() map[string]interface{} {
|
func Info() map[string]interface{} {
|
||||||
m := map[string]interface{}{}
|
// topics
|
||||||
|
topics := map[string]interface{}{}
|
||||||
for s, topic := range zsub.topics {
|
for s, topic := range zsub.topics {
|
||||||
// {groups:[{name:xxx,size:xx}]}
|
// {groups:[{name:xxx,size:xx}]}
|
||||||
arr := make([]map[string]interface{}, 0)
|
arr := make([]map[string]interface{}, 0)
|
||||||
@@ -456,10 +461,28 @@ func Info() map[string]interface{} {
|
|||||||
"mcount": topic.mcount,
|
"mcount": topic.mcount,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
m[s] = arr
|
topics[s] = arr
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
// conns
|
||||||
|
conns := make([]interface{}, 0)
|
||||||
|
for _, c := range zsub.conns {
|
||||||
|
m := make(map[string]interface{}, 0)
|
||||||
|
m["remoteaddr"] = (*c.conn).RemoteAddr()
|
||||||
|
m["groupid"] = c.groupid
|
||||||
|
m["topics"] = c.topics
|
||||||
|
m["timers"] = c.timers
|
||||||
|
conns = append(conns, m)
|
||||||
|
}
|
||||||
|
|
||||||
|
info := map[string]interface{}{
|
||||||
|
"topics": topics,
|
||||||
|
"topicsize": len(topics),
|
||||||
|
"timersize": len(zsub.timers),
|
||||||
|
"conns": conns,
|
||||||
|
"connsize": len(zsub.conns),
|
||||||
|
}
|
||||||
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ZSub) Clearup() {
|
func (s *ZSub) Clearup() {
|
||||||
|
|||||||
Reference in New Issue
Block a user