scoop:scoop.http:0.1.0
src/native/common.scoop
Selected production source · src/native/common.scoop
1
package scoop.http3
@CLayout4
internal struct NativeHttpStep(val count: Long, val code: Int)6
@CLayout7
internal struct NativeHttpBytes(val data: Ptr<Byte>?, val size: Long)9
@CLayout10
internal struct NativeHttpField(11
val name: Ptr<Byte>?,12
val nameSize: Long,13
val value: Ptr<Byte>?,14
val valueSize: Long,15
val neverIndex: Int16
)18
@CLayout19
internal struct NativeHttpEventInfo(20
val kind: Int,21
val version: Int,22
val streamId: Int,23
val status: Int,24
val flags: UInt,25
val code: Int,26
val amount: Long27
)29
@Unsafe30
internal fun httpBytes(view: NativeHttpBytes): Array<Byte> =31
Array<Byte>(view.size) {32
index -> @Unsafe33
{34
return@Array view.data!!.load(index)35
}36
}38
@Unsafe39
internal fun httpEventFields(event: ULong): Array<HttpField> =40
Array<HttpField>(httpEventFieldCount(event)) {41
index -> @Unsafe42
{43
val field = httpEventField(event, index)44
return@Array HttpField(45
httpBytes(NativeHttpBytes(field.name, field.nameSize)),46
httpBytes(NativeHttpBytes(field.value, field.valueSize)),47
field.neverIndex != 048
)49
}50
}52
@Unsafe53
internal fun httpEventVersion(info: NativeHttpEventInfo): HttpVersion =54
when (info.version) {55
case 10 -> HttpVersion.Http1056
case 11 -> HttpVersion.Http1157
case 20 -> HttpVersion.Http258
else -> throw IllegalStateException(Some("invalid native HTTP version"))59
}61
@Extern(name = "scoop_http_event_info")62
internal fun httpEventInfo(handle: ULong): NativeHttpEventInfo64
@Extern(name = "scoop_http_event_bytes")65
internal fun httpEventBytes(handle: ULong, index: Int): NativeHttpBytes67
@Extern(name = "scoop_http_event_field_count")68
internal fun httpEventFieldCount(handle: ULong): Long70
@Extern(name = "scoop_http_event_field")71
internal fun httpEventField(handle: ULong, index: Long): NativeHttpField73
@Extern(name = "scoop_http_event_free")74
internal fun httpEventFree(handle: ULong)76
@Extern(name = "scoop_http1_new")77
internal fun http1New(server: Int, config: NativeHttp1Config): ULong79
@Extern(name = "scoop_http1_free")80
internal fun http1Free(handle: ULong)82
@Extern(name = "scoop_http1_expect")83
internal fun http1Expect(handle: ULong, name: Ptr<Byte>, size: Long): Int85
@Extern(name = "scoop_http1_receive")86
internal fun http1Receive(handle: ULong, data: Ptr<Byte>, size: Long): NativeHttpStep88
@GCLeaf89
@Extern(name = "scoop_http1_started_messages")90
internal fun http1StartedMessages(handle: ULong): Long92
@Extern(name = "scoop_http1_end")93
internal fun http1End(handle: ULong): Int95
@GCLeaf96
@Extern(name = "scoop_http1_is_unexpected_eof")97
internal fun http1IsUnexpectedEof(code: Int): Int99
@Extern(name = "scoop_http1_resume")100
internal fun http1Resume(handle: ULong): Int102
@GCLeaf103
@Extern(name = "scoop_http1_switched")104
internal fun http1Switched(handle: ULong): Int106
@Extern(name = "scoop_http1_error")107
internal fun http1Error(handle: ULong): Ptr<Byte>