MCPcopy
hub / github.com/shadow1ng/fscan / Run

Method Run

web/ws/hub.go:73–112  ·  view source on GitHub ↗

Run 启动Hub

()

Source from the content-addressed store, hash-verified

71
72// Run 启动Hub
73func (h *Hub) Run() {
74 for {
75 select {
76 case client := <-h.register:
77 h.mu.Lock()
78 h.clients[client] = true
79 h.mu.Unlock()
80
81 // 发送连接成功消息
82 msg := Message{
83 Type: MsgConnected,
84 Timestamp: time.Now().UnixMilli(),
85 Data: map[string]string{"status": "connected"},
86 }
87 if data, err := json.Marshal(msg); err == nil {
88 client.send <- data
89 }
90
91 case client := <-h.unregister:
92 h.mu.Lock()
93 if _, ok := h.clients[client]; ok {
94 delete(h.clients, client)
95 close(client.send)
96 }
97 h.mu.Unlock()
98
99 case message := <-h.broadcast:
100 h.mu.Lock()
101 for client := range h.clients {
102 select {
103 case client.send <- message:
104 default:
105 close(client.send)
106 delete(h.clients, client)
107 }
108 }
109 h.mu.Unlock()
110 }
111 }
112}
113
114// Broadcast 广播消息给所有客户端
115func (h *Hub) Broadcast(msgType MessageType, data interface{}) {

Callers 15

StartServerFunction · 0.95
TestCheckSumFunction · 0.80
TestCheckSum_IdempotentFunction · 0.80
TestCheckSum_EdgeCasesFunction · 0.80
TestGenSequenceFunction · 0.80
TestGenIdentifierFunction · 0.80
TestGetOptimalTopCountFunction · 0.80
TestIsContainFunction · 0.80
TestArrayCountValueTopFunction · 0.80

Calls

no outgoing calls

Tested by 15

TestCheckSumFunction · 0.64
TestCheckSum_IdempotentFunction · 0.64
TestCheckSum_EdgeCasesFunction · 0.64
TestGenSequenceFunction · 0.64
TestGenIdentifierFunction · 0.64
TestGetOptimalTopCountFunction · 0.64
TestIsContainFunction · 0.64
TestArrayCountValueTopFunction · 0.64
TestMakemsgFunction · 0.64