예제 #1
0
        static void OnConnectionCallback(IntPtr handle, int status)
        {
            TcpStream server = HandleContext.GetTarget <TcpStream>(handle);

            if (server == null)
            {
                return;
            }

            TcpStream client = null;
            Exception error  = null;

            try
            {
                if (status < 0)
                {
                    error = NativeMethods.CreateError((uv_err_code)status);
                }
                else
                {
                    client = server.NewStream();

                    // initialize internal buffer after we can access libuv
                    // send/recv buffer sizes (which is after connecting)
                    client.InitializeInternalBuffers();
                }

                server.onServerConnect(client, error);
            }
            catch
            {
                client?.Dispose();
                throw;
            }
        }
예제 #2
0
        static void OnConnectionCallback(IntPtr handle, int status)
        {
            // look up the C# TcpStream for this native handle
            if (nativeLookup.TryGetValue(handle, out NativeHandle entry))
            {
                if (entry is TcpStream server)
                {
                    TcpStream client = null;
                    Exception error  = null;
                    try
                    {
                        if (status < 0)
                        {
                            error = NativeMethods.CreateError((uv_err_code)status);
                        }
                        else
                        {
                            client = server.NewStream();

                            // initialize internal buffer after we can access libuv
                            // send/recv buffer sizes (which is after connecting)
                            client.InitializeInternalBuffers();
                        }

                        server.onServerConnect(client, error);
                    }
                    catch
                    {
                        client?.Dispose();
                        throw;
                    }
                }
                else
                {
                    Log.Error($"TcpStream.OnConnectionCallback: unexpected lookup type: {entry.GetType()}");
                }
            }
            else
            {
                Log.Error($"TcpStream.OnConnectionCallback: nativeLookup no entry found for handle={handle}");
            }
        }