Documentation
This commit is contained in:
parent
c872bb18c3
commit
fdc0d6924d
24
client.go
24
client.go
|
@ -1,11 +1,6 @@
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
// A concurrent client implementation.
|
// A concurrent client implementation.
|
||||||
// Client sends query to a channel which
|
|
||||||
// will then handle the query. Returned replys
|
|
||||||
// are return on another channel. Ready for handling --- same
|
|
||||||
// setup for server - a HANDLER function that gets run
|
|
||||||
// when the query returns.
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
@ -13,7 +8,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Incoming (documentation just as in os.Signal)
|
|
||||||
type QueryHandler interface {
|
type QueryHandler interface {
|
||||||
QueryDNS(w RequestWriter, q *Msg)
|
QueryDNS(w RequestWriter, q *Msg)
|
||||||
}
|
}
|
||||||
|
@ -88,7 +82,7 @@ var (
|
||||||
// QueryHandler object that calls f.
|
// QueryHandler object that calls f.
|
||||||
type HandlerQueryFunc func(RequestWriter, *Msg)
|
type HandlerQueryFunc func(RequestWriter, *Msg)
|
||||||
|
|
||||||
// QueryDNS calls f(w, reg)
|
// QueryDNS calls f(w, reg).
|
||||||
func (f HandlerQueryFunc) QueryDNS(w RequestWriter, r *Msg) {
|
func (f HandlerQueryFunc) QueryDNS(w RequestWriter, r *Msg) {
|
||||||
go f(w, r)
|
go f(w, r)
|
||||||
}
|
}
|
||||||
|
@ -229,7 +223,13 @@ func (w *reply) Write(m *Msg) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do performs an asynchronous query. The result is returned on the
|
// Do performs an asynchronous query. The result is returned on the
|
||||||
// QueryChan channel set in the Client c.
|
// QueryChan channel set in the *Client c. Basic use pattern for
|
||||||
|
// sending message m to the server listening on port 53 on localhost
|
||||||
|
//
|
||||||
|
// c.Do(m, "127.0.0.1:53") // Sends to c.QueryChan
|
||||||
|
// r := <- DefaultReplyChan // The reply comes back on DefaultReplyChan
|
||||||
|
//
|
||||||
|
// r is of type Exchange.
|
||||||
func (c *Client) Do(m *Msg, a string) {
|
func (c *Client) Do(m *Msg, a string) {
|
||||||
c.QueryChan <- &Request{Client: c, Addr: a, Request: m}
|
c.QueryChan <- &Request{Client: c, Addr: a, Request: m}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +261,13 @@ func (c *Client) exchangeBuffer(inbuf []byte, a string, outbuf []byte) (n int, w
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exchange performs an synchronous query. It sends the message m to the address
|
// Exchange performs an synchronous query. It sends the message m to the address
|
||||||
// contained in a and waits for an reply.
|
// contained in a and waits for an reply. Basic use pattern with a *Client:
|
||||||
|
//
|
||||||
|
// c := NewClient()
|
||||||
|
// in, rtt, addr, err := c.Exchange(m1, "127.0.0.1:53")
|
||||||
|
//
|
||||||
|
// The 'addr' return value is superfluous in this case, but it is here to retain symmetry
|
||||||
|
// with the asynchronous call, see Client.Do().
|
||||||
func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, addr net.Addr, err error) {
|
func (c *Client) Exchange(m *Msg, a string) (r *Msg, rtt time.Duration, addr net.Addr, err error) {
|
||||||
var n int
|
var n int
|
||||||
var w *reply
|
var w *reply
|
||||||
|
|
15
dns.go
15
dns.go
|
@ -66,11 +66,12 @@
|
||||||
// c.Do(m1, "127.0.0.1:53")
|
// c.Do(m1, "127.0.0.1:53")
|
||||||
// // Do something else
|
// // Do something else
|
||||||
// r := <- DefaultReplyChan
|
// r := <- DefaultReplyChan
|
||||||
// // r.Reply is the answer
|
// // r is of type Exchange:
|
||||||
// // r.Request is the original request
|
// // * r.Reply is the answer
|
||||||
// // r.Rtt is the round trip time
|
// // * r.Request is the original request
|
||||||
// // r.RemoteAddr is the net.Addr were the request was sent to
|
// // * r.Rtt is the round trip time
|
||||||
// // r.Error is the error (if any)
|
// // * r.RemoteAddr is the net.Addr were the request was sent to
|
||||||
|
// // * r.Error is the error (if any)
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -121,8 +122,8 @@ type RR interface {
|
||||||
type Exchange struct {
|
type Exchange struct {
|
||||||
Request *Msg // the question sent
|
Request *Msg // the question sent
|
||||||
Reply *Msg // the answer to the question that was sent
|
Reply *Msg // the answer to the question that was sent
|
||||||
Rtt time.Duration // Round trip time
|
Rtt time.Duration // round trip time
|
||||||
RemoteAddr net.Addr // Client address
|
RemoteAddr net.Addr // client address
|
||||||
Error error // if something went wrong, this contains the error
|
Error error // if something went wrong, this contains the error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue