Add send(ByteArray)

This commit is contained in:
Him188 2020-01-30 20:02:28 +08:00
parent b3e9d553aa
commit d6d1f2c74d
3 changed files with 21 additions and 0 deletions

View File

@ -34,6 +34,14 @@ actual class PlatformSocket : Closeable {
@PublishedApi
internal lateinit var readChannel: ByteReadChannel
actual suspend inline fun send(packet: ByteArray, offset: Int, length: Int) {
try {
writeChannel.writeFully(packet, offset, length)
} catch (e: Exception) {
throw SendPacketInternalException(e)
}
}
/**
* @throws SendPacketInternalException
*/

View File

@ -12,6 +12,11 @@ import net.mamoe.mirai.utils.MiraiInternalAPI
expect class PlatformSocket() : Closeable {
suspend fun connect(serverHost: String, serverPort: Int)
/**
* @throws SendPacketInternalException
*/
suspend inline fun send(packet: ByteArray, offset: Int = 0, length: Int = packet.size - offset)
/**
* @throws SendPacketInternalException
*/

View File

@ -34,6 +34,14 @@ actual class PlatformSocket : Closeable {
@PublishedApi
internal lateinit var readChannel: ByteReadChannel
actual suspend inline fun send(packet: ByteArray, offset: Int, length: Int) {
try {
writeChannel.writeFully(packet, offset, length)
} catch (e: Exception) {
throw SendPacketInternalException(e)
}
}
/**
* @throws SendPacketInternalException
*/