فهرست منبع

Added ticker closer to smbfs

Toby Chui 3 سال پیش
والد
کامیت
c6aa923ee4
1فایلهای تغییر یافته به همراه22 افزوده شده و 19 حذف شده
  1. 22 19
      mod/filesystem/abstractions/smbfs/smbfs.go

+ 22 - 19
mod/filesystem/abstractions/smbfs/smbfs.go

@@ -24,15 +24,16 @@ import (
 */
 
 type ServerMessageBlockFileSystemAbstraction struct {
-	UUID      string
-	Hierarchy string
-	root      string
-	ipaddr    string
-	user      string
-	pass      string
-	conn      *net.Conn
-	session   *smb2.Session
-	share     *smb2.Share
+	UUID       string
+	Hierarchy  string
+	root       string
+	ipaddr     string
+	user       string
+	pass       string
+	conn       *net.Conn
+	session    *smb2.Session
+	share      *smb2.Share
+	tickerChan chan bool
 }
 
 func NewServerMessageBlockFileSystemAbstraction(uuid string, hierarchy string, ipaddr string, rootShare string, username string, password string) (ServerMessageBlockFileSystemAbstraction, error) {
@@ -64,21 +65,22 @@ func NewServerMessageBlockFileSystemAbstraction(uuid string, hierarchy string, i
 		return ServerMessageBlockFileSystemAbstraction{}, err
 	}
 
+	done := make(chan bool)
 	fsAbstraction := ServerMessageBlockFileSystemAbstraction{
-		UUID:      uuid,
-		Hierarchy: hierarchy,
-		root:      rootShare,
-		ipaddr:    ipaddr,
-		user:      username,
-		pass:      password,
-		conn:      &conn,
-		session:   s,
-		share:     fs,
+		UUID:       uuid,
+		Hierarchy:  hierarchy,
+		root:       rootShare,
+		ipaddr:     ipaddr,
+		user:       username,
+		pass:       password,
+		conn:       &conn,
+		session:    s,
+		share:      fs,
+		tickerChan: done,
 	}
 
 	//Create a ticker to check for renewing conncetion once an hour
 	ticker := time.NewTicker(1 * time.Hour)
-	done := make(chan bool)
 	go func(s *ServerMessageBlockFileSystemAbstraction) {
 		for {
 			select {
@@ -176,6 +178,7 @@ func (a ServerMessageBlockFileSystemAbstraction) Stat(filename string) (os.FileI
 	return a.share.Stat(filename)
 }
 func (a ServerMessageBlockFileSystemAbstraction) Close() error {
+	a.tickerChan <- true
 	a.share.Umount()
 	a.session.Logoff()
 	conn := *(a.conn)