commit f61c5d1ead3eb9551b87d014dd175948ed27caba
Author: David Fifield <[email protected]>
Date:   Sun Nov 11 20:14:46 2012 -0800

    Use the official sync.WaitGroup to wait for read loops to finish.
---
 websocket-transport/websocket-client.go |   14 +++++++-------
 1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/websocket-transport/websocket-client.go 
b/websocket-transport/websocket-client.go
index 7205517..7e483f6 100644
--- a/websocket-transport/websocket-client.go
+++ b/websocket-transport/websocket-client.go
@@ -9,6 +9,7 @@ import (
        "net/url"
        "os"
        "os/signal"
+       "sync"
        "time"
 )
 
@@ -24,7 +25,9 @@ func logDebug(format string, v ...interface{}) {
 }
 
 func proxy(local *net.TCPConn, ws *websocket.Conn) {
-       finishedChan := make(chan int)
+       var wg sync.WaitGroup
+
+       wg.Add(2)
 
        // Local-to-WebSocket read loop.
        go func() {
@@ -50,7 +53,7 @@ func proxy(local *net.TCPConn, ws *websocket.Conn) {
                local.CloseRead()
                ws.Close()
 
-               finishedChan <- 1
+               wg.Done()
        }()
 
        // WebSocket-to-local read loop.
@@ -79,13 +82,10 @@ func proxy(local *net.TCPConn, ws *websocket.Conn) {
                local.CloseWrite()
                ws.Close()
 
-               finishedChan <- 1
+               wg.Done()
        }()
 
-       // Wait for both read loops to finish.
-       for i := 0; i < 2; i++ {
-               <-finishedChan
-       }
+       wg.Wait()
 }
 
 func handleConnection(conn *net.TCPConn) error {



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to