Scoop API

scoop:scoop.http:0.1.0

src/native/common.scoop

Selected production source · src/native/common.scoop

1package scoop.http
3@CLayout
4internal struct NativeHttpStep(val count: Long, val code: Int)
6@CLayout
7internal struct NativeHttpBytes(val data: Ptr<Byte>?, val size: Long)
9@CLayout
10internal struct NativeHttpField(
11 val name: Ptr<Byte>?,
12 val nameSize: Long,
13 val value: Ptr<Byte>?,
14 val valueSize: Long,
15 val neverIndex: Int
18@CLayout
19internal 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: Long
29@Unsafe
30internal fun httpBytes(view: NativeHttpBytes): Array<Byte> =
31 Array<Byte>(view.size) {
32 index -> @Unsafe
33 {
34 return@Array view.data!!.load(index)
35 }
36 }
38@Unsafe
39internal fun httpEventFields(event: ULong): Array<HttpField> =
40 Array<HttpField>(httpEventFieldCount(event)) {
41 index -> @Unsafe
42 {
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 != 0
48 )
49 }
50 }
52@Unsafe
53internal fun httpEventVersion(info: NativeHttpEventInfo): HttpVersion =
54 when (info.version) {
55 case 10 -> HttpVersion.Http10
56 case 11 -> HttpVersion.Http11
57 case 20 -> HttpVersion.Http2
58 else -> throw IllegalStateException(Some("invalid native HTTP version"))
59 }
61@Extern(name = "scoop_http_event_info")
62internal fun httpEventInfo(handle: ULong): NativeHttpEventInfo
64@Extern(name = "scoop_http_event_bytes")
65internal fun httpEventBytes(handle: ULong, index: Int): NativeHttpBytes
67@Extern(name = "scoop_http_event_field_count")
68internal fun httpEventFieldCount(handle: ULong): Long
70@Extern(name = "scoop_http_event_field")
71internal fun httpEventField(handle: ULong, index: Long): NativeHttpField
73@Extern(name = "scoop_http_event_free")
74internal fun httpEventFree(handle: ULong)
76@Extern(name = "scoop_http1_new")
77internal fun http1New(server: Int, config: NativeHttp1Config): ULong
79@Extern(name = "scoop_http1_free")
80internal fun http1Free(handle: ULong)
82@Extern(name = "scoop_http1_expect")
83internal fun http1Expect(handle: ULong, name: Ptr<Byte>, size: Long): Int
85@Extern(name = "scoop_http1_receive")
86internal fun http1Receive(handle: ULong, data: Ptr<Byte>, size: Long): NativeHttpStep
88@GCLeaf
89@Extern(name = "scoop_http1_started_messages")
90internal fun http1StartedMessages(handle: ULong): Long
92@Extern(name = "scoop_http1_end")
93internal fun http1End(handle: ULong): Int
95@GCLeaf
96@Extern(name = "scoop_http1_is_unexpected_eof")
97internal fun http1IsUnexpectedEof(code: Int): Int
99@Extern(name = "scoop_http1_resume")
100internal fun http1Resume(handle: ULong): Int
102@GCLeaf
103@Extern(name = "scoop_http1_switched")
104internal fun http1Switched(handle: ULong): Int
106@Extern(name = "scoop_http1_error")
107internal fun http1Error(handle: ULong): Ptr<Byte>