Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NSInputStream.source() and BufferedSource.inputStream() functions for Apple's NSInputStream #1123

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e0548f2
NSInputStream.source() and BufferedSource.inputStream(): NSInputStream
jeffdgr8 Jun 21, 2022
5578fd8
Set streamError and return -1 on read failure
jeffdgr8 Jun 21, 2022
b95de57
Implement NSInputStream.getBuffer()
jeffdgr8 Jun 21, 2022
ddb66c3
convert() native types
jeffdgr8 Jun 21, 2022
a6c3e16
Test NSInputStream.close()
jeffdgr8 Jun 21, 2022
7a8c292
Additional test assertions
jeffdgr8 Jun 22, 2022
b8d1ba9
appleTest TestUtil
jeffdgr8 Jun 22, 2022
c319152
Add doc comments
jeffdgr8 Jun 22, 2022
506fa4f
Resolve checks
jeffdgr8 Jun 22, 2022
aa0b6d3
Avoid data copy & read source to buffer
jeffdgr8 Jun 25, 2022
9ac4e4d
Resolve checks
jeffdgr8 Jun 27, 2022
7e9cbfa
Merge branch 'master' into nsinputstream
jeffdgr8 Jul 22, 2022
72efc44
Override open() as no-op
jeffdgr8 Jul 22, 2022
0f74ac7
Rename variable to avoid ambiguity
jeffdgr8 Jul 22, 2022
3191c97
Move private functions in class
jeffdgr8 Jul 22, 2022
031a3a1
Code review feedback
jeffdgr8 Jul 25, 2022
3571012
Replace additional RealBufferedSource.commonExhausted() logic
jeffdgr8 Jul 25, 2022
41c38a5
Remove variable
jeffdgr8 Jul 25, 2022
c59ea79
Keep buffer pinned for getBuffer() caller
jeffdgr8 Jul 25, 2022
fb883f9
null pinnedBuffer after unpin()
jeffdgr8 Jul 25, 2022
e554a72
Merge branch 'master' into nsinputstream
jeffdgr8 Jul 27, 2022
f917c2e
Merge remote-tracking branch 'upstream/master' into nsinputstream
jeffdgr8 Mar 1, 2023
a40e1c7
Fix lint errors
jeffdgr8 Mar 1, 2023
97192bb
Merge remote-tracking branch 'upstream/master' into nsinputstream
jeffdgr8 Aug 9, 2023
bbddc69
Add NSOutputStream extensions
jeffdgr8 Aug 10, 2023
8b3fe7e
Fix from https://github.com/Kotlin/kotlinx-io/issues/215
jeffdgr8 Aug 24, 2023
f5d63c0
Remove comment
jeffdgr8 Aug 24, 2023
4b7600f
Merge branch 'master' into nsinputstream
jeffdgr8 Oct 1, 2024
089f548
Merge branch 'master' into nsinputstream
jeffdgr8 Jan 4, 2025
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
Prev Previous commit
Next Next commit
Move private functions in class
  • Loading branch information
jeffdgr8 committed Jul 22, 2022
commit 3191c976eb4032780b7689bb69b34fce294e0b69
49 changes: 24 additions & 25 deletions okio/src/appleMain/kotlin/okio/BufferedSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ private class BufferedSourceInputStream(

private var error: NSError? = null

private fun Exception.toNSError(): NSError {
return NSError(
"Kotlin",
0,
mapOf(
NSLocalizedDescriptionKey to message,
NSUnderlyingErrorKey to this
)
)
}

override fun streamError(): NSError? = error

override fun open() {
Expand Down Expand Up @@ -104,23 +93,33 @@ private class BufferedSourceInputStream(
override fun close() = bufferedSource.close()

override fun description(): String = "$bufferedSource.inputStream()"
}

@OptIn(UnsafeNumber::class)
internal fun Buffer.readNative(sink: CPointer<uint8_tVar>?, maxLength: Int): Int {
val s = head ?: return 0
val toCopy = minOf(maxLength, s.limit - s.pos)
s.data.usePinned {
memcpy(sink, it.addressOf(s.pos), toCopy.convert())
private fun Exception.toNSError(): NSError {
return NSError(
"Kotlin",
0,
mapOf(
NSLocalizedDescriptionKey to message,
NSUnderlyingErrorKey to this
)
)
}

s.pos += toCopy
size -= toCopy.toLong()
private fun Buffer.readNative(sink: CPointer<uint8_tVar>?, maxLength: Int): Int {
val s = head ?: return 0
val toCopy = minOf(maxLength, s.limit - s.pos)
s.data.usePinned {
memcpy(sink, it.addressOf(s.pos), toCopy.convert())
}

if (s.pos == s.limit) {
head = s.pop()
SegmentPool.recycle(s)
}
s.pos += toCopy
size -= toCopy.toLong()

return toCopy
if (s.pos == s.limit) {
head = s.pop()
SegmentPool.recycle(s)
}

return toCopy
}
}