-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,188 additions
and
92 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
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
84 changes: 84 additions & 0 deletions
84
...commonMain/kotlin/io/rsocket/kotlin/internal/connection/ConnectionEstablishmentHandler.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,84 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.internal.connection | ||
|
||
// TODO: change package to internal.transport? | ||
|
||
// TODO? | ||
//internal abstract class ConnectionEstablishmentHandler { | ||
// abstract suspend fun receiveFrame(): ByteReadPacket | ||
// abstract suspend fun sendFrame(frame: ByteReadPacket) | ||
//} | ||
// | ||
///* | ||
// Client setup: | ||
// 1. configure | ||
// 2. send setup frame (or resume + await resume ok frame) | ||
// 3. done | ||
// | ||
// Server setup: | ||
// 1. await setup frame (or resume) | ||
// 2. configure | ||
// 3. done | send error (or send resume ok frame) | ||
// */ | ||
// | ||
///* | ||
// done means: | ||
// 1. start receiving frames/streams | ||
// 2. create requester | ||
// */ | ||
// | ||
//@RSocketTransportApi | ||
//internal suspend fun RSocketClientTransport.connect( | ||
// isClient: Boolean, | ||
// maxFragmentSize: Int, | ||
// interceptors: Interceptors, | ||
// connectionConfig: ConnectionConfig, | ||
// acceptor: ConnectionAcceptor, | ||
//) { | ||
// suspend fun setup(handler: ConnectionEstablishmentHandler) { | ||
// val setupFrame = SetupFrame( | ||
// version = Version.Current, | ||
// honorLease = false, | ||
// keepAlive = connectionConfig.keepAlive, | ||
// resumeToken = null, | ||
// payloadMimeType = connectionConfig.payloadMimeType, | ||
// payload = connectionConfig.setupPayload.copy() //copy needed, as it can be used in acceptor | ||
// ).toPacket(ChunkBuffer.Pool) | ||
// handler.sendFrame(setupFrame) | ||
// // done | ||
// } | ||
// | ||
// when (val connection = connect()) { | ||
// is RSocketTransportConnection.Multiplexed -> { | ||
// val connectionStream = connection.createStream() | ||
// connectionStream.prioritize() | ||
// | ||
// while (true) { | ||
// val stream = connection.awaitStream() | ||
// launch { | ||
// val firstFrame = stream.receiveFrame() | ||
// } | ||
// } | ||
// } | ||
// | ||
// is RSocketTransportConnection.Sequential -> { | ||
// setup(SequentialConnectionEstablishmentHandler(connection)) | ||
// | ||
// } | ||
// } | ||
//} |
39 changes: 39 additions & 0 deletions
39
...ore/src/commonMain/kotlin/io/rsocket/kotlin/internal/connection/ConnectionFrameHandler.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,39 @@ | ||
/* | ||
* Copyright 2015-2023 the original author or authors. | ||
* | ||
* 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 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.rsocket.kotlin.internal.connection | ||
|
||
import io.rsocket.kotlin.frame.* | ||
|
||
internal class ConnectionFrameHandler( | ||
private val inbound: ConnectionInbound, | ||
) { | ||
suspend fun handleFrame(frame: Frame): Boolean = when (frame) { | ||
is MetadataPushFrame -> inbound.receiveMetadataPush(frame.metadata) | ||
is KeepAliveFrame -> inbound.receiveKeepAlive(frame.respond, frame.data, frame.lastPosition) | ||
is ErrorFrame -> inbound.receiveError(frame.throwable) | ||
is LeaseFrame -> { | ||
frame.close() | ||
TODO("lease is not supported") | ||
} | ||
|
||
else -> { | ||
frame.close() | ||
false // wrong frame | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.