0001 // UDPError.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 @_exported import System 0026 @_exported import Data 0027 0028 public enum UDPError: ErrorType { 0029 case Unknown
UDP.swift:39 try UDPError.assertNoError()UDP.swift:63 try UDPError.assertNoError()UDP.swift:76 try UDPError.assertNoReceiveErrorWithData(data, bytesProcessed: bytesProcessed)UDP.swift:89 try UDPError.assertNoError()UDP.swift:107 throw UDPError.closedSocketErrorUDPError.swift:35 static func lastReceiveErrorWithData(source: Data, bytesProcessed: Int) -> UDPError {UDPError.swift:40 static func lastErrorWithData(data: Data) -> UDPError {UDPError.swift:57 static var lastError: UDPError {UDPError.swift:63 return UDPError.ClosedSocket(description: "Closed socket")UDPError.swift:62 static var closedSocketError: UDPError {UDPError.swift:68 throw UDPError.lastErrorUDPError.swift:74 throw UDPError.lastReceiveErrorWithData(data, bytesProcessed: bytesProcessed)UDPError.swift:79 extension UDPError: CustomStringConvertible {(description: String) 0030 case ConnectionResetByPeer(description: String, data: Data) 0031 case NoBufferSpaceAvailabe(description: String, data: Data) 0032 case OperationTimedOut(description: String, data: Data) 0033 case ClosedSocket
UDPError.swift:59 return .Unknown(description: lastErrorDescription)UDPError.swift:82 case Unknown(let description):(description: String) 0034 0035 static func lastReceiveErrorWithData(source: Data, bytesProcessed: Int) -> UDPError { 0036 let data = source.prefix(bytesProcessed) 0037 return lastErrorWithData(data) 0038 } 0039 0040 static func lastErrorWithData(data: Data) -> UDPError { 0041 switch errno { 0042 case ECONNRESET: 0043 return .ConnectionResetByPeer(description: lastErrorDescription, data: data) 0044 case ENOBUFS: 0045 return .NoBufferSpaceAvailabe(description: lastErrorDescription, data: data) 0046 case ETIMEDOUT: 0047 return .OperationTimedOut(description: lastErrorDescription, data: data) 0048 default: 0049 return .Unknown(description: lastErrorDescription) 0050 } 0051 } 0052 0053 static var lastErrorDescription
UDPError.swift:63 return UDPError.ClosedSocket(description: "Closed socket")UDPError.swift:90 case ClosedSocket(let description):: String { 0054 return String.fromCString(strerror(errno))! 0055 } 0056 0057 static var lastError
UDPError.swift:59 return .Unknown(description: lastErrorDescription): UDPError { 0058 // TODO: Switch on errno 0059 return .Unknown(description: lastErrorDescription) 0060 } 0061 0062 static var closedSocketError
UDPError.swift:68 throw UDPError.lastError: UDPError { 0063 return UDPError.ClosedSocket(description: "Closed socket") 0064 } 0065 0066 static func assertNoError
UDP.swift:107 throw UDPError.closedSocketError() throws { 0067 if errno != 0 { 0068 throw UDPError.lastError 0069 } 0070 } 0071 0072 static func assertNoReceiveErrorWithData(data: Data, bytesProcessed: Int) throws { 0073 if errno != 0 { 0074 throw UDPError.lastReceiveErrorWithData(data, bytesProcessed: bytesProcessed) 0075 } 0076 } 0077 } 0078 0079 extension UDPError: CustomStringConvertible { 0080 public var description: String { 0081 switch self { 0082 case Unknown(let description): 0083 return description 0084 case ConnectionResetByPeer(let description, _): 0085 return description 0086 case NoBufferSpaceAvailabe(let description, _): 0087 return description 0088 case OperationTimedOut(let description, _): 0089 return description 0090 case ClosedSocket(let description): 0091 return description 0092 } 0093 } 0094 }
UDP.swift:39 try UDPError.assertNoError()UDP.swift:63 try UDPError.assertNoError()UDP.swift:89 try UDPError.assertNoError()