MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / sendPingData

Function sendPingData

relay/channel/api_request.go:175–204  ·  view source on GitHub ↗
(c *gin.Context, mutex *sync.Mutex)

Source from the content-addressed store, hash-verified

173}
174
175func sendPingData(c *gin.Context, mutex *sync.Mutex) error {
176 // 增加超时控制,防止锁死等待
177 done := make(chan error, 1)
178 go func() {
179 mutex.Lock()
180 defer mutex.Unlock()
181
182 err := helper.PingData(c)
183 if err != nil {
184 common2.LogError(c, "SSE ping error: "+err.Error())
185 done <- err
186 return
187 }
188
189 if common2.DebugEnabled {
190 println("SSE ping data sent.")
191 }
192 done <- nil
193 }()
194
195 // 设置发送ping数据的超时时间
196 select {
197 case err := <-done:
198 return err
199 case <-time.After(10 * time.Second):
200 return errors.New("SSE ping data send timeout")
201 case <-c.Request.Context().Done():
202 return errors.New("request context cancelled during ping")
203 }
204}
205
206func DoRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http.Response, error) {
207 return doRequest(c, req, info)

Callers 1

startPingKeepAliveFunction · 0.85

Calls 2

PingDataFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected