Explorar o código

Update Socket.swift

Young Jae Sim %!s(int64=10) %!d(string=hai) anos
pai
achega
06189458e0
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      Sources/Swifter/Socket.swift

+ 6 - 2
Sources/Swifter/Socket.swift

@@ -119,7 +119,11 @@ public class Socket : Hashable {
         try data.withUnsafeBufferPointer { pointer in
             var sent = 0
             while sent < data.count {
-                let s = write(self.socketFileDescriptor, pointer.baseAddress + sent, Int(data.count - sent))
+                #if os(Linux)
+                    let s = send(self.socketFileDescriptor, pointer.baseAddress + sent, Int(data.count - sent), Int32(MSG_NOSIGNAL))
+                #else
+                    let s = write(self.socketFileDescriptor, pointer.baseAddress + sent, Int(data.count - sent))
+                #endif
                 if s <= 0 {
                     throw SocketError.WriteFailed(Socket.descriptionOfLastError())
                 }
@@ -210,4 +214,4 @@ public class Socket : Hashable {
 
 public func ==(socket1: Socket, socket2: Socket) -> Bool {
     return socket1.hashValue == socket2.hashValue
-}
+}