"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "server_test.go" between
dns-1.1.45.tar.gz and dns-1.1.46.tar.gz

About: GO DNS implements a DNS library in Go.

server_test.go  (dns-1.1.45):server_test.go  (dns-1.1.46)
skipping to change at line 70 skipping to change at line 70
func AnotherHelloServer(w ResponseWriter, req *Msg) { func AnotherHelloServer(w ResponseWriter, req *Msg) {
m := new(Msg) m := new(Msg)
m.SetReply(req) m.SetReply(req)
m.Extra = make([]RR, 1) m.Extra = make([]RR, 1)
m.Extra[0] = &TXT{Hdr: RR_Header{Name: m.Question[0].Name, Rrtype: TypeTX T, Class: ClassINET, Ttl: 0}, Txt: []string{"Hello example"}} m.Extra[0] = &TXT{Hdr: RR_Header{Name: m.Question[0].Name, Rrtype: TypeTX T, Class: ClassINET, Ttl: 0}, Txt: []string{"Hello example"}}
w.WriteMsg(m) w.WriteMsg(m)
} }
func RunLocalUDPServer(laddr string, opts ...func(*Server)) (*Server, string, ch func RunLocalServer(pc net.PacketConn, l net.Listener, opts ...func(*Server)) (*
an error, error) { Server, string, chan error, error) {
pc, err := net.ListenPacket("udp", laddr) server := &Server{
if err != nil { PacketConn: pc,
return nil, "", nil, err Listener: l,
ReadTimeout: time.Hour,
WriteTimeout: time.Hour,
} }
server := &Server{PacketConn: pc, ReadTimeout: time.Hour, WriteTimeout: t ime.Hour}
waitLock := sync.Mutex{} waitLock := sync.Mutex{}
waitLock.Lock() waitLock.Lock()
server.NotifyStartedFunc = waitLock.Unlock server.NotifyStartedFunc = waitLock.Unlock
for _, opt := range opts { for _, opt := range opts {
opt(server) opt(server)
} }
var (
addr string
closer io.Closer
)
if l != nil {
addr = l.Addr().String()
closer = l
} else {
addr = pc.LocalAddr().String()
closer = pc
}
// fin must be buffered so the goroutine below won't block // fin must be buffered so the goroutine below won't block
// forever if fin is never read from. This always happens // forever if fin is never read from. This always happens
// if the channel is discarded and can happen in TestShutdownUDP. // if the channel is discarded and can happen in TestShutdownUDP.
fin := make(chan error, 1) fin := make(chan error, 1)
go func() { go func() {
fin <- server.ActivateAndServe() fin <- server.ActivateAndServe()
pc.Close() closer.Close()
}() }()
waitLock.Lock() waitLock.Lock()
return server, pc.LocalAddr().String(), fin, nil return server, addr, fin, nil
}
func RunLocalUDPServer(laddr string, opts ...func(*Server)) (*Server, string, ch
an error, error) {
pc, err := net.ListenPacket("udp", laddr)
if err != nil {
return nil, "", nil, err
}
return RunLocalServer(pc, nil, opts...)
} }
func RunLocalPacketConnServer(laddr string, opts ...func(*Server)) (*Server, str ing, chan error, error) { func RunLocalPacketConnServer(laddr string, opts ...func(*Server)) (*Server, str ing, chan error, error) {
return RunLocalUDPServer(laddr, append(opts, func(srv *Server) { return RunLocalUDPServer(laddr, append(opts, func(srv *Server) {
// Make srv.PacketConn opaque to trigger the generic code paths. // Make srv.PacketConn opaque to trigger the generic code paths.
srv.PacketConn = struct{ net.PacketConn }{srv.PacketConn} srv.PacketConn = struct{ net.PacketConn }{srv.PacketConn}
})...) })...)
} }
func RunLocalTCPServer(laddr string, opts ...func(*Server)) (*Server, string, ch an error, error) { func RunLocalTCPServer(laddr string, opts ...func(*Server)) (*Server, string, ch an error, error) {
l, err := net.Listen("tcp", laddr) l, err := net.Listen("tcp", laddr)
if err != nil { if err != nil {
return nil, "", nil, err return nil, "", nil, err
} }
server := &Server{Listener: l, ReadTimeout: time.Hour, WriteTimeout: time return RunLocalServer(nil, l, opts...)
.Hour}
waitLock := sync.Mutex{}
waitLock.Lock()
server.NotifyStartedFunc = waitLock.Unlock
for _, opt := range opts {
opt(server)
}
// See the comment in RunLocalUDPServer as to why fin must be buffered.
fin := make(chan error, 1)
go func() {
fin <- server.ActivateAndServe()
l.Close()
}()
waitLock.Lock()
return server, l.Addr().String(), fin, nil
} }
func RunLocalTLSServer(laddr string, config *tls.Config) (*Server, string, chan error, error) { func RunLocalTLSServer(laddr string, config *tls.Config) (*Server, string, chan error, error) {
return RunLocalTCPServer(laddr, func(srv *Server) { return RunLocalTCPServer(laddr, func(srv *Server) {
srv.Listener = tls.NewListener(srv.Listener, config) srv.Listener = tls.NewListener(srv.Listener, config)
}) })
} }
func RunLocalUnixServer(laddr string, opts ...func(*Server)) (*Server, string, c
han error, error) {
l, err := net.Listen("unix", laddr)
if err != nil {
return nil, "", nil, err
}
return RunLocalServer(nil, l, opts...)
}
func RunLocalUnixGramServer(laddr string, opts ...func(*Server)) (*Server, strin
g, chan error, error) {
pc, err := net.ListenPacket("unixgram", laddr)
if err != nil {
return nil, "", nil, err
}
return RunLocalServer(pc, nil, opts...)
}
func TestServing(t *testing.T) { func TestServing(t *testing.T) {
for _, tc := range []struct { for _, tc := range []struct {
name string name string
network string network string
runServer func(laddr string, opts ...func(*Server)) (*Server, str ing, chan error, error) runServer func(laddr string, opts ...func(*Server)) (*Server, str ing, chan error, error)
}{ }{
{"udp", "udp", RunLocalUDPServer}, {"udp", "udp", RunLocalUDPServer},
{"tcp", "tcp", RunLocalTCPServer}, {"tcp", "tcp", RunLocalTCPServer},
{"PacketConn", "udp", RunLocalPacketConnServer}, {"PacketConn", "udp", RunLocalPacketConnServer},
} { } {
 End of changes. 7 change blocks. 
29 lines changed or deleted 53 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)