Make async querying work again
This commit is contained in:
parent
cd17a26192
commit
313640276f
11
client.go
11
client.go
|
@ -134,12 +134,14 @@ type Client struct {
|
|||
}
|
||||
|
||||
// NewClient creates a new client, with Net set to "udp" and Attempts to 1.
|
||||
// The client's ReplyChan is set to DefaultReplyChan.
|
||||
// The client's ReplyChan is set to DefaultReplyChan and QueryChan
|
||||
// to DefaultQueryChan.
|
||||
func NewClient() *Client {
|
||||
c := new(Client)
|
||||
c.Net = "udp"
|
||||
c.Attempts = 1
|
||||
c.ReplyChan = DefaultReplyChan
|
||||
c.QueryChan = DefaultQueryChan
|
||||
c.ReadTimeout = 5000
|
||||
c.WriteTimeout = 5000
|
||||
return c
|
||||
|
@ -184,17 +186,18 @@ func ListenAndQuery(request chan *Request, handler QueryHandler) {
|
|||
go q.ListenAndQuery()
|
||||
}
|
||||
|
||||
// Write returns the original question and the answer on the reply channel of the
|
||||
// client.
|
||||
// Write returns the original question and the answer on the
|
||||
// reply channel of the client.
|
||||
func (w *reply) Write(m *Msg) {
|
||||
// Check if nil??
|
||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: m}
|
||||
}
|
||||
|
||||
// Do performs an asynchronous query. The result is returned on the
|
||||
// QueryChan channel set in the Client c.
|
||||
func (c *Client) Do(m *Msg, a string) {
|
||||
println("send")
|
||||
c.QueryChan <- &Request{Client: c, Addr: a, Request: m}
|
||||
println("sent")
|
||||
}
|
||||
|
||||
// ExchangeBuffer performs a synchronous query. It sends the buffer m to the
|
||||
|
|
|
@ -20,6 +20,7 @@ func TestClientSync(t *testing.T) {
|
|||
}
|
||||
|
||||
func helloMiek(w RequestWriter, r *Msg) {
|
||||
println("hello")
|
||||
w.Send(r)
|
||||
reply, _ := w.Receive()
|
||||
w.Write(reply)
|
||||
|
@ -33,12 +34,13 @@ func TestClientASync(t *testing.T) {
|
|||
m.SetQuestion("miek.nl", TypeSOA)
|
||||
|
||||
c := NewClient()
|
||||
println("Do")
|
||||
c.Do(m, "85.223.71.124:53")
|
||||
|
||||
forever:
|
||||
for {
|
||||
select {
|
||||
case n := <-DefaultReplyChan:
|
||||
case n := <-c.ReplyChan:
|
||||
if n.Reply != nil && n.Reply.Rcode != RcodeSuccess {
|
||||
t.Log("Failed to get an valid answer")
|
||||
t.Fail()
|
||||
|
@ -88,14 +90,18 @@ func TestClientTsigAXFR(t *testing.T) {
|
|||
c.Net = "tcp"
|
||||
c.TsigSecret = secrets
|
||||
|
||||
if err := c.XfrReceive(m, "85.223.71.124:53"); err != nil {
|
||||
t.Log("Failed to setup axfr" + err.String())
|
||||
t.Fail()
|
||||
}
|
||||
/*
|
||||
for {
|
||||
// select on c.ReplyChannel
|
||||
// and receive the *Exchange messages
|
||||
}
|
||||
*/
|
||||
if err := c.XfrReceive(m, "85.223.71.124:53"); err != nil {
|
||||
t.Log("Failed to setup axfr" + err.String())
|
||||
t.Fail()
|
||||
}
|
||||
for {
|
||||
ex := <-c.ReplyChan
|
||||
println(ex.Reply.String())
|
||||
}
|
||||
/*
|
||||
for {
|
||||
// select on c.ReplyChannel
|
||||
// and receive the *Exchange messages
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue