Procházet zdrojové kódy

Use notification channel (chan struct{}) for close.

Steve Thielemann před 2 roky
rodič
revize
2ce7453b2c
3 změnil soubory, kde provedl 22 přidání a 21 odebrání
  1. 18 17
      door/door.go
  2. 2 2
      door/input_linux.go
  3. 2 2
      door/input_windows.go

+ 18 - 17
door/door.go

@@ -41,12 +41,13 @@ const Clrscr = "\x1b[0m\x1b[2J\x1b[H" // Clear screen, home cursor
 const HideCursor = "\x1b[?25l"        // Hide Cursor
 const ShowCursor = "\x1b[?25h"        // Show Cursor
 var Reset string = Color(0)           // ANSI Color Reset
-var Unicode bool                      // Unicode support detected
-var CP437 bool                        // CP437 support detected
-var Full_CP437 bool                   // Full CP437 support detected (handles control codes properly)
-var Height int                        // Screen height detected
-var Width int                         // Screen width detected
-var Inactivity int64 = 120            // Inactivity timeout
+
+var Unicode bool           // Unicode support detected
+var CP437 bool             // CP437 support detected
+var Full_CP437 bool        // Full CP437 support detected (handles control codes properly)
+var Height int             // Screen height detected
+var Width int              // Screen width detected
+var Inactivity int64 = 120 // Inactivity timeout
 
 type MouseInfo struct {
 	Button int
@@ -91,15 +92,15 @@ type Door struct {
 	Config         DropfileConfig
 	READFD         int
 	WRITEFD        int
-	Disconnected   int32     // atomic bool      // Has User disconnected/Hung up?
-	TimeOut        time.Time // Fixed point in time, when time expires
-	StartTime      time.Time // Time when User started door
-	Pushback       FIFOBuffer
-	LastColor      []int       // Track the last color sent for restore color
-	readerChannel  chan byte   // Reading from the User
-	ReaderCanClose bool        // We can close the reader (in tests)
-	writerChannel  chan string // Writing to the User
-	closeChannel   chan bool   // Closing
+	Disconnected   int32         // atomic bool      // Has User disconnected/Hung up?
+	TimeOut        time.Time     // Fixed point in time, when time expires
+	StartTime      time.Time     // Time when User started door
+	Pushback       FIFOBuffer    // Key buffer
+	LastColor      []int         // Track the last color sent for restore color
+	readerChannel  chan byte     // Reading from the User
+	ReaderCanClose bool          // We can close the reader (in tests)
+	writerChannel  chan string   // Writing to the User
+	closeChannel   chan struct{} // Closing
 	wg             sync.WaitGroup
 }
 
@@ -290,7 +291,7 @@ func (d *Door) Init(doorname string) {
 
 	d.readerChannel = make(chan byte, 8)
 	d.writerChannel = make(chan string)
-	d.closeChannel = make(chan bool, 2) // reader & door.Close
+	d.closeChannel = make(chan struct{}, 2) // reader & door.Close
 
 	d.setupChannels()
 
@@ -314,7 +315,7 @@ func (d *Door) Close() {
 	}()
 
 	log.Println("Closing...")
-	d.closeChannel <- true
+	d.closeChannel <- struct{}{}
 
 	// CloseReader(d.Config.Comm_handle)
 

+ 2 - 2
door/input_linux.go

@@ -33,7 +33,7 @@ func Reader(handle int, d *Door) {
 				log.Println("Reader close writerChannel")
 				// d.Disconnected = true
 				atomic.StoreInt32(&d.Disconnected, 1)
-				d.closeChannel <- true
+				d.closeChannel <- struct{}{}
 				// close(d.writerChannel)
 				return
 			}
@@ -49,7 +49,7 @@ func Reader(handle int, d *Door) {
 				log.Println("Reader close writerChannel")
 				// d.Disconnected = true
 				atomic.StoreInt32(&d.Disconnected, 1)
-				d.closeChannel <- true
+				d.closeChannel <- struct{}{}
 				//close(d.writerChannel)
 				return
 			}

+ 2 - 2
door/input_windows.go

@@ -36,7 +36,7 @@ func Reader(d *Door) {
 			if !d.Disconnect() {
 				log.Println("Reader close writerChannel")
 				atomic.StoreInt32(&d.Disconnected, 1)
-				d.closeChannel <- true
+				d.closeChannel <- struct{}{}
 				return
 			}
 			break
@@ -50,7 +50,7 @@ func Reader(d *Door) {
 			if !d.Disconnect() {
 				log.Println("Reader close writerChannel")
 				atomic.StoreInt32(&d.Disconnected, 1)
-				d.closeChannel <- true
+				d.closeChannel <- struct{}{}
 				return
 			}
 			return