Add a ExchangeConn
This commit is contained in:
parent
c8f880217f
commit
0dc922a99b
15
client.go
15
client.go
|
@ -40,9 +40,7 @@ type Client struct {
|
|||
// in, rtt, err := c.Exchange(message, "127.0.0.1:53")
|
||||
//
|
||||
func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err error) {
|
||||
w := new(reply)
|
||||
w.client = c
|
||||
w.addr = a
|
||||
w := &reply{client: c, addr: a}
|
||||
if err = w.dial(); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
@ -54,6 +52,17 @@ func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
|
|||
return r, w.rtt, err
|
||||
}
|
||||
|
||||
// ExchangeConn performs an synchronous query. It sends the message m trough the
|
||||
// connection c and waits for a reply.
|
||||
func (c *Client) ExchangeConn(m *Msg, c net.Conn) (r *Msg, rtt time.Duration, err error) {
|
||||
w := &reply{client: c, addr: a.RemoteAddr()}
|
||||
if err = w.send(m); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
r, err = w.receive()
|
||||
return r, w.rtt, err
|
||||
}
|
||||
|
||||
func (w *reply) RemoteAddr() net.Addr {
|
||||
if w.conn != nil {
|
||||
return w.conn.RemoteAddr()
|
||||
|
|
Loading…
Reference in New Issue