MCPcopy
hub / github.com/tinode/chat / readOnce

Method readOnce

server/hdl_longpoll.go:97–115  ·  view source on GitHub ↗
(wrt http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

95}
96
97func (sess *Session) readOnce(wrt http.ResponseWriter, req *http.Request) (int, error) {
98 if req.ContentLength > globals.maxMessageSize {
99 return http.StatusExpectationFailed, errors.New("request too large")
100 }
101
102 req.Body = http.MaxBytesReader(wrt, req.Body, globals.maxMessageSize)
103 raw, err := io.ReadAll(req.Body)
104 if err == nil {
105 // Locking-unlocking is needed because the client may issue multiple requests in parallel.
106 // Should not affect performance
107 sess.lock.Lock()
108 statsInc("IncomingMessagesLongpollTotal", 1)
109 sess.dispatchRaw(raw)
110 sess.lock.Unlock()
111 return 0, nil
112 }
113
114 return 0, err
115}
116
117// serveLongPoll handles long poll connections when WebSocket is not available
118// Connection could be without sid or with sid:

Callers 1

serveLongPollFunction · 0.95

Calls 4

dispatchRawMethod · 0.95
statsIncFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected