Adopted the standard withCString for C strings throughout the library.
This commit is contained in:
@@ -33,7 +33,7 @@ extension Network {
|
||||
/// Opens a connection to `server`. Fails if access has not been
|
||||
/// granted.
|
||||
public init?(server: String, port: Int = 443, useSSL: Bool = true) {
|
||||
let pointer = server.withPlaydateCString {
|
||||
let pointer = server.withCString {
|
||||
httpAPI.pointee.newConnection.unsafelyUnwrapped($0, Int32(port), useSSL)
|
||||
}
|
||||
guard let pointer else { return nil }
|
||||
@@ -84,8 +84,8 @@ extension Network {
|
||||
/// Sends a GET request for `path`. `headers` are raw header lines
|
||||
/// (e.g. "Accept: text/html\r\n").
|
||||
public func get(path: String, headers: String = "") throws(NetError) {
|
||||
let error = path.withPlaydateCString { cPath in
|
||||
headers.withPlaydateCString { cHeaders in
|
||||
let error = path.withCString { cPath in
|
||||
headers.withCString { cHeaders in
|
||||
httpAPI.pointee.get.unsafelyUnwrapped(pointer, cPath, cHeaders, headers.utf8.count)
|
||||
}
|
||||
}
|
||||
@@ -94,8 +94,8 @@ extension Network {
|
||||
|
||||
/// Sends a POST request for `path` with the given body.
|
||||
public func post(path: String, headers: String = "", body: [UInt8]) throws(NetError) {
|
||||
let error = path.withPlaydateCString { cPath in
|
||||
headers.withPlaydateCString { cHeaders in
|
||||
let error = path.withCString { cPath in
|
||||
headers.withCString { cHeaders in
|
||||
body.withUnsafeBytes { bodyBuffer in
|
||||
httpAPI.pointee.post.unsafelyUnwrapped(
|
||||
pointer, cPath, cHeaders, headers.utf8.count,
|
||||
@@ -110,9 +110,9 @@ extension Network {
|
||||
/// Sends a request with an arbitrary HTTP method.
|
||||
public func query(method: String, path: String, headers: String = "",
|
||||
body: [UInt8] = []) throws(NetError) {
|
||||
let error = method.withPlaydateCString { cMethod in
|
||||
path.withPlaydateCString { cPath in
|
||||
headers.withPlaydateCString { cHeaders in
|
||||
let error = method.withCString { cMethod in
|
||||
path.withCString { cPath in
|
||||
headers.withCString { cHeaders in
|
||||
body.withUnsafeBytes { bodyBuffer in
|
||||
httpAPI.pointee.query.unsafelyUnwrapped(
|
||||
pointer, cMethod, cPath, cHeaders, headers.utf8.count,
|
||||
|
||||
@@ -30,7 +30,7 @@ extension Network {
|
||||
/// Creates a connection to `server`. Fails if access has not been
|
||||
/// granted. Call `open(_:)` to connect.
|
||||
public init?(server: String, port: Int, useSSL: Bool = true) {
|
||||
let pointer = server.withPlaydateCString {
|
||||
let pointer = server.withCString {
|
||||
tcpAPI.pointee.newConnection.unsafelyUnwrapped($0, Int32(port), useSSL)
|
||||
}
|
||||
guard let pointer else { return nil }
|
||||
|
||||
Reference in New Issue
Block a user