-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iOS SocketTransport implementation (#542)
This is rather crude, but it seems to work. Protocol and Transport are blocking APIs; in Android (and Java generally) that's okay, but Apple strongly pushes you towards async networking in iOS. So strongly in fact that all high-level APIs that are not yet deprecated are async-only, including Network.framework. This framework is also the only non-deprecated game in town when it comes to TLS. In order to bridge the gap between Network.framework and our blocking APIs, this PR makes extensive use of dispatch semaphores - essentially, we block the calling thread until a completion handler signals the semaphore. In the next major version of Thrifty, we should see about making the core APIs suspend, with blocking shims for migration. In that version, we can drop this charade and just use ktor or something. Until that glorious day, we get NwSocket.
- Loading branch information
1 parent
436e7f2
commit 188faba
Showing
9 changed files
with
749 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
thrifty-runtime/src/commonMain/kotlin/com/microsoft/thrifty/transport/SocketTransport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Thrifty | ||
* | ||
* Copyright (c) Microsoft Corporation | ||
* | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the License); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
* WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, | ||
* FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. | ||
* | ||
* See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. | ||
*/ | ||
package com.microsoft.thrifty.transport | ||
|
||
expect class SocketTransport internal constructor( | ||
builder: Builder | ||
) : Transport { | ||
class Builder(host: String, port: Int) { | ||
/** | ||
* The number of milliseconds to wait for a connection to be established. | ||
*/ | ||
fun connectTimeout(connectTimeout: Int): Builder | ||
|
||
/** | ||
* The number of milliseconds a read operation should wait for completion. | ||
*/ | ||
fun readTimeout(readTimeout: Int): Builder | ||
|
||
/** | ||
* Enable TLS for this connection. | ||
*/ | ||
fun enableTls(enableTls: Boolean): Builder | ||
|
||
fun build(): SocketTransport | ||
} | ||
|
||
@Throws(okio.IOException::class) | ||
fun connect() | ||
} |
Oops, something went wrong.