コード例 #1
0
ファイル: TcpStream.cs プロジェクト: dstoffels/Theia
        public void ConnectTo(IPEndPoint remoteEndPoint, Action <TcpStream, Exception> connectedAction, bool dualStack = false)
        {
            if (remoteEndPoint != null && connectedAction != null)
            {
                // let's only connect if a connect isn't in progress already.
                // this way we only need to keep track of one WatcherRequest.
                if (connectRequest == null)
                {
                    onClientConnect = connectedAction;

                    try
                    {
                        connectRequest = new WatcherRequest(
                            uv_req_type.UV_CONNECT,
                            ConnectRequestCallback,
                            h => NativeMethods.TcpConnect(h, InternalHandle, remoteEndPoint));
                    }
                    catch (Exception)
                    {
                        connectRequest?.Dispose();
                        connectRequest = null;
                        throw;
                    }
                }
                else
                {
                    Log.Warning("A connect is already in progress. Please wait for it to finish before connecting again.");
                }
            }
            else
            {
                throw new ArgumentException($"remoteEndPoint {remoteEndPoint}, connectedAction {connectedAction} can't be null!");
            }
        }
コード例 #2
0
ファイル: TcpStream.cs プロジェクト: raiskader/TestMirror
 public void ConnectTo(IPEndPoint remoteEndPoint)
 {
     // make sure callback has been set up. won't get notified otherwise.
     if (onClientConnect != null && remoteEndPoint != null)
     {
         // let's only connect if a connect isn't in progress already.
         // this way we only need to keep track of one WatcherRequest.
         if (connectRequest == null)
         {
             try
             {
                 connectRequest = new WatcherRequest(
                     uv_req_type.UV_CONNECT,
                     ConnectRequestCallback,
                     h => NativeMethods.TcpConnect(h, Handle, remoteEndPoint));
             }
             catch (Exception)
             {
                 connectRequest?.Dispose();
                 connectRequest = null;
                 throw;
             }
         }
         else
         {
             Log.Warning("A connect is already in progress. Please wait for it to finish before connecting again.");
         }
     }
     else
     {
         throw new ArgumentException($"onClientConnect, remoteEndPoint can't be null!");
     }
 }
コード例 #3
0
ファイル: TcpStream.cs プロジェクト: raiskader/TestMirror
        // CloseHandle called by NativeHandle, calls uv_close with callback
        protected override void CloseHandle()
        {
            // dispose connect request (if any)
            connectRequest?.Dispose();

            // uv_tcp_init in constructor requires us to call uv_close here
            // before freeing base NativeHandle
            //
            // IMPORTANT: CloseCallback is not called IMMEDIATELY!
            // it happens some time after returning.
            NativeMethods.CloseHandle(Handle, CloseCallback);
            //Logger.Log($"TcpStream {Handle} closed, releasing pending resources.");
        }
コード例 #4
0
ファイル: TcpStream.cs プロジェクト: dstoffels/Theia
        public void Dispose()
        {
            connectRequest?.Dispose();
            shutdownRequest?.Dispose();

            UnpinReadBuffer();
            try
            {
                CloseHandle();
            }
            catch (Exception exception)
            {
                Log.Warning($"{handle} Failed to close and releasing resources: {exception}");
            }
        }
コード例 #5
0
ファイル: TcpStream.cs プロジェクト: dstoffels/Theia
        // connect /////////////////////////////////////////////////////////////
        void ConnectRequestCallback(WatcherRequest request, Exception error)
        {
            try
            {
                if (error == null)
                {
                    // initialize internal buffer after we can access libuv
                    // send/recv buffer sizes (which is after connecting)
                    InitializeInternalBuffers();
                    ReadStart();
                }

                onClientConnect(this, error);
            }
            finally
            {
                connectRequest.Dispose();
                connectRequest = null;
            }
        }