Exemple #1
0
        /// <summary>
        /// Determines whether [is server end point exist] [the specified end point].
        /// </summary>
        /// <param name="endPoint">The end point.</param>
        /// <returns>
        ///   <c>true</c> if [is server end point exist] [the specified end point]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsServerEndPointExist(AddressEndPoint endPoint)
        {
            if (endPoint == null)
            {
                ThrowHelper.ThrowArgumentNullException("endPoint");
            }

            bool result = false;

            mLockForServers.EnterReadLock();
            try
            {
                foreach (KeyValuePair <long, ServerContainer> kv in mServers)
                {
                    if (kv.Value.Listener.LocalEndpoint.Equals(endPoint))
                    {
                        result = true;
                        break;
                    }
                }
            }
            finally
            {
                mLockForServers.ExitReadLock();
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Connects the specified end point.
        /// </summary>
        /// <param name="endPoint">The end point.</param>
        /// <param name="bufferSize">Size of the buffer.</param>
        /// <param name="clientStreamFactory">The client stream factory.</param>
        /// <returns>
        /// Network Stream instance
        /// </returns>
        public NetworkStream Connect(AddressEndPoint endPoint, int bufferSize, IClientStreamFactory clientStreamFactory)
        {
            DoDisposeCheck();
            if (endPoint == null)
            {
                ThrowHelper.ThrowArgumentNullException("endPoint");
            }
            if (bufferSize < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException("bufferSize");
            }
            if (clientStreamFactory == null)
            {
                ThrowHelper.ThrowArgumentNullException("clientStreamFactory");
            }

            ITcpClient client = mNetworkFactory.CreateTcpClient();

            client.Connect(endPoint); // ez dobhat kivételt
            client.Client.SendBufferSize    = bufferSize;
            client.Client.ReceiveBufferSize = bufferSize;
            client.Client.SendTimeout       = Timeout.Infinite;
            client.Client.ReceiveTimeout    = Timeout.Infinite;
            client.Client.SetKeepAliveValues(true, DefaultSocketKeepAliveTime, DefaultSocketKeepAliveTimeInterval);
            client.Client.NoDelay = this.NoDelay;

            if (LOGGER.IsDebugEnabled)
            {
                LOGGER.Debug(string.Format("SYNAPSE_NETWORK_MANAGER, create client network stream for connection. Factory type: '{0}'. Connection remote endpoint: '{1}'", clientStreamFactory.GetType().FullName, endPoint.ToString()));
            }
            return(clientStreamFactory.CreateNetworkStream(client));
        }
Exemple #3
0
        /// <summary>
        /// Begins the connect.
        /// </summary>
        /// <param name="endPoint">The end point.</param>
        /// <param name="bufferSize">Size of the buffer.</param>
        /// <param name="clientStreamFactory">The client stream factory.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">The state.</param>
        /// <returns>Async property</returns>
        public IAsyncResult BeginConnect(AddressEndPoint endPoint, int bufferSize, IClientStreamFactory clientStreamFactory, AsyncCallback callback, object state)
        {
            DoDisposeCheck();
            if (endPoint == null)
            {
                ThrowHelper.ThrowArgumentNullException("endPoint");
            }
            if (bufferSize < 0)
            {
                ThrowHelper.ThrowArgumentOutOfRangeException("bufferSize");
            }
            if (clientStreamFactory == null)
            {
                ThrowHelper.ThrowArgumentNullException("clientStreamFactory");
            }

            Interlocked.Increment(ref mAsyncActiveConnectCount);
            NetworkManagerConnectDelegate d = new NetworkManagerConnectDelegate(this.Connect);

            if (this.mAsyncActiveConnectEvent == null)
            {
                lock (LOCK_CONNECT)
                {
                    if (this.mAsyncActiveConnectEvent == null)
                    {
                        this.mAsyncActiveConnectEvent = new AutoResetEvent(true);
                    }
                }
            }
            this.mAsyncActiveConnectEvent.WaitOne();
            this.mConnectDelegate = d;
            return(d.BeginInvoke(endPoint, bufferSize, clientStreamFactory, callback, state));
        }
Exemple #4
0
        /// <summary>
        /// Gets the server end point.
        /// </summary>
        /// <param name="serverId">The server id.</param>
        /// <returns>AddressEndPoint</returns>
        public AddressEndPoint GetServerEndPoint(long serverId)
        {
            AddressEndPoint result = null;

            mLockForServers.EnterReadLock();
            try
            {
                if (mServers.ContainsKey(serverId))
                {
                    result = mServers[serverId].Listener.LocalEndpoint;
                }
            }
            finally
            {
                mLockForServers.ExitReadLock();
            }

            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        /// <param name="endPoint">The end point.</param>
        /// <param name="serverStreamFactory">The server stream factory.</param>
        /// <returns>Identifier of the listener</returns>
        public long StartServer(AddressEndPoint endPoint, IServerStreamFactory serverStreamFactory)
        {
            DoDisposeCheck();

            if (endPoint == null)
            {
                ThrowHelper.ThrowArgumentNullException("endPoint");
            }

            ITcpListener listener = mNetworkFactory.CreateTcpListener(endPoint);

            listener.Start(); // ez dobhat kivételt

            ServerContainer container = new ServerContainer(Interlocked.Increment(ref mServerGlobalId), listener, this, serverStreamFactory);

            mLockForServers.EnterWriteLock();
            try
            {
                mServers.Add(container.ServerId, container);
                container.Initialize();
            }
            catch (Exception ex)
            {
                if (LOGGER.IsFatalEnabled)
                {
                    LOGGER.Fatal(ex.Message, ex);
                }
                listener.Stop();
                throw;
            }
            finally
            {
                mLockForServers.ExitWriteLock();
            }

            return(container.ServerId);
        }
Exemple #6
0
 /// <summary>
 /// Connects the specified end point.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <param name="bufferSize">Size of the buffer.</param>
 /// <returns>Network Stream instance</returns>
 public NetworkStream Connect(AddressEndPoint endPoint, int bufferSize)
 {
     DoDisposeCheck();
     return(Connect(endPoint, bufferSize, mClientStreamFactory));
 }
Exemple #7
0
 /// <summary>
 /// Connects the specified end point.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <param name="clientStreamFactory">The client stream factory.</param>
 /// <returns>Network Stream instance</returns>
 public NetworkStream Connect(AddressEndPoint endPoint, IClientStreamFactory clientStreamFactory)
 {
     DoDisposeCheck();
     return(Connect(endPoint, this.mSocketReceiveBufferSize, clientStreamFactory));
 }
Exemple #8
0
 /// <summary>
 /// Begins the connect.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <param name="bufferSize">Size of the buffer.</param>
 /// <param name="callback">The callback.</param>
 /// <param name="state">The state.</param>
 /// <returns>Async property</returns>
 public IAsyncResult BeginConnect(AddressEndPoint endPoint, int bufferSize, AsyncCallback callback, object state)
 {
     return(BeginConnect(endPoint, bufferSize, mClientStreamFactory, callback, state));
 }
Exemple #9
0
 /// <summary>
 /// Begins the connect.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <param name="clientStreamFactory">The client stream factory.</param>
 /// <param name="callback">The callback.</param>
 /// <param name="state">The state.</param>
 /// <returns>Async property</returns>
 public IAsyncResult BeginConnect(AddressEndPoint endPoint, IClientStreamFactory clientStreamFactory, AsyncCallback callback, object state)
 {
     return(BeginConnect(endPoint, this.mSocketReceiveBufferSize, clientStreamFactory, callback, state));
 }
Exemple #10
0
 /// <summary>
 /// Starts the server.
 /// </summary>
 /// <param name="endPoint">The end point.</param>
 /// <returns>Identifier of the listener</returns>
 public long StartServer(AddressEndPoint endPoint)
 {
     DoDisposeCheck();
     return(StartServer(endPoint, mServerStreamFactory));
 }