Add a simple query

This commit is contained in:
Miek Gieben 2011-03-29 09:02:51 +02:00
parent 12196e35ac
commit 5130184443
1 changed files with 17 additions and 0 deletions

View File

@ -81,6 +81,23 @@ func QueryDefault(d *Conn, m *Msg, q chan Query) {
return
}
// Simple query function that waits for and returns the reply.
func QuerySimple(d *Conn, m *Msg) (*Msg, os.Error) {
buf, ok := m.Pack()
if !ok {
return nil, ErrPack
}
ret, err := d.Exchange(buf, false)
if err != nil {
return nil, err
}
o := new(Msg)
if ok := o.Unpack(ret); !ok {
return nil, ErrUnpack
}
return o, nil
}
// QueryAndServeTCP listens for incoming requests on channel in and
// then calls QueryTCP with f to the handle the request.
// It returns a channel on which the response is returned.