wait blocks until the penging response is received, filling out with the response data.
(out interface{})
| 164 | // wait blocks until the penging response is received, filling out with the |
| 165 | // response data. |
| 166 | func (p *pending) wait(out interface{}) error { |
| 167 | select { |
| 168 | case reply := <-p.p: |
| 169 | if reply.err != ErrNone { |
| 170 | dbg("<%v> recv err: %+v", p.id, reply.err) |
| 171 | return reply.err |
| 172 | } |
| 173 | if out == nil { |
| 174 | return nil |
| 175 | } |
| 176 | r := bytes.NewReader(reply.data) |
| 177 | d := endian.Reader(r, device.BigEndian) |
| 178 | if err := p.c.decode(d, reflect.ValueOf(out)); err != nil { |
| 179 | return err |
| 180 | } |
| 181 | dbg("<%v> recv: %+v", p.id, out) |
| 182 | if offset, _ := r.Seek(0, 1); offset != int64(len(reply.data)) { |
| 183 | panic(fmt.Errorf("Only %d/%d bytes read from reply packet", offset, len(reply.data))) |
| 184 | } |
| 185 | return nil |
| 186 | case <-time.After(time.Second * 120): |
| 187 | return fmt.Errorf("timeout") |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func (c *Connection) newReplyHandler() (packetID, <-chan replyPacket) { |
| 192 | reply := make(chan replyPacket, 1) |