0001    // TCPError.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 TCPError
TCPClientSocket.swift:52
        try TCPError.assertNoSendErrorWithData(data, bytesProcessed: bytesProcessed)
TCPClientSocket.swift:62
        try TCPError.assertNoError()
TCPClientSocket.swift:73
        try TCPError.assertNoReceiveErrorWithData(data, bytesProcessed: bytesProcessed)
TCPClientSocket.swift:81
            throw TCPError.Unknown(description: "Marks should be > 0")
TCPClientSocket.swift:85
            throw TCPError.Unknown(description: "loweWaterMark should be less than highWaterMark")
TCPClientSocket.swift:93
        try TCPError.assertNoReceiveErrorWithData(data, bytesProcessed: bytesProcessed)
TCPClientSocket.swift:105
        try TCPError.assertNoReceiveErrorWithData(data, bytesProcessed: bytesProcessed)
TCPError.swift:36
    static func lastReceiveErrorWithData(source: Data, bytesProcessed: Int) -> TCPError {
TCPError.swift:41
    static func lastSendErrorWithData(source: Data, bytesProcessed: Int) -> TCPError {
TCPError.swift:46
    static func lastErrorWithData(data: Data) -> TCPError {
TCPError.swift:65
    static var lastError: TCPError {
TCPError.swift:81
        return TCPError.ClosedSocket(description: "Closed socket")
TCPError.swift:80
    static var closedSocketError: TCPError {
TCPError.swift:86
            throw TCPError.lastError
TCPError.swift:92
            throw TCPError.lastReceiveErrorWithData(data, bytesProcessed: bytesProcessed)
TCPError.swift:98
            throw TCPError.lastSendErrorWithData(data, bytesProcessed: bytesProcessed)
TCPError.swift:103
extension TCPError: CustomStringConvertible {
TCPSocket.swift:37
        try TCPError.assertNoError()
TCPSocket.swift:52
        try TCPError.assertNoError()
TCPSocket.swift:74
            throw TCPError.closedSocketError
: ErrorType { 0029 case Unknown
TCPClientSocket.swift:81
            throw TCPError.Unknown(description: "Marks should be > 0")
TCPClientSocket.swift:85
            throw TCPError.Unknown(description: "loweWaterMark should be less than highWaterMark")
TCPError.swift:76
            return .Unknown(description: lastErrorDescription)
TCPError.swift:106
        case Unknown(let description):
(description: String) 0030 case BrokenPipe(description: String, data: Data) 0031 case ConnectionResetByPeer(description: String, data: Data) 0032 case NoBufferSpaceAvailabe(description: String, data: Data) 0033 case OperationTimedOut(description: String, data: Data) 0034 case ClosedSocket
TCPError.swift:81
        return TCPError.ClosedSocket(description: "Closed socket")
TCPError.swift:116
        case ClosedSocket(let description):
(description: String) 0035 0036 static func lastReceiveErrorWithData(source: Data, bytesProcessed: Int) -> TCPError { 0037 let data = source.prefix(bytesProcessed) 0038 return lastErrorWithData(data) 0039 } 0040 0041 static func lastSendErrorWithData(source: Data, bytesProcessed: Int) -> TCPError { 0042 let data = source.suffix(bytesProcessed) 0043 return lastErrorWithData(data) 0044 } 0045 0046 static func lastErrorWithData(data: Data) -> TCPError { 0047 switch errno { 0048 case EPIPE: 0049 return .BrokenPipe(description: lastErrorDescription, data: data) 0050 case ECONNRESET: 0051 return .ConnectionResetByPeer(description: lastErrorDescription, data: data) 0052 case ENOBUFS: 0053 return .NoBufferSpaceAvailabe(description: lastErrorDescription, data: data) 0054 case ETIMEDOUT: 0055 return .OperationTimedOut(description: lastErrorDescription, data: data) 0056 default: 0057 return .Unknown(description: lastErrorDescription) 0058 } 0059 } 0060 0061 static var lastErrorDescription
TCPError.swift:76
            return .Unknown(description: lastErrorDescription)
: String { 0062 return String.fromCString(strerror(errno))! 0063 } 0064 0065 static var lastError
TCPError.swift:86
            throw TCPError.lastError
: TCPError { 0066 switch errno { 0067 case EPIPE: 0068 return .BrokenPipe(description: lastErrorDescription, data: nil) 0069 case ECONNRESET: 0070 return .ConnectionResetByPeer(description: lastErrorDescription, data: nil) 0071 case ENOBUFS: 0072 return .NoBufferSpaceAvailabe(description: lastErrorDescription, data: nil) 0073 case ETIMEDOUT: 0074 return .OperationTimedOut(description: lastErrorDescription, data: nil) 0075 default: 0076 return .Unknown(description: lastErrorDescription) 0077 } 0078 } 0079 0080 static var closedSocketError
TCPSocket.swift:74
            throw TCPError.closedSocketError
: TCPError { 0081 return TCPError.ClosedSocket(description: "Closed socket") 0082 } 0083 0084 static func assertNoError
TCPClientSocket.swift:62
        try TCPError.assertNoError()
TCPSocket.swift:37
        try TCPError.assertNoError()
TCPSocket.swift:52
        try TCPError.assertNoError()
() throws { 0085 if errno != 0 { 0086 throw TCPError.lastError 0087 } 0088 } 0089 0090 static func assertNoReceiveErrorWithData(data: Data, bytesProcessed: Int) throws { 0091 if errno != 0 { 0092 throw TCPError.lastReceiveErrorWithData(data, bytesProcessed: bytesProcessed) 0093 } 0094 } 0095 0096 static func assertNoSendErrorWithData(data: Data, bytesProcessed: Int) throws { 0097 if errno != 0 { 0098 throw TCPError.lastSendErrorWithData(data, bytesProcessed: bytesProcessed) 0099 } 0100 } 0101 } 0102 0103 extension TCPError: CustomStringConvertible { 0104 public var description: String { 0105 switch self { 0106 case Unknown(let description): 0107 return description 0108 case .BrokenPipe(let description, _): 0109 return description 0110 case ConnectionResetByPeer(let description, _): 0111 return description 0112 case NoBufferSpaceAvailabe(let description, _): 0113 return description 0114 case OperationTimedOut(let description, _): 0115 return description 0116 case ClosedSocket(let description): 0117 return description 0118 } 0119 } 0120 }