[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [flashproxy/master] Use a simpler means of waiting for read loops to end.
commit fd2f3d523bf5a6f20fdfbb9fe7ed8b91bc7f906d
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Sun Nov 11 19:39:28 2012 -0800
Use a simpler means of waiting for read loops to end.
---
websocket-transport/websocket-client.go | 20 ++++++--------------
1 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/websocket-transport/websocket-client.go b/websocket-transport/websocket-client.go
index 6cce020..fcb9767 100644
--- a/websocket-transport/websocket-client.go
+++ b/websocket-transport/websocket-client.go
@@ -23,11 +23,9 @@ func logDebug(format string, v ...interface{}) {
}
func proxy(local *net.TCPConn, ws *websocket.Conn) {
- var localToWs chan bool
- var wsToLocal chan bool
+ finishedChan := make(chan int)
// Local-to-WebSocket read loop.
- localToWs = make(chan bool, 1)
go func() {
buf := make([]byte, bufSiz)
var err error
@@ -51,11 +49,10 @@ func proxy(local *net.TCPConn, ws *websocket.Conn) {
local.CloseRead()
ws.Close()
- localToWs <- true
+ finishedChan <- 1
}()
// WebSocket-to-local read loop.
- wsToLocal = make(chan bool, 1)
go func() {
var buf []byte
var err error
@@ -81,17 +78,12 @@ func proxy(local *net.TCPConn, ws *websocket.Conn) {
local.CloseWrite()
ws.Close()
- wsToLocal <- true
+ finishedChan <- 1
}()
- // Select twice, once for each read loop.
- select {
- case <-localToWs:
- case <-wsToLocal:
- }
- select {
- case <-localToWs:
- case <-wsToLocal:
+ // Wait for both read loops to finish.
+ for i := 0; i < 2; i++ {
+ <-finishedChan
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits