[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [goptlib/master] pt-spec no longer mentions SIGINT.



commit 50915b3ba5ee27c0b2fcdad9edd51156fb55192c
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sun Sep 25 18:33:10 2016 -0700

    pt-spec no longer mentions SIGINT.
---
 examples/dummy-client/dummy-client.go | 22 ++++++++--------------
 examples/dummy-server/dummy-server.go | 22 ++++++++--------------
 pt.go                                 |  2 +-
 3 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/examples/dummy-client/dummy-client.go b/examples/dummy-client/dummy-client.go
index 74843fd..a15189c 100644
--- a/examples/dummy-client/dummy-client.go
+++ b/examples/dummy-client/dummy-client.go
@@ -114,9 +114,9 @@ func main() {
 	var numHandlers int = 0
 	var sig os.Signal
 	sigChan := make(chan os.Signal, 1)
-	signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+	signal.Notify(sigChan, syscall.SIGTERM)
 
-	// wait for first signal
+	// keep track of handlers and wait for a signal
 	sig = nil
 	for sig == nil {
 		select {
@@ -125,21 +125,15 @@ func main() {
 		case sig = <-sigChan:
 		}
 	}
+
+	// signal received, shut down
 	for _, ln := range listeners {
 		ln.Close()
 	}
-
-	if sig == syscall.SIGTERM {
-		return
-	}
-
-	// wait for second signal or no more handlers
-	sig = nil
-	for sig == nil && numHandlers != 0 {
-		select {
-		case n := <-handlerChan:
-			numHandlers += n
-		case sig = <-sigChan:
+	for n := range handlerChan {
+		numHandlers += n
+		if numHandlers == 0 {
+			break
 		}
 	}
 }
diff --git a/examples/dummy-server/dummy-server.go b/examples/dummy-server/dummy-server.go
index 933630b..c31c63f 100644
--- a/examples/dummy-server/dummy-server.go
+++ b/examples/dummy-server/dummy-server.go
@@ -106,9 +106,9 @@ func main() {
 	var numHandlers int = 0
 	var sig os.Signal
 	sigChan := make(chan os.Signal, 1)
-	signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+	signal.Notify(sigChan, syscall.SIGTERM)
 
-	// wait for first signal
+	// keep track of handlers and wait for a signal
 	sig = nil
 	for sig == nil {
 		select {
@@ -117,21 +117,15 @@ func main() {
 		case sig = <-sigChan:
 		}
 	}
+
+	// signal received, shut down
 	for _, ln := range listeners {
 		ln.Close()
 	}
-
-	if sig == syscall.SIGTERM {
-		return
-	}
-
-	// wait for second signal or no more handlers
-	sig = nil
-	for sig == nil && numHandlers != 0 {
-		select {
-		case n := <-handlerChan:
-			numHandlers += n
-		case sig = <-sigChan:
+	for n := range handlerChan {
+		numHandlers += n
+		if numHandlers == 0 {
+			break
 		}
 	}
 }
diff --git a/pt.go b/pt.go
index 82c42d5..20917a4 100644
--- a/pt.go
+++ b/pt.go
@@ -113,7 +113,7 @@
 // 		pt.SmethodsDone()
 // 	}
 //
-// Some additional care is needed to handle SIGINT and shutdown properly. See
+// Some additional care is needed to handle signals and shutdown properly. See
 // the example programs dummy-client and dummy-server.
 //
 // Tor pluggable transports specification:

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits