txdv / libuvsharp Goto Github PK
View Code? Open in Web Editor NEW.NET bindings for libuv
.NET bindings for libuv
Error codes on windows seem to be totally different then what I compile into the library.
Under linux I generate the file containing the error codes https://github.com/txdv/LibuvSharp/blob/master/LibuvSharp/Internal/uv_err_code.cs and the error codes differ on windows.
related libuv issue: libuv/libuv#283
Hi there,
I'm trying to understand how the library works.
I wrote the following client code replacing the Client in TcpAsync:
public static async Task Client2()
{
try
{
using (System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient())
{
client.Connect(Default.IPEndPoint);
var st = client.GetStream();
using (BinaryWriter writer = new BinaryWriter(st))
using (BinaryReader reader = new BinaryReader(st))
{
writer.Write("Hello ");
writer.Flush();
writer.Write(true);
writer.Flush();
writer.Write(" good to go");
string s = reader.ReadString();
Console.Write(s);
}
}
}
catch (Exception e)
{
Console.WriteLine("Client Exception:");
Console.WriteLine(e);
}
}
Well, the server never returns from AcceptAsync().
I'm familiar with socket programming, but not this.
Is this implementation somehow bound to use strings or something? I mean, shouldn't I be able to read the bytes sent by the client?
Thanks!
Doesn't however on mono. I will address this issue hopefully today.
I think I will take a strict look of what is supported by the .NET runtime and create a mono strict option so verification can be made easier.
Mono is able to pin down a lot of non blittable. Even normal clr objects and all the fields can be accessed via a pointer.
All throughout the examples and tests, there is code like this:
var now = DateTime.Now;
// ... do something ...
span = DateTime.Now - now;
You should never use DateTime.Now
for timing operations.
DateTime.Now
calls DateTime.UtcNow
under the hood anyway, and then applies the local time zone.For timing operation, use a System.Diagnostics.Stopwatch
.
You can do any of the following:
var stopwatch = Stopwatch.StartNew();
// .. do the thing ...
stopwatch.Stop();
TimeSpan span = stopwatch.Elapsed;
var stopwatch = new Stopwatch();
for (var foo in alotofthings)
{
stopwatch.Restart();
// .. do the things ...
TimeSpan span = stopwatch.Elapsed;
}
long start = Stopwatch.GetTimestamp();
// .. do the thing(s) ...
long stop = Stopwatch.GetTimestamp();
long elapsed = stop - start;
TimeSpan elapsedTime = TimeSpan.FromSeconds(elapsed * (1.0 / Stopwatch.Frequency));
I wanted the give a try to the project but getting some tests failing, is this an issue on my part?
System.Net.Sockets.SocketExceptionOnly one usage of each socket address (protocol/network address/port) is normally permitted
at LibuvSharp.Ensure.Success(Int32 errorCode, Loop loop) in Ensure.cs: line 50
at LibuvSharp.PipeListener.Bind(String name) in Pipe.cs: line 35
at LibuvSharp.Tests.PipeFixture.OneSideCloseTest(String name) in PipeFixture.cs: line 160
at LibuvSharp.Tests.PipeFixture.OneSideClose() in PipeFixture.cs: line 148
System.Net.Sockets.SocketExceptionOnly one usage of each socket address (protocol/network address/port) is normally permitted
at LibuvSharp.Ensure.Success(Int32 errorCode, Loop loop) in Ensure.cs: line 50
at LibuvSharp.PipeListener.Bind(String name) in Pipe.cs: line 35
at LibuvSharp.Tests.PipeFixture.SimpleTest(String name) in PipeFixture.cs: line 25
at LibuvSharp.Tests.PipeFixture.Simple() in PipeFixture.cs: line 13
Xunit.Sdk.EqualExceptionAssert.Equal() Failure
Expected: 3
Actual: 0
at LibuvSharp.Tests.PipeFixture.StressTest(String name) in PipeFixture.cs: line 133
at LibuvSharp.Tests.PipeFixture.Stress() in PipeFixture.cs: line 81
LibuvSharp.UVExceptionENOTCONN(31): socket is not connected
at LibuvSharp.Ensure.Success(Int32 errorCode, Loop loop) in Ensure.cs: line 50
at LibuvSharp.UVStream.Resume() in UVStream.cs: line 81
at LibuvSharp.Tests.ProcessFixture.ProcessSpawnTest(String command, Action`1 callback) in ProcessFixture.cs: line 50
at LibuvSharp.Tests.ProcessFixture.ProcessSpawn() in ProcessFixture.cs: line 66
Xunit.Sdk.TrueExceptionAssert.True() Failure
at LibuvSharp.Tests.TcpFixture.PeerAndSockname() in TcpFixture.cs: line 303
System.Net.Sockets.SocketExceptionOnly one usage of each socket address (protocol/network address/port) is normally permitted
at LibuvSharp.Ensure.Success(Int32 errorCode, Loop loop) in Ensure.cs: line 50
at LibuvSharp.Listener`1.Listen(Int32 backlog) in Listener.cs: line 28
at LibuvSharp.Listener`1.Listen() in Listener.cs: line 33
at LibuvSharp.Tests.TcpFixture.SimpleTest(IPEndPoint ep) in TcpFixture.cs: line 41
at LibuvSharp.Tests.TcpFixture.Simple() in TcpFixture.cs: line 15
Xunit.Sdk.EqualExceptionAssert.Equal() Failure
Position: First difference is at position 20
Expected: PINGPINGPINGPINGPINGPINGPINGPINGPINGPING
Actual: PINGPINGPINGPINGPING
at LibuvSharp.Tests.TcpFixture.<>c__DisplayClass16.<>c__DisplayClass18.<StressTest>b__e(String str) in TcpFixture.cs: line 107
at LibuvSharp.IUVStreamExtensions.<>c__DisplayClass1.<Read>b__0(ArraySegment`1 data) in IUVStreamExtensions.cs: line 10
at LibuvSharp.UVStream.OnData(ArraySegment`1 data) in UVStream.cs: line 140
at LibuvSharp.UVStream.read_callback(IntPtr stream, IntPtr size) in UVStream.cs: line 115
at LibuvSharp.UVStream.read_callback_w(IntPtr stream, IntPtr size, WindowsBufferStruct buf) in UVStream.cs: line 99
at LibuvSharp.Loop.uv_run(LoopSafeHandle loop, uv_run_mode mode)
at LibuvSharp.Loop.<Run>b__2() in Loop.cs: line 146
at LibuvSharp.Loop.RunGuard(Action action) in Loop.cs: line 127
at LibuvSharp.Loop.Run() in Loop.cs: line 146
at LibuvSharp.Tests.TcpFixture.StressTest(IPEndPoint ep) in TcpFixture.cs: line 136
at LibuvSharp.Tests.TcpFixture.Stress() in TcpFixture.cs: line 85
Xunit.Sdk.NotEqualExceptionAssert.NotEqual() Failure
at LibuvSharp.Tests.ThreadingFixture.LoopBlocking() in ThreadingFixture.cs: line 20
Xunit.Sdk.TrueExceptionAssert.True() Failure
at LibuvSharp.Tests.TimerFixture.Simple(Int32 times, Int32 spawn) in TimerFixture.cs: line 26
Xunit.Sdk.TrueExceptionAssert.True() Failure
at LibuvSharp.Tests.TimerFixture.Simple(Int32 times, Int32 spawn) in TimerFixture.cs: line 26
Xunit.Sdk.TrueExceptionAssert.True() Failure
at LibuvSharp.Tests.TimerFixture.Simple(Int32 times, Int32 spawn) in TimerFixture.cs: line 26
Xunit.Sdk.EqualExceptionAssert.Equal() Failure
Expected: 2
Actual: 0
at LibuvSharp.Tests.UdpFixture.RunTest(IPEndPoint ep) in UdpFixture.cs: line 62
at LibuvSharp.Tests.UdpFixture.Run() in UdpFixture.cs: line 13
I'm working on a version of my Flux web server using LibuvSharp: https://github.com/markrendle/flux/tree/libuv
My test console application works fine until I hit it with around 10,000 requests using weighttp -n 10000 -t 4 -c 8
, at which point I start getting AccessViolationException thrown all over the place.
It also gets thrown sometimes when running the TcpFixture.Stress
test (using R# test runner).
This is on a fairly monster PC, overclocked i7-4770, 32GB RAM, SSDs, etc.
I'm going to do some investigation of my own today, but thought I'd open an issue to get other eyes on the problem.
Please write a short documentation/readme on how to get started using LibuvSharp including:
Because that would be really useful
UVStream
ByteBufferAllocatorBase allocator;
public ByteBufferAllocatorBase ByteBufferAllocator
{
get
{
return allocator ?? Loop.ByteBufferAllocator;
}
set
{
allocator = value;
}
}
public void Resume()
{
CheckDisposed();
int r = uv_read_start(NativeHandle, ByteBufferAllocator.AllocCallback, read_cb);
Ensure.Success(r);
}
Don't know if I'm doing it "right", but I just cloned everything, compiled and built clean and shiny on Arch Linux.
Running TcpAsync.exe immediately leads to this:
$ ./TcpAsync.exe
Starting example.
From Server: Hello World!
Unhandled Exception:
System.InvalidOperationException: The underlying Task is already in one of the three final states: RanToCompletion, Faulted, or Canceled.
at System.Threading.Tasks.TaskCompletionSource`1<System.Nullable`1<System.ArraySegment`1<byte>>>.SetResult (System.Nullable`1<System.ArraySegment`1<byte>>) <0x00057>
at LibuvSharp.Threading.Tasks.IUVStreamExtensions/<ReadAsync>c__AnonStorey15.<>m__1E () <0x00047>
at LibuvSharp.Handle/<Close>c__AnonStorey0.<>m__0 () <0x0006c>
at LibuvSharp.CAction.PrivateCallback () <0x00022>
at (wrapper native-to-managed) LibuvSharp.CAction.PrivateCallback () <0x0006c>
at (wrapper managed-to-native) LibuvSharp.Loop.uv_run (intptr,LibuvSharp.uv_run_mode) <0x00060>
at LibuvSharp.Loop.Run () <0x00017>
at LibuvSharp.Threading.Tasks.LoopExtensions.Run (LibuvSharp.Loop,System.Func`1<System.Threading.Tasks.Task>) <0x001e7>
at Test.MainClass.Main (string[]) <0x000a3>
From Client: Labas Pasauli!
mono: src/unix/stream.c:1074: uv_shutdown: Assertion `((stream)->io_watcher.fd) >= 0' failed.
Stacktrace:
at <unknown> <0xffffffff>
at (wrapper managed-to-native) LibuvSharp.UVStream.uv_shutdown (intptr,intptr,LibuvSharp.Handle/callback) <0xffffffff>
at LibuvSharp.UVStream.Shutdown (System.Action) <0x0026f>
at LibuvSharp.IUVStreamExtensions.Shutdown (LibuvSharp.IUVStream) <0x00018>
at Test.MainClass/<Server>c__async0.MoveNext () <0x00433>
at (wrapper unbox) Test.MainClass/<Server>c__async0.MoveNext () <0xffffffff>
at System.Threading.Tasks.ActionContinuation.Execute () <0x00019>
at System.Threading.Tasks.Task.ProcessCompleteDelegates () <0x00053>
at System.Threading.Tasks.Task.Finish () <0x00157>
at System.Threading.Tasks.Task`1.TrySetResult (TResult) <0x000eb>
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetResult (TResult) <0x00047>
at AsyncExtensions/<ReadStringAsync>c__async2.MoveNext () <0x001b7>
at (wrapper unbox) AsyncExtensions/<ReadStringAsync>c__async2.MoveNext () <0xffffffff>
at System.Threading.Tasks.ActionContinuation.Execute () <0x00019>
at System.Threading.Tasks.Task.ProcessCompleteDelegates () <0x00053>
at System.Threading.Tasks.Task.Finish () <0x00157>
at System.Threading.Tasks.Task`1.TrySetResult (TResult) <0x000eb>
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetResult (TResult) <0x00047>
at AsyncExtensions/<ReadStringAsync>c__async3.MoveNext () <0x002ff>
at (wrapper unbox) AsyncExtensions/<ReadStringAsync>c__async3.MoveNext () <0xffffffff>
at System.Threading.Tasks.ActionContinuation.Execute () <0x00019>
at System.Threading.Tasks.Task.ProcessCompleteDelegates () <0x00053>
at System.Threading.Tasks.Task.Finish () <0x00157>
at System.Threading.Tasks.Task.ThreadStart () <0x0061f>
at System.Threading.Tasks.Task.Execute () <0x0000f>
at System.Threading.Tasks.TpScheduler.TaskExecuterCallback (object) <0x00047>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <0xffffffff>
uv_timer_start has a uv_timer_cb and the signature of uv_timer_cb is (IntPtr) not (IntPtr, int)
I am interested in using this library for developing a high performance socket server on Linux. I've already tried using async sockets under mono but their performance is abysmal compared on how the same IOCP socket server runs under Windows with .NET. While mono uses epoll under Linux when available, the actual implementation of async socket operations (SendAsync, ReceiveAsync, etc) is using a threadpool making them quite unusable in high performance scenarios.
I checked the tcp tests source code regarding the possible operations, but I do not have sufficient information to take an informed decision. I am interested mainly in the following topics:
What is the status of this library regarding sockets support? Was it used until now in production applications?
Hello, your framework is really good, high-performance, and you want to continue to update it, optimize it for the net core, so you can make a lightweight and high-performance version of the net core, compared to the built-in socket of the net core
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.