Skip to content

Commit 0460957

Browse files
committed
libssh2 init
1 parent f03eea9 commit 0460957

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/SSH.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public class SSH {
106106
self.debug = debug
107107
self.blocking = blocking
108108
self.keepalive = keepalive
109-
libssh2_init(0)
110109
}
111110

112111
/// 关闭 SSH 会话和 Socket 连接。
@@ -155,15 +154,16 @@ public class SSH {
155154
libssh2_session_disconnect_ex(rawSession, SSH_DISCONNECT_BY_APPLICATION, "SSH Term: Disconnect", "")
156155
}
157156
libssh2_session_free(rawSession)
157+
libssh2_exit()
158158
shutdown(.w)
159159
close(.socket)
160160
self.rawSession = nil
161161
}
162162
}
163163
}
164164

165-
/// 析构函数,‌用于清理资源。‌
165+
166166
deinit {
167-
libssh2_exit()
167+
168168
}
169169
}

src/Session.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public extension SSH {
8686
}
8787
SSH.getSSH(from: sess)?.trace(message: message, messageLen: messageLen)
8888
}
89-
89+
90+
libssh2_init(0)
9091
rawSession = libssh2_session_init_ex(nil, nil, nil, Unmanaged.passUnretained(self).toOpaque())
9192

9293
_ = methods.map { (key: SSHMethod, value: String) in

0 commit comments

Comments
 (0)