Open swankjesse opened 2 years ago
I've been hoping okio would have some socket like interface for a while. Would make things like OkHttp/Wire working multiplatform possible. Possible implementations, 1) Socket, 2) TLS Socket, ...
Could you gain anything by expressing this problem with an Okio socket like interface?
Yep, I think that’s appropriate. Particularly for Kotlin/Native, where we don’t yet have a multiplatform socket.
I’m experimenting using
okio.Buffer
withSocketChannel
.One challenge is
SocketChannel
doesn’t offer APIs that fit Okio:I can accomplish my goals by creating a temporary
ByteBuffer
, then copying its results into an Okio Buffer with these existing functions from theByteChannel
supertype:But copying an extra time sucks, let’s not do that!
A better alternative is @bnorm’s awesome ByteChannelSink sample, which uses
ByteBuffer.wrap()
.I’d like to get something like that into Okio, as extension functions on the appropriate NIO channel types:
Cache ByteBuffer instances?
Should we cache result of
ByteBuffer.wrap()
as a field onSegment
? It has the potential to be a frequent allocation, though it’s also one that the VM should be able to escape-analysis away. Looking at JOL, we could add aByteBuffer
field without immediately harming the size ofSegment
.For now I’d like to start by not caching, especially since doing so would require
Segment
to be split into JVM and non-JVM declarations.