-
Notifications
You must be signed in to change notification settings - Fork 10
/
Interop.cs
47 lines (36 loc) · 1.68 KB
/
Interop.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.CompilerServices;
using static Wasi.AspNetCore.Server.Atmo.AtmoLogger;
namespace Wasi.AspNetCore.Server.Atmo;
internal class Interop
{
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void RunHttpServer(Interop owner, int port);
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void ResponseAddHeader(uint ident, string name, string value);
[MethodImpl(MethodImplOptions.InternalCall)]
public static unsafe extern void ResponseComplete(uint ident, int statusCode, byte* body, int body_len);
public event EventHandler<uint>? OnIncomingRequest;
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void LogMessage(uint ident, int level, string message);
[MethodImpl(MethodImplOptions.InternalCall)]
public static unsafe extern void LogMessageRaw(uint ident, int level, byte* message, int message_len);
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern string RequestGetField(FieldType fieldType, string fieldName, uint ident);
// TODO: Make sure this doesn't get trimmed if AOT compiled
// It's static because we want it to be able to emit pending logs even if 'interop' is null
private static unsafe void HandleIncomingRequest(Interop interop, uint ident)
{
AtmoLogsWriterStream.EmitPendingMessages(ident);
interop.OnIncomingRequest?.Invoke(interop, ident);
}
public enum FieldType : int
{
Meta = 0,
Body = 1,
Header = 2,
Params = 3,
State = 4,
}
}