コード例 #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
ファイル: WatcherRequest.cs プロジェクト: dstoffels/Theia
        static void OnWatcherCallback(IntPtr handle, int status)
        {
            if (handle == IntPtr.Zero)
            {
                return;
            }

            WatcherRequest     request = RequestContext.GetTarget <WatcherRequest>(handle);
            OperationException error   = null;

            if (status < 0)
            {
                error = NativeMethods.CreateError((uv_err_code)status);
            }

            request?.OnWatcherCallback(error);
        }
コード例 #4
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;
            }
        }