From 53384ea4a1e162f378f97a0b49f0e09f21c4d3fb Mon Sep 17 00:00:00 2001 From: Amir Abbas Date: Thu, 19 Jul 2018 17:44:15 +0430 Subject: [PATCH] Fixed timeout not triggered, gardening --- AMSMB2.podspec | 2 +- AMSMB2/Context.swift | 26 +++++++++++++------------- AMSMB2/Info.plist | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/AMSMB2.podspec b/AMSMB2.podspec index dc7afb4..80b3833 100644 --- a/AMSMB2.podspec +++ b/AMSMB2.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "AMSMB2" - s.version = "1.4.0" + s.version = "1.5.0" s.summary = "Swift framework to connect SMB2/3 shares" # This description is used to generate tags and improve search results. diff --git a/AMSMB2/Context.swift b/AMSMB2/Context.swift index b4318a2..224cfee 100644 --- a/AMSMB2/Context.swift +++ b/AMSMB2/Context.swift @@ -243,7 +243,7 @@ extension SMB2Context { // MARK: Async operation handler extension SMB2Context { private struct CBData { - var result: Int32 = 0 + var result: Int32 = SMB2_STATUS_SUCCESS var isFinished: Bool = false var commandData: UnsafeMutableRawPointer? = nil @@ -275,14 +275,13 @@ extension SMB2Context { } if pfd.revents == 0 { + if timeout > 0, Date().timeIntervalSince(startDate) > timeout { + throw POSIXError(.ETIMEDOUT) + } continue } try service(revents: Int32(pfd.revents)) - - if timeout > 0, Date().timeIntervalSince(startDate) > timeout { - throw POSIXError(.ETIMEDOUT) - } } } @@ -304,13 +303,13 @@ extension SMB2Context { } try POSIXError.throwIfError(result, description: error, default: .ECONNRESET) try wait_for_reply(cbPtr) - let cbresult = cbPtr.bindMemory(to: CBData.self, capacity: 1).pointee.result - try POSIXError.throwIfError(cbresult, description: error, default: defaultError) + let cbResult = cbPtr.bindMemory(to: CBData.self, capacity: 1).pointee.result + try POSIXError.throwIfError(cbResult, description: error, default: defaultError) let data = cbPtr.bindMemory(to: CBData.self, capacity: 1).pointee.commandData - return (cbresult, data) + return (cbResult, data) } - func async_await_pdu(defaultError: POSIXError.Code, execute handler: (_ context: UnsafeMutablePointer, _ cbPtr: UnsafeMutableRawPointer) -> UnsafeMutablePointer?) throws -> (result: Int32, data: UnsafeMutableRawPointer?) { + func async_await_pdu(defaultError: POSIXError.Code, execute handler: (_ context: UnsafeMutablePointer, _ cbPtr: UnsafeMutableRawPointer) -> UnsafeMutablePointer?) throws -> (result: UInt32, data: UnsafeMutableRawPointer?) { let cbPtr = CBData.initPointer() defer { cbPtr.deallocate() @@ -324,12 +323,13 @@ extension SMB2Context { smb2_queue_pdu(context, pdu) } try wait_for_reply(cbPtr) - let cbresult = cbPtr.bindMemory(to: CBData.self, capacity: 1).pointee.result - if cbresult < 0 { - let errorNo = nterror_to_errno(UInt32(bitPattern: cbresult)) + let cbResult = cbPtr.bindMemory(to: CBData.self, capacity: 1).pointee.result + let result = UInt32(bitPattern: cbResult) + if result & SMB2_STATUS_SEVERITY_ERROR == 0xc0000000 { + let errorNo = nterror_to_errno(result) try POSIXError.throwIfError(-errorNo, description: nil, default: defaultError) } let data = cbPtr.bindMemory(to: CBData.self, capacity: 1).pointee.commandData - return (cbresult, data) + return (result, data) } } diff --git a/AMSMB2/Info.plist b/AMSMB2/Info.plist index 4e57c3d..79efccc 100644 --- a/AMSMB2/Info.plist +++ b/AMSMB2/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.4.0 + 1.5.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass