0001 /* 0002 The MIT License (MIT) 0003 0004 Copyright (c) 2015 Shun Takebayashi 0005 0006 Permission is hereby granted, free of charge, to any person obtaining a copy 0007 of this software and associated documentation files (the "Software"), to deal 0008 in the Software without restriction, including without limitation the rights 0009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0010 copies of the Software, and to permit persons to whom the Software is 0011 furnished to do so, subject to the following conditions: 0012 0013 The above copyright notice and this permission notice shall be included in all 0014 copies or substantial portions of the Software. 0015 0016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0022 SOFTWARE. 0023 */ 0024 0025 #if os(OSX) 0026 import Darwin 0027 #elseif os(Linux) 0028 import Glibc 0029 #endif 0030 0031 enum WriterError: ErrorType { 0032 case GenericError
HTTPResponseWriter.swift:54 throw WriterError.GenericError(error: errno)(error: Int32) 0033 } 0034 0035 public class HTTPResponseWriter
HTTPResponseWriter.swift:54 throw WriterError.GenericError(error: errno)HTTPServer.swift:70 catch let WriterError.GenericError(error: no) {{ 0036 0037 let socket
HTTPServer.swift:31 public typealias HTTPHandler = (HTTPRequest, HTTPResponseWriter) throws -> ()HTTPServer.swift:64 let writer = HTTPResponseWriter(socket: client): Int32 0038 0039 init
HTTPResponseWriter.swift:40 self.socket = socketHTTPResponseWriter.swift:52 let sent = send(socket, bytes, rest, flags)(socket: Int32) { 0040 self.socket = socket 0041 } 0042 0043 public func write(bytes: UnsafePointer<Int8>) throws { 0044 #if os(Linux) 0045 let flags = Int32(MSG_NOSIGNAL) 0046 #else 0047 let flags = Int32(0) 0048 #endif 0049 0050 var rest = Int(strlen(bytes)) 0051 while rest > 0 { 0052 let sent = send(socket, bytes, rest, flags) 0053 if sent < 0 { 0054 throw WriterError.GenericError(error: errno) 0055 } 0056 rest -= sent 0057 } 0058 } 0059 0060 } 0061
HTTPServer.swift:64 let writer = HTTPResponseWriter(socket: client)