Ver Fonte

Fixed all problems caused by Beta3 upgrade.

Damian Kołakowski há 12 anos atrás
pai
commit
c76d5ce350
3 ficheiros alterados com 9 adições e 9 exclusões
  1. 1 1
      Swifter/AppDelegate.swift
  2. 2 4
      Swifter/HttpParser.swift
  3. 6 4
      Swifter/Socket.swift

+ 1 - 1
Swifter/AppDelegate.swift

@@ -33,7 +33,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
         }
         server["/long"] = { (method, headers) in
             var longResponse = ""
-            for k in 0..1000 { longResponse += "(\(k)),->" }
+            for k in 0..<1000 { longResponse += "(\(k)),->" }
             return .OK(.RAW(longResponse))
         }
         server["/"] = { (method, headers) in

+ 2 - 4
Swifter/HttpParser.swift

@@ -51,7 +51,7 @@ class HttpParser {
         return nil
     }
 
-    var recvBuffer: UInt8[] = UInt8[](count: 1024, repeatedValue: 0)
+    var recvBuffer: [UInt8] = [UInt8](count: 1024, repeatedValue: 0)
     var recvBufferSize: Int = 0
     var recvBufferOffset: Int = 0
     
@@ -71,9 +71,7 @@ class HttpParser {
         var n = 0
         do {
             n = nextUInt8(socket)
-            if ( n > 13 /* CR */ ) {
-                characters += Character(UnicodeScalar(n))
-            }
+            if ( n > 13 /* CR */ ) { characters += Character(UnicodeScalar(n)) }
         } while ( n > 0 && n != 10 /* NL */ );
         if ( n == -1 ) {
             if error { error.memory = Socket.socketLastError("recv(...) failed.") }

+ 6 - 4
Swifter/Socket.swift

@@ -12,9 +12,11 @@ import Foundation
 struct Socket {
     
     static func socketLastError(reason:String) -> NSError {
-        let code = errno
-        return NSError.errorWithDomain("SOCKET", code: Int(code), userInfo:
-            [NSLocalizedFailureReasonErrorKey : reason, NSLocalizedDescriptionKey : String.fromCString(strerror(code))])
+        let errorCode = errno
+        if let errorText = String.fromCString(CString(strerror(errorCode))) {
+            return NSError.errorWithDomain("SOCKET", code: Int(errorCode), userInfo: [NSLocalizedFailureReasonErrorKey : reason, NSLocalizedDescriptionKey : errorText])
+        }
+        return NSError.errorWithDomain("SOCKET", code: Int(errorCode), userInfo: nil)
     }
     
     static func tcpForListen(port: in_port_t = 8080, error:NSErrorPointer = nil) -> CInt? {
@@ -52,7 +54,7 @@ struct Socket {
     static func writeStringUTF8(socket: CInt, string: String, error:NSErrorPointer = nil) -> Bool {
         var sent = 0;
         let nsdata = string.bridgeToObjectiveC().dataUsingEncoding(NSUTF8StringEncoding)
-        let unsafePointer = UnsafePointer<UInt8>(nsdata.bytes)
+        let unsafePointer = ConstUnsafePointer<UInt8>(nsdata.bytes)
         while ( sent < nsdata.length ) {
             let s = write(socket, unsafePointer + sent, UInt(nsdata.length - sent))
             if ( s <= 0 ) {