mirror of https://github.com/perkeep/perkeep.git
Merge "pkg/webserver: remove usage of the obsolete runsit package"
This commit is contained in:
commit
36f351ff50
4
TODO
4
TODO
|
@ -214,10 +214,6 @@ Offline list:
|
||||||
-- get webdav server working again, for mounting on Windows. This worked before Go 1
|
-- get webdav server working again, for mounting on Windows. This worked before Go 1
|
||||||
but bitrot when we moved pkg/fs to use the rsc/fuse.
|
but bitrot when we moved pkg/fs to use the rsc/fuse.
|
||||||
|
|
||||||
-- work on runsit more, so I can start using this more often. runsit should
|
|
||||||
be able to reload itself, and also watch for binaries changing and restart
|
|
||||||
when binaries change. (or symlinks to binaries)
|
|
||||||
|
|
||||||
-- BUG: osutil paths.go on OS X: should use Library everywhere instead of mix of
|
-- BUG: osutil paths.go on OS X: should use Library everywhere instead of mix of
|
||||||
Library and ~/.camlistore?
|
Library and ~/.camlistore?
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,20 @@
|
||||||
package listen
|
/*
|
||||||
|
Copyright 2017 Google Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package listen // import "camlistore.org/pkg/webserver/listen"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -19,9 +35,8 @@ func NewFlag(flagName, defaultValue string, serverType string) *Addr {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen is a replacement for net.Listen that also respects runsit
|
// Listen is a replacement for net.Listen and supports
|
||||||
// listeners: port, :port, ip:port, FD:<fd_num>, ADDR:<name> or <name>
|
// port, :port, ip:port, FD:<fd_num>, ADDR:<name>
|
||||||
// named ports.
|
|
||||||
// Listeners are always TCP.
|
// Listeners are always TCP.
|
||||||
func Listen(addr string) (net.Listener, error) {
|
func Listen(addr string) (net.Listener, error) {
|
||||||
a := &Addr{s: addr}
|
a := &Addr{s: addr}
|
||||||
|
@ -37,15 +52,15 @@ func Usage(name string) string {
|
||||||
if !strings.HasSuffix(name, " address") {
|
if !strings.HasSuffix(name, " address") {
|
||||||
name += " address"
|
name += " address"
|
||||||
}
|
}
|
||||||
return name + "; may be port, :port, ip:port, FD:<fd_num>, or ADDR:<name> to use named runsit ports"
|
return name + "; may be port, :port, ip:port, FD:<fd_num>, or ADDR:<name> to use named ports"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addr is a flag variable. Use like:
|
// Addr is a flag variable. Use like:
|
||||||
//
|
//
|
||||||
// var webPort listen.Addr
|
// var webPort listen.Addr
|
||||||
// flag.Var(&webPort, "web_addr", listen.Usage("Web server address"))
|
// flag.Var(&webPort, "web_addr", listen.Usage("Web server address"))
|
||||||
// flag.Parse()
|
// flag.Parse()
|
||||||
// webListener, err := webPort.Listen()
|
// webListener, err := webPort.Listen()
|
||||||
type Addr struct {
|
type Addr struct {
|
||||||
s string
|
s string
|
||||||
ln net.Listener
|
ln net.Listener
|
||||||
|
@ -60,15 +75,6 @@ func (a *Addr) String() string {
|
||||||
func (a *Addr) Set(v string) error {
|
func (a *Addr) Set(v string) error {
|
||||||
a.s = v
|
a.s = v
|
||||||
|
|
||||||
// Try the requested port by runsit port name first.
|
|
||||||
fd, ok, err := namedPort(v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if ok {
|
|
||||||
return a.listenOnFD(fd)
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(v, "FD:") {
|
if strings.HasPrefix(v, "FD:") {
|
||||||
fdStr := v[len("FD:"):]
|
fdStr := v[len("FD:"):]
|
||||||
fd, err := strconv.ParseUint(fdStr, 10, 32)
|
fd, err := strconv.ParseUint(fdStr, 10, 32)
|
||||||
|
@ -83,7 +89,7 @@ func (a *Addr) Set(v string) error {
|
||||||
ipPort = ":" + v
|
ipPort = ":" + v
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err = net.SplitHostPort(ipPort)
|
_, _, err := net.SplitHostPort(ipPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid PORT or IP:PORT %q: %v", v, err)
|
return fmt.Errorf("invalid PORT or IP:PORT %q: %v", v, err)
|
||||||
}
|
}
|
||||||
|
@ -97,23 +103,11 @@ func isPort(s string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Addr) listenOnFD(fd uintptr) (err error) {
|
func (a *Addr) listenOnFD(fd uintptr) (err error) {
|
||||||
f := os.NewFile(fd, fmt.Sprintf("fd #%d from runsit parent", fd))
|
f := os.NewFile(fd, fmt.Sprintf("fd #%d from process parent", fd))
|
||||||
a.ln, err = net.FileListener(f)
|
a.ln, err = net.FileListener(f)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func namedPort(name string) (fd uintptr, ok bool, err error) {
|
|
||||||
s := os.Getenv("RUNSIT_PORTFD_" + name)
|
|
||||||
if s == "" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
u64, err := strconv.ParseUint(s, 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return uintptr(u64), true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ flag.Value = (*Addr)(nil)
|
var _ flag.Value = (*Addr)(nil)
|
||||||
|
|
||||||
// Listen returns the address's TCP listener.
|
// Listen returns the address's TCP listener.
|
|
@ -36,7 +36,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bradfitz/runsit/listen"
|
"camlistore.org/pkg/webserver/listen"
|
||||||
|
|
||||||
"go4.org/net/throttle"
|
"go4.org/net/throttle"
|
||||||
"go4.org/wkfs"
|
"go4.org/wkfs"
|
||||||
|
|
Loading…
Reference in New Issue