replace zxq.co/ripple/hanayo
This commit is contained in:
1
vendor/github.com/rcrowley/goagain/example/double/.gitignore
generated
vendored
Normal file
1
vendor/github.com/rcrowley/goagain/example/double/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
double
|
105
vendor/github.com/rcrowley/goagain/example/double/main.go
generated
vendored
Normal file
105
vendor/github.com/rcrowley/goagain/example/double/main.go
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rcrowley/goagain"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
goagain.Strategy = goagain.Double
|
||||
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||
log.SetPrefix(fmt.Sprintf("pid:%d ", syscall.Getpid()))
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Inherit a net.Listener from our parent process or listen anew.
|
||||
ch := make(chan struct{})
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
l, err := goagain.Listener()
|
||||
if nil != err {
|
||||
|
||||
// Listen on a TCP or a UNIX domain socket (TCP here).
|
||||
l, err = net.Listen("tcp", "127.0.0.1:48879")
|
||||
if nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Println("listening on", l.Addr())
|
||||
|
||||
// Accept connections in a new goroutine.
|
||||
go serve(l, ch, wg)
|
||||
|
||||
} else {
|
||||
|
||||
// Resume listening and accepting connections in a new goroutine.
|
||||
log.Println("resuming listening on", l.Addr())
|
||||
go serve(l, ch, wg)
|
||||
|
||||
// If this is the child, send the parent SIGUSR2. If this is the
|
||||
// parent, send the child SIGQUIT.
|
||||
if err := goagain.Kill(); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Block the main goroutine awaiting signals.
|
||||
sig, err := goagain.Wait(l)
|
||||
if nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Do whatever's necessary to ensure a graceful exit like waiting for
|
||||
// goroutines to terminate or a channel to become closed.
|
||||
//
|
||||
// In this case, we'll close the channel to signal the goroutine to stop
|
||||
// accepting connections and wait for the goroutine to exit.
|
||||
close(ch)
|
||||
wg.Wait()
|
||||
|
||||
// If we received SIGUSR2, re-exec the parent process.
|
||||
if goagain.SIGUSR2 == sig {
|
||||
if err := goagain.Exec(l); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// A very rude server that says hello and then closes your connection.
|
||||
func serve(l net.Listener, ch chan struct{}, wg *sync.WaitGroup) {
|
||||
defer wg.Done()
|
||||
for {
|
||||
|
||||
// Break out of the accept loop on the next iteration after the
|
||||
// process was signaled and our channel was closed.
|
||||
select {
|
||||
case <-ch:
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
// Set a deadline so Accept doesn't block forever, which gives
|
||||
// us an opportunity to stop gracefully.
|
||||
l.(*net.TCPListener).SetDeadline(time.Now().Add(100e6))
|
||||
|
||||
c, err := l.Accept()
|
||||
if nil != err {
|
||||
if goagain.IsErrClosing(err) {
|
||||
return
|
||||
}
|
||||
if err.(*net.OpError).Timeout() {
|
||||
continue
|
||||
}
|
||||
log.Fatalln(err)
|
||||
}
|
||||
c.Write([]byte("Hello, world!\n"))
|
||||
c.Close()
|
||||
}
|
||||
}
|
1
vendor/github.com/rcrowley/goagain/example/legacy/.gitignore
generated
vendored
Normal file
1
vendor/github.com/rcrowley/goagain/example/legacy/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
legacy
|
75
vendor/github.com/rcrowley/goagain/example/legacy/main.go
generated
vendored
Normal file
75
vendor/github.com/rcrowley/goagain/example/legacy/main.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rcrowley/goagain"
|
||||
"log"
|
||||
"net"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||
log.SetPrefix(fmt.Sprintf("pid:%d ", syscall.Getpid()))
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Get the listener and ppid from the environment. If this is successful,
|
||||
// this process is a child that's inheriting and open listener from ppid.
|
||||
l, ppid, err := goagain.GetEnvs()
|
||||
if nil != err {
|
||||
|
||||
// Listen on a TCP or a UNIX domain socket (TCP here).
|
||||
l, err = net.Listen("tcp", "127.0.0.1:48879")
|
||||
if nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Println("listening on", l.Addr())
|
||||
|
||||
// Accept connections in a new goroutine.
|
||||
go serve(l)
|
||||
|
||||
} else {
|
||||
|
||||
// Resume listening and accepting connections in a new goroutine.
|
||||
log.Println("resuming listening on", l.Addr())
|
||||
go serve(l)
|
||||
|
||||
// Kill the parent, now that the child has started successfully.
|
||||
if err := goagain.KillParent(ppid); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Block the main goroutine awaiting signals.
|
||||
if err := goagain.AwaitSignals(l); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Do whatever's necessary to ensure a graceful exit like waiting for
|
||||
// goroutines to terminate or a channel to become closed.
|
||||
|
||||
// In this case, we'll simply stop listening and wait one second.
|
||||
if err := l.Close(); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
time.Sleep(1e9)
|
||||
|
||||
}
|
||||
|
||||
func serve(l net.Listener) {
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if nil != err {
|
||||
if goagain.IsErrClosing(err) {
|
||||
break
|
||||
}
|
||||
log.Fatalln(err)
|
||||
}
|
||||
c.Write([]byte("Hello, world!\n"))
|
||||
c.Close()
|
||||
}
|
||||
}
|
1
vendor/github.com/rcrowley/goagain/example/sendto/.gitignore
generated
vendored
Normal file
1
vendor/github.com/rcrowley/goagain/example/sendto/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
sendto
|
1
vendor/github.com/rcrowley/goagain/example/single/.gitignore
generated
vendored
Normal file
1
vendor/github.com/rcrowley/goagain/example/single/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
single
|
75
vendor/github.com/rcrowley/goagain/example/single/main.go
generated
vendored
Normal file
75
vendor/github.com/rcrowley/goagain/example/single/main.go
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rcrowley/goagain"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetFlags(log.Lmicroseconds | log.Lshortfile)
|
||||
log.SetPrefix(fmt.Sprintf("pid:%d ", syscall.Getpid()))
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// Inherit a net.Listener from our parent process or listen anew.
|
||||
l, err := goagain.Listener()
|
||||
if nil != err {
|
||||
|
||||
// Listen on a TCP or a UNIX domain socket (TCP here).
|
||||
l, err = net.Listen("tcp", "127.0.0.1:48879")
|
||||
if nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
log.Println("listening on", l.Addr())
|
||||
|
||||
// Accept connections in a new goroutine.
|
||||
go serve(l)
|
||||
|
||||
} else {
|
||||
|
||||
// Resume accepting connections in a new goroutine.
|
||||
log.Println("resuming listening on", l.Addr())
|
||||
go serve(l)
|
||||
|
||||
// Kill the parent, now that the child has started successfully.
|
||||
if err := goagain.Kill(); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Block the main goroutine awaiting signals.
|
||||
if _, err := goagain.Wait(l); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// Do whatever's necessary to ensure a graceful exit like waiting for
|
||||
// goroutines to terminate or a channel to become closed.
|
||||
//
|
||||
// In this case, we'll simply stop listening and wait one second.
|
||||
if err := l.Close(); nil != err {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
time.Sleep(1e9)
|
||||
|
||||
}
|
||||
|
||||
// A very rude server that says hello and then closes your connection.
|
||||
func serve(l net.Listener) {
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if nil != err {
|
||||
if goagain.IsErrClosing(err) {
|
||||
break
|
||||
}
|
||||
log.Fatalln(err)
|
||||
}
|
||||
c.Write([]byte("Hello, world!\n"))
|
||||
c.Close()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user