Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Sources/HttpParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ public class HttpParser {
}

private func extractQueryParams(_ url: String) -> [(String, String)] {
guard let questionMark = url.index(of: "?") else {
#if compiler(>=5.0)
guard let questionMarkIndex = url.firstIndex(of: "?") else {
return []
}
let queryStart = url.index(after: questionMark)
#else
guard let questionMarkIndex = url.index(of: "?") else {
return []
}
#endif
let queryStart = url.index(after: questionMarkIndex)

guard url.endIndex > queryStart else { return [] }

Expand All @@ -48,9 +54,15 @@ public class HttpParser {

return query.components(separatedBy: "&")
.reduce([(String, String)]()) { (c, s) -> [(String, String)] in
#if compiler(>=5.0)
guard let nameEndIndex = s.firstIndex(of: "=") else {
return c
}
#else
guard let nameEndIndex = s.index(of: "=") else {
return c
}
#endif
guard let name = String(s[s.startIndex..<nameEndIndex]).removingPercentEncoding else {
return c
}
Expand Down
13 changes: 12 additions & 1 deletion Sources/Socket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ open class Socket: Hashable, Equatable {
close()
}

public var hashValue: Int { return Int(self.socketFileDescriptor) }
public func hash(into hasher: inout Hasher) {
hasher.combine(self.socketFileDescriptor)
}

public func close() {
if shutdown {
Expand Down Expand Up @@ -91,9 +93,18 @@ open class Socket: Hashable, Equatable {
}

public func writeData(_ data: Data) throws {
#if compiler(>=5.0)
try data.withUnsafeBytes { (body: UnsafeRawBufferPointer) -> Void in
if let baseAddress = body.baseAddress, body.count > 0 {
let pointer = baseAddress.assumingMemoryBound(to: UInt8.self)
try self.writeBuffer(pointer, length: data.count)
}
}
#else
try data.withUnsafeBytes { (pointer: UnsafePointer<UInt8>) -> Void in
try self.writeBuffer(pointer, length: data.count)
}
#endif
}

private func writeBuffer(_ pointer: UnsafeRawPointer, length: Int) throws {
Expand Down
8 changes: 3 additions & 5 deletions Sources/WebSockets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,9 @@ public class WebSocketSession: Hashable, Equatable {
}
return frm
}

public var hashValue: Int {
get {
return socket.hashValue
}

public func hash(into hasher: inout Hasher) {
hasher.combine(socket)
}
}

Expand Down