diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-03-30 22:09:55 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-03-30 22:09:55 +0000 |
commit | 9a18821cfc7169ea9f4d0bb661e7c4ea362e993d (patch) | |
tree | 26322d11da7cc220190e0b8430565ea207eb3eab /libgo/go/net | |
parent | 57c7433fdc3fcb7b0cfd7b13bd11360a5e17c624 (diff) | |
download | gcc-9a18821cfc7169ea9f4d0bb661e7c4ea362e993d.zip gcc-9a18821cfc7169ea9f4d0bb661e7c4ea362e993d.tar.gz gcc-9a18821cfc7169ea9f4d0bb661e7c4ea362e993d.tar.bz2 |
libgo: Update to weekly.2012-03-22.
From-SVN: r186026
Diffstat (limited to 'libgo/go/net')
-rw-r--r-- | libgo/go/net/http/triv.go | 53 | ||||
-rw-r--r-- | libgo/go/net/interface_linux.go | 2 | ||||
-rw-r--r-- | libgo/go/net/interface_stub.go | 2 | ||||
-rw-r--r-- | libgo/go/net/interface_windows.go | 2 | ||||
-rw-r--r-- | libgo/go/net/unicast_test.go | 12 |
5 files changed, 31 insertions, 40 deletions
diff --git a/libgo/go/net/http/triv.go b/libgo/go/net/http/triv.go index 269af0c..232d650 100644 --- a/libgo/go/net/http/triv.go +++ b/libgo/go/net/http/triv.go @@ -15,7 +15,9 @@ import ( "log" "net/http" "os" + "os/exec" "strconv" + "sync" ) // hello world, the web server @@ -28,14 +30,21 @@ func HelloServer(w http.ResponseWriter, req *http.Request) { // Simple counter server. POSTing to it will set the value. type Counter struct { - n int + mu sync.Mutex // protects n + n int } // This makes Counter satisfy the expvar.Var interface, so we can export // it directly. -func (ctr *Counter) String() string { return fmt.Sprintf("%d", ctr.n) } +func (ctr *Counter) String() string { + ctr.mu.Lock() + defer ctr.mu.Unlock() + return fmt.Sprintf("%d", ctr.n) +} func (ctr *Counter) ServeHTTP(w http.ResponseWriter, req *http.Request) { + ctr.mu.Lock() + defer ctr.mu.Unlock() switch req.Method { case "GET": ctr.n++ @@ -95,54 +104,36 @@ func (ch Chan) ServeHTTP(w http.ResponseWriter, req *http.Request) { // exec a program, redirecting output func DateServer(rw http.ResponseWriter, req *http.Request) { rw.Header().Set("Content-Type", "text/plain; charset=utf-8") - r, w, err := os.Pipe() - if err != nil { - fmt.Fprintf(rw, "pipe: %s\n", err) - return - } - p, err := os.StartProcess("/bin/date", []string{"date"}, &os.ProcAttr{Files: []*os.File{nil, w, w}}) - defer r.Close() - w.Close() - if err != nil { - fmt.Fprintf(rw, "fork/exec: %s\n", err) - return - } - io.Copy(rw, r) - wait, err := p.Wait(0) + date, err := exec.Command("/bin/date").Output() if err != nil { - fmt.Fprintf(rw, "wait: %s\n", err) - return - } - if !wait.Exited() || wait.ExitStatus() != 0 { - fmt.Fprintf(rw, "date: %v\n", wait) + http.Error(rw, err.Error(), 500) return } + rw.Write(date) } func Logger(w http.ResponseWriter, req *http.Request) { - log.Print(req.URL.Raw) - w.WriteHeader(404) - w.Write([]byte("oops")) + log.Print(req.URL) + http.Error(w, "oops", 404) } -var webroot = flag.String("root", "/home/rsc", "web root directory") +var webroot = flag.String("root", os.Getenv("HOME"), "web root directory") func main() { flag.Parse() // The counter is published as a variable directly. ctr := new(Counter) - http.Handle("/counter", ctr) expvar.Publish("counter", ctr) - + http.Handle("/counter", ctr) http.Handle("/", http.HandlerFunc(Logger)) http.Handle("/go/", http.StripPrefix("/go/", http.FileServer(http.Dir(*webroot)))) - http.Handle("/flags", http.HandlerFunc(FlagServer)) - http.Handle("/args", http.HandlerFunc(ArgServer)) - http.Handle("/go/hello", http.HandlerFunc(HelloServer)) http.Handle("/chan", ChanCreate()) - http.Handle("/date", http.HandlerFunc(DateServer)) + http.HandleFunc("/flags", FlagServer) + http.HandleFunc("/args", ArgServer) + http.HandleFunc("/go/hello", HelloServer) + http.HandleFunc("/date", DateServer) err := http.ListenAndServe(":12345", nil) if err != nil { log.Panicln("ListenAndServe:", err) diff --git a/libgo/go/net/interface_linux.go b/libgo/go/net/interface_linux.go index 8c9c304..825b202 100644 --- a/libgo/go/net/interface_linux.go +++ b/libgo/go/net/interface_linux.go @@ -13,7 +13,7 @@ import ( ) // If the ifindex is zero, interfaceTable returns mappings of all -// network interfaces. Otheriwse it returns a mapping of a specific +// network interfaces. Otherwise it returns a mapping of a specific // interface. func interfaceTable(ifindex int) ([]Interface, error) { tab, err := syscall.NetlinkRIB(syscall.RTM_GETLINK, syscall.AF_UNSPEC) diff --git a/libgo/go/net/interface_stub.go b/libgo/go/net/interface_stub.go index 4876b3a..d4d7ce9 100644 --- a/libgo/go/net/interface_stub.go +++ b/libgo/go/net/interface_stub.go @@ -9,7 +9,7 @@ package net // If the ifindex is zero, interfaceTable returns mappings of all -// network interfaces. Otheriwse it returns a mapping of a specific +// network interfaces. Otherwise it returns a mapping of a specific // interface. func interfaceTable(ifindex int) ([]Interface, error) { return nil, nil diff --git a/libgo/go/net/interface_windows.go b/libgo/go/net/interface_windows.go index d0c9753..4368b33 100644 --- a/libgo/go/net/interface_windows.go +++ b/libgo/go/net/interface_windows.go @@ -56,7 +56,7 @@ func getInterfaceList() ([]syscall.InterfaceInfo, error) { } // If the ifindex is zero, interfaceTable returns mappings of all -// network interfaces. Otheriwse it returns a mapping of a specific +// network interfaces. Otherwise it returns a mapping of a specific // interface. func interfaceTable(ifindex int) ([]Interface, error) { ai, err := getAdapterList() diff --git a/libgo/go/net/unicast_test.go b/libgo/go/net/unicast_test.go index a23bc5a..e5dd013 100644 --- a/libgo/go/net/unicast_test.go +++ b/libgo/go/net/unicast_test.go @@ -5,7 +5,6 @@ package net import ( - "io" "runtime" "syscall" "testing" @@ -67,7 +66,7 @@ func TestTCPListener(t *testing.T) { case syscall.AF_INET6: testIPv6UnicastSocketOptions(t, fd) } - l1.(io.Closer).Close() + l1.Close() } } @@ -112,7 +111,7 @@ func TestUDPListener(t *testing.T) { case syscall.AF_INET6: testIPv6UnicastSocketOptions(t, fd) } - l1.(io.Closer).Close() + l1.Close() } } @@ -134,7 +133,7 @@ func TestSimpleTCPListener(t *testing.T) { checkFirstListener(t, tt.net, tt.laddr+":"+port, l1) l2, err := Listen(tt.net, tt.laddr+":"+port) checkSecondListener(t, tt.net, tt.laddr+":"+port, err, l2) - l1.(io.Closer).Close() + l1.Close() } } @@ -169,7 +168,7 @@ func TestSimpleUDPListener(t *testing.T) { checkFirstListener(t, tt.net, tt.laddr+":"+port, l1) l2, err := ListenPacket(tt.net, tt.laddr+":"+port) checkSecondListener(t, tt.net, tt.laddr+":"+port, err, l2) - l1.(io.Closer).Close() + l1.Close() } } @@ -530,8 +529,9 @@ func TestProhibitionaryDialArgs(t *testing.T) { defer l.Close() for _, tt := range prohibitionaryDialArgTests { - _, err := Dial(tt.net, tt.addr+":"+port) + c, err := Dial(tt.net, tt.addr+":"+port) if err == nil { + c.Close() t.Fatalf("Dial(%q, %q) should fail", tt.net, tt.addr) } } |