예제 #1
0
		internal FragmentInformation(RUDPSocket rudpSocket, bool isReliable, byte[] payload, int offset, int size, RUDPSendIAsyncResult asyncResult)
		{
			rudp = rudpSocket;
			IsReliable = isReliable;
			Offset = offset;
			Size = size;
			Payload = payload;
			AsyncResult = asyncResult;
		}
예제 #2
0
        internal void OnEndSend(RUDPSocketError error, RUDPSendIAsyncResult asyncResult)
        {
            if (asyncResult == null)
            {
                return;
            }

            asyncResult.SetAsCompleted(error, false);
        }
예제 #3
0
 internal FragmentInformation(RUDPSocket rudpSocket, bool isReliable, byte[] payload, int offset, int size, RUDPSendIAsyncResult asyncResult)
 {
     rudp        = rudpSocket;
     IsReliable  = isReliable;
     Offset      = offset;
     Size        = size;
     Payload     = payload;
     AsyncResult = asyncResult;
 }
예제 #4
0
        public int EndSend(IAsyncResult asyncResult)
        {
            RUDPSendIAsyncResult result = asyncResult as RUDPSendIAsyncResult;

            result.EndInvoke(false);

            if (result.SocketError != RUDPSocketError.Success)
            {
                return(-1);
            }

            return(result._size);
        }
예제 #5
0
        public IAsyncResult BeginSend(byte[] buffer,
                                      int offset,
                                      int size,
                                      out RUDPSocketError errorCode,
                                      AsyncCallback callback,
                                      Object state,
                                      bool reliable)
        {
            RUDPSendIAsyncResult asyncResult = new RUDPSendIAsyncResult(this, callback, state, size);

            errorCode = RUDPStack.SendPayload(this, buffer, offset, size, reliable, asyncResult);

            if (errorCode != RUDPSocketError.Success)
            {
                return(null);
            }

            return(asyncResult);
        }
예제 #6
0
		internal static RUDPSocketError SendPayload(RUDPSocket rudp, byte[] payload, int offset, int payloadLength, bool reliable, RUDPSendIAsyncResult asyncResult)
		{
			// We are no longer active
			if (!_isStackRunning)
				return RUDPSocketError.SystemNotReady;

			//---- Only when connected
			if (rudp._status != RUDPSocketStatus.Connected)
				return RUDPSocketError.NotConnected;

			//---- Fragmentation
			asyncResult.ForceAsyncCall = true;
			FragmentInformation fragments = NewFragmentInformation(rudp, reliable, payload, offset, payloadLength, asyncResult);

			//----- Async send
			rudp._fragmentsLock.EnterWriteLock();
			rudp._fragments.AddFirst(fragments);
			rudp._fragmentsLock.ExitWriteLock();

			ForceFragmentsSending(rudp._controlThreadId);

			//---- If possible send Sync... otherwise relate to control thread
			/*
			if (!SendFragments(fragments))
			{
				rudp._fragmentsLock.EnterWriteLock();
				rudp._fragments.AddFirst(fragments);
				rudp._fragmentsLock.ExitWriteLock();

				_protocolControlEvent.Set();
			}
			*/

			//---- Synchrone send
			/*
			while (!SendFragments(fragments))
				fragments.rudp._controlWindow.WaitObject.WaitOne();
			*/
			return fragments.Error;
		}
예제 #7
0
		internal static FragmentInformation NewFragmentInformation(RUDPSocket rudpSocket, bool isReliable, byte[] payload, int offset, int size, RUDPSendIAsyncResult asyncResult)
		{
			//return new FragmentInformation(rudpSocket, isReliable, payload, offset, size, asyncResult);

			FragmentInformation fragment;

			if (!_fragmentsPools.TryDequeue(out fragment))
			{
				for (int index = 0; index < 100; index++)
					_fragmentsPools.Enqueue(new FragmentInformation(null, false, null, -1, -1, null));
				return new FragmentInformation(rudpSocket, isReliable, payload, offset, size, asyncResult);
			}

			fragment.rudp = rudpSocket;
			fragment.IsReliable = isReliable;
			fragment.Offset = offset;
			fragment.Size = size;
			fragment.Payload = payload;
			fragment.AsyncResult = asyncResult;

			return fragment;
		}
예제 #8
0
		/// <summary>
		/// Called when we have an error on a socket.
		/// </summary>
		static internal void OnSocketUnhandledError(RUDPSocket rudp, RUDPSocketError error, RUDPSendIAsyncResult sendAsyncResult)
		{
			//---- Disconnect the socket
			OnDisconnected(rudp, DisconnectionReason.SocketError);

			//---- Handle the error and forward it to the socket
			if (rudp._status == RUDPSocketStatus.Connecting)
				rudp.OnEndConnect(error);
			else
			{
				// On Send Error
				if (sendAsyncResult != null)
					rudp.OnEndSend(error, sendAsyncResult);

				// ELSE ... HOW TO GET sendAsyncResult when NULL ?????

				// On Receive Error
				RUDPReceiveIAsyncResult receiveAsyncResult = null;
				Interlocked.Exchange<RUDPReceiveIAsyncResult>(ref receiveAsyncResult, rudp._asyncResultReceive);
				if (receiveAsyncResult != null)
				{
					Interlocked.Exchange<RUDPReceiveIAsyncResult>(ref rudp._asyncResultReceive, null);

					rudp.OnEndReceive(error, null, true, receiveAsyncResult);
				}
			}
		}
예제 #9
0
		internal void OnEndSend(RUDPSocket rudp, RUDPSendIAsyncResult asyncResult)
		{
			rudp.OnEndSend(RUDPSocketError.Success, asyncResult);
		}
예제 #10
0
		public IAsyncResult BeginSend(byte[] buffer,
										int offset,
										int size,
										out RUDPSocketError errorCode,
										AsyncCallback callback,
										Object state,
										bool reliable)
		{
			RUDPSendIAsyncResult asyncResult = new RUDPSendIAsyncResult(this, callback, state, size);

			errorCode = RUDPStack.SendPayload(this, buffer, offset, size, reliable, asyncResult);

			if (errorCode != RUDPSocketError.Success)
				return null;

			return asyncResult;
		}
예제 #11
0
		internal void OnEndSend(RUDPSocketError error, RUDPSendIAsyncResult asyncResult)
		{
			if (asyncResult == null)
				return;

			asyncResult.SetAsCompleted(error, false);
		}
예제 #12
0
 internal void OnEndSend(RUDPSocket rudp, RUDPSendIAsyncResult asyncResult)
 {
     rudp.OnEndSend(RUDPSocketError.Success, asyncResult);
 }