MCPcopy Index your code
hub / github.com/koding/kite / Recv

Method Recv

sockjsclient/xhr.go:102–155  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100}
101
102func (x *XHRSession) Recv() (string, error) {
103 type requestCanceler interface {
104 CancelRequest(*http.Request)
105 }
106
107 // Return previously received messages if there is any.
108 if len(x.messages) > 0 {
109 msg := x.messages[0]
110 x.messages = x.messages[1:]
111 return msg, nil
112 }
113
114 if x.isClosed() {
115 return "", ErrSessionClosed
116 }
117
118 // start to poll from the server until we receive something
119 for {
120 req, err := http.NewRequest("POST", x.sessionURL+"/xhr", nil)
121 if err != nil {
122 return "", errors.New("invalid session url: " + err.Error())
123 }
124
125 req.Header.Set("Content-Type", "text/plain")
126
127 select {
128 case <-x.abort:
129 if cn, ok := x.client.Transport.(requestCanceler); ok {
130 cn.CancelRequest(req)
131 }
132
133 return "", &ErrSession{
134 Type: config.XHRPolling,
135 State: sockjs.SessionClosed,
136 Err: errAborted,
137 }
138 case res := <-x.do(req):
139 if res.Error != nil {
140 return "", fmt.Errorf("Receiving data failed: %s", res.Error)
141 }
142
143 msg, ok, err := x.handleResp(res.Response)
144 if err != nil {
145 return "", err
146 }
147
148 if ok {
149 continue
150 }
151
152 return msg, nil
153 }
154 }
155}
156
157func (x *XHRSession) setState(state sockjs.SessionState) {
158 x.mu.Lock()

Callers 2

receiveDataMethod · 0.45
ReadMethod · 0.45

Calls 6

isClosedMethod · 0.95
doMethod · 0.95
handleRespMethod · 0.95
CancelRequestMethod · 0.80
ErrorMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected