diff options
| author | Russ Cox <rsc@golang.org> | 2009-11-02 18:37:30 -0800 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2009-11-02 18:37:30 -0800 |
| commit | c83b838641649230d3cbb8be83fc4159949c29a2 (patch) | |
| tree | 34addcd47401db47aac916688b90b8be55850c40 /src/pkg/http/server.go | |
| parent | 6e8184d8cd53e76e7f9f9366c06f0441c5b5aa4c (diff) | |
| download | go-c83b838641649230d3cbb8be83fc4159949c29a2.tar.xz | |
package net cleanup
added ReadFrom/WriteTo for packet protocols like UDP.
simplified the net.Conn interface.
added new net.PacketConn interface for packet protocols.
implemented proper UDP listener.
cleaned up LocalAddr/RemoteAddr methods - cache in netFD.
threw away various unused methods.
an interface change:
introduced net.Addr as a network address interface,
to avoid conversion of UDP host:port to string and
back for every ReadFrom/WriteTo sequence.
another interface change:
since signature of Listener.Accept was changing anyway,
dropped the middle return value, because it is available
as c.RemoteAddr(). (the Accept signature predates the
existence of that method.)
Dial and Listen still accept strings, but the proto-specific
versions DialTCP, ListenUDP, etc. take net.Addr instead.
because the generic Dial didn't change and because
no one calls Accept directly (only indirectly via the http
server), very little code will be affected by these interface
changes.
design comments welcome.
R=p
CC=go-dev, r
http://go/go-review/1018017
Diffstat (limited to 'src/pkg/http/server.go')
| -rw-r--r-- | src/pkg/http/server.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/pkg/http/server.go b/src/pkg/http/server.go index fb6b3bd4d8..3aa5c072f5 100644 --- a/src/pkg/http/server.go +++ b/src/pkg/http/server.go @@ -56,9 +56,11 @@ type Conn struct { } // Create new connection from rwc. -func newConn(rwc io.ReadWriteCloser, raddr string, handler Handler) (c *Conn, err os.Error) { +func newConn(rwc net.Conn, handler Handler) (c *Conn, err os.Error) { c = new(Conn); - c.RemoteAddr = raddr; + if a := rwc.RemoteAddr(); a != nil { + c.RemoteAddr = a.String(); + } c.handler = handler; c.rwc = rwc; br := bufio.NewReader(rwc); @@ -527,11 +529,11 @@ func Serve(l net.Listener, handler Handler) os.Error { handler = DefaultServeMux; } for { - rw, raddr, e := l.Accept(); + rw, e := l.Accept(); if e != nil { return e; } - c, err := newConn(rw, raddr, handler); + c, err := newConn(rw, handler); if err != nil { continue; } |
