Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Unhinged.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ public static void Main(string[] args)
{
var builder = UnhingedEngine
.CreateBuilder()
.SetNWorkersSolver(() => (Environment.ProcessorCount / 2) - 2)
.SetNWorkersSolver(() => (Environment.ProcessorCount / 2))
.SetBacklog(16384)
.SetMaxEventsPerWake(512)
.SetMaxNumberConnectionsPerWorker(512)
.SetPort(8080)
.SetSlabSizes(16 * 1024, 16 * 1024)
.SetSlabSizes(512 * 1024, 128 * 1024)
.InjectRequestHandler(RequestHandler);

var engine = builder.Build();
Expand Down
2 changes: 2 additions & 0 deletions Unhinged/ABI/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ internal struct Linger
internal const int EPOLLERR = 0x008;
internal const int EPOLLHUP = 0x010;
internal const int EPOLLRDHUP = 0x2000;
internal const uint EPOLLET = 0x80000000;
internal const uint EPOLLONESHOT = 0x40000000;

// epoll_ctl ops
internal const int EPOLL_CTL_ADD = 1;
Expand Down
29 changes: 16 additions & 13 deletions Unhinged/Engine/UnhingedEngine.Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ private static unsafe void WorkerLoop(Worker W)

// Ensure free space at the tail; compact or grow if necessary.
// TODO: This logic needs rework, doesn't sense
//int avail = c.Buf.Length - c.Tail;
int avail = _inSlabSize - c.Tail;

// If the receiving buffer has no space available, that means that either there are
Expand All @@ -131,8 +130,7 @@ private static unsafe void WorkerLoop(Worker W)
while (true)
{
long got;
//fixed (byte* p = &c.Buf[c.Tail])
// got = recv(fd, (IntPtr)p, (ulong)avail, 0);

got = recv(fd, c.ReceiveBuffer + c.Tail, (ulong)avail, 0);

if (got > 0)
Expand All @@ -155,7 +153,7 @@ private static unsafe void WorkerLoop(Worker W)
// TODO: That could be an issue because this could give more airtime to a specific fd
// TODO: We want to release the loop to move into another fd's?
break;
}
}
if (err is ECONNRESET or ECONNABORTED or EPIPE) { CloseConn(fd, connections, W); break; }
CloseConn(fd, connections, W); break; // default: close on unexpected errors
}
Expand Down Expand Up @@ -257,7 +255,7 @@ private static async ValueTask TryParseRequests(
bool hasDataToFlush = false;

int idx = 0;

while (true)
{
unsafe
Expand All @@ -268,8 +266,6 @@ private static async ValueTask TryParseRequests(
break;

// A full request was received, handle it

// Extract the request Header data
connection.H1HeaderData = ExtractH1HeaderData(headerSpan);

// Advance the pointer after the request was dealt with
Expand All @@ -294,17 +290,24 @@ private static async ValueTask TryParseRequests(
// Move the incomplete request to the buffer start and reset head and tail to 0
if (connection.Head > 0 && connection.Head < connection.Tail)
{
var length = connection.Tail - connection.Head;
Buffer.MemoryCopy(
connection.ReceiveBuffer + connection.Head,
connection.ReceiveBuffer,
_inSlabSize,
connection.Tail - connection.Head);
length);

// Update head to 0 and tail to length
connection.Head = 0;
connection.Tail = length;
}
else
{
//Reset the receiving buffer
connection.Head = connection.Tail = 0;
}
}

//Reset the receiving buffer
connection.Head = connection.Tail = 0;

if (hasDataToFlush)
{
var tryEmptyResult = TryEmptyWriteBuffer(connection, ref fd);
Expand Down Expand Up @@ -441,7 +444,7 @@ private static unsafe EmptyAttemptResult TryEmptyWriteBuffer(Connection connecti
private static unsafe void ArmEpollIn(ref int fd, int ep)
{
byte* ev = stackalloc byte[EvSize];
WriteEpollEvent(ev, EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP, fd);
WriteEpollEvent(ev, EPOLLIN | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET, fd);
epoll_ctl(ep, EPOLL_CTL_MOD, fd, (IntPtr)ev);
}

Expand All @@ -452,7 +455,7 @@ private static unsafe void ArmEpollIn(ref int fd, int ep)
private static unsafe void ArmEpollOut(ref int fd, int ep)
{
byte* ev = stackalloc byte[EvSize];
WriteEpollEvent(ev, EPOLLOUT | EPOLLRDHUP | EPOLLERR | EPOLLHUP, fd);
WriteEpollEvent(ev, EPOLLOUT | EPOLLRDHUP | EPOLLERR | EPOLLHUP | EPOLLET, fd);
epoll_ctl(ep, EPOLL_CTL_MOD, fd, (IntPtr)ev);
}

Expand Down
6 changes: 3 additions & 3 deletions Unhinged/Unhinged.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<Authors>Diogo Martins</Authors>
<RepositoryUrl>https://github.com/MDA2AV/Unhinged</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>9.0.4</AssemblyVersion>
<FileVersion>9.0.4</FileVersion>
<Version>9.0.4</Version>
<AssemblyVersion>9.0.5</AssemblyVersion>
<FileVersion>9.0.5</FileVersion>
<Version>9.0.5</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>Unhinged</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down
Loading