|
@@ -31,6 +31,7 @@ import (
|
|
|
"sync"
|
|
|
"time"
|
|
|
"runtime/debug"
|
|
|
+ "sync/atomic"
|
|
|
)
|
|
|
|
|
|
const SavePos = "\x1b[s" // Save Cursor Position
|
|
@@ -82,7 +83,7 @@ type Door struct {
|
|
|
Config DropfileConfig
|
|
|
READFD int
|
|
|
WRITEFD int
|
|
|
- Disconnected bool // Has User disconnected/Hung up?
|
|
|
+ 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
|
|
@@ -103,6 +104,10 @@ func (d *Door) TimeUsed() time.Duration {
|
|
|
return time.Since(d.StartTime)
|
|
|
}
|
|
|
|
|
|
+func (d *Door) Disconnect() bool {
|
|
|
+ return atomic.LoadInt32(&d.Disconnected) != 0
|
|
|
+}
|
|
|
+
|
|
|
// Read the BBS door file. We only support door32.sys.
|
|
|
func (d *Door) ReadDropfile(filename string) {
|
|
|
file, err := os.Open(filename)
|
|
@@ -269,9 +274,9 @@ func (d *Door) Init(doorname string) {
|
|
|
log.Printf("Loading dropfile %s\n", dropfile)
|
|
|
log.Printf("BBS %s, User %s / Handle %s / File %d\n", d.Config.BBSID, d.Config.Real_name, d.Config.Handle, d.Config.Comm_handle)
|
|
|
|
|
|
- d.readerChannel = make(chan byte)
|
|
|
+ d.readerChannel = make(chan byte, 8)
|
|
|
d.writerChannel = make(chan string)
|
|
|
- d.closeChannel = make(chan bool,5)
|
|
|
+ d.closeChannel = make(chan bool, 2) // reader & door.Close
|
|
|
|
|
|
d.setupChannels()
|
|
|
|
|
@@ -294,11 +299,21 @@ func (d *Door) Close() {
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- log.Printf("Closing...")
|
|
|
+ log.Println("Closing...")
|
|
|
d.closeChannel <- true
|
|
|
+ if ! d.Disconnect() {
|
|
|
+ // log.Println("close write channel")
|
|
|
+ // close(d.writerChannel)
|
|
|
+ log.Println("close read handle")
|
|
|
+ CloseReader(d.Config.Comm_handle)
|
|
|
+ log.Println("closed read handle")
|
|
|
+ }
|
|
|
+
|
|
|
+ // d.closeChannel <- true
|
|
|
// close(d.closeChannel)
|
|
|
+ log.Println("wg.Wait()")
|
|
|
d.wg.Wait()
|
|
|
- log.Printf("Closed.")
|
|
|
+ log.Println("Closed.")
|
|
|
}
|
|
|
|
|
|
// Goto X, Y - Position the cursor using ANSI Escape Codes
|