Пример #1
0
		void IHttpServer.SendResponse(BaseConnection c, HttpMessageWriter writer)
		{
			var r = EventArgsManager.Get();
			r.CopyAddressesFrom(c);
			r.Count = writer.Count;
			r.OffsetOffset = writer.OffsetOffset;
			r.AttachBuffer(writer.Detach());

			SendAsync(r);
		}
Пример #2
0
		void IHttpServer.SendResponse(BaseConnection c, ArraySegment<byte> data)
		{
			int offset = data.Offset, left = data.Count;

			while (left > 0)
			{
				var r = EventArgsManager.Get();
				r.CopyAddressesFrom(c);
				r.OffsetOffset = r.MinimumRequredOffsetOffset;
				r.AllocateBuffer();
				r.SetMaxCount();

				if (r.Count > left)
					r.Count = left;

				r.BlockCopyFrom(new ArraySegment<byte>(data.Array, offset, r.Count));

				offset += r.Count;
				left -= r.Count;

				SendAsync(r);
			}
		}
Пример #3
0
        static bool ServersManager_Received(ServersManager<BaseConnection2> server, BaseConnection c, ref ServerAsyncEventArgs e)
        {
            e.Count = e.BytesTransferred;
            server.SendAsync(e);
            e = null;

            return true;
        }
Пример #4
0
 static void ServersManager_NewConnection(ServersManager<BaseConnection2> s, BaseConnection e)
 {
     Interlocked.Increment(ref openedConnections);
 }
Пример #5
0
 static void ServersManager_EndConnection(ServersManager<BaseConnection2> s, BaseConnection e)
 {
     Interlocked.Increment(ref closedConnections);
 }
Пример #6
0
        private bool PeerServer_Received(ServersManager<PeerConnection> s, BaseConnection с, ref ServerAsyncEventArgs e)
        {
            //lock (syncRoot)
            {
                try
                {
                    Allocation allocation = allocations.Get(e.LocalEndPoint);

                    if (allocation != null)
                    {
                        if (allocation.Permissions.IsPermited(e.RemoteEndPoint))
                        {
                            allocation.TouchLifetime();

                            if (allocation.ActiveDestination.IsEqual(e.RemoteEndPoint))
                            {
                                if (e.LocalEndPoint.Protocol == ServerProtocol.Tcp)
                                {
                                    TcpFramingHeader.GetBytes(e.Buffer, e.Offset, TcpFrameType.EndToEndData, e.BytesTransferred);

                                    e.Count = e.OffsetOffset + e.BytesTransferred;
                                    e.OffsetOffset = 0;
                                }
                                else
                                {
                                    e.Count = e.BytesTransferred;
                                }

                                e.LocalEndPoint = allocation.Local;
                                e.RemoteEndPoint = allocation.Reflexive;
                                e.ConnectionId = ServerAsyncEventArgs.AnyConnectionId;

                                turnServer.SendAsync(e);

                                e = null;
                            }
                            else
                            {
                                TurnMessage message = new TurnMessage()
                                {
                                    IsAttributePaddingDisabled = true,
                                    MessageType = MessageType.DataIndication,
                                    TransactionId = TransactionServer.GenerateTransactionId(),

                                    MagicCookie = new MagicCookie(),

                                    RemoteAddress = new RemoteAddress()
                                    {
                                        IpAddress = e.RemoteEndPoint.Address,
                                        Port = (UInt16)e.RemoteEndPoint.Port,
                                    },

                                    Data = new Data()
                                    {
                                        ValueRef = e.Buffer,
                                        ValueRefOffset = e.Offset,
                                        ValueRefLength = e.BytesTransferred,
                                    },
                                };

                                SendTurn(message, allocation.Local, allocation.Reflexive);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.WriteWarning(ex.ToString());
                }
            }

            return true;
        }
Пример #7
0
 public void CopyAddressesFrom(BaseConnection c)
 {
     this.ConnectionId   = c.Id;
     this.LocalEndPoint  = c.LocalEndPoint;
     this.RemoteEndPoint = c.RemoteEndPoint;
 }
Пример #8
0
			void IHttpServer.SendResponse(BaseConnection connection, ArraySegment<byte> data)
			{
				server.SendResponse(connection, data, index);
			}
Пример #9
0
			void IHttpServer.SendResponse(BaseConnection connection, HttpMessageWriter writer)
			{
				server.SendResponse(connection, writer, index);
			}
Пример #10
0
		protected void SendResponse(BaseConnection c, HttpMessageWriter writer, int agentIndex)
		{
			var r = EventArgsManager.Get();
			r.CopyAddressesFrom(c);
			r.Count = writer.Count;
			r.OffsetOffset = writer.OffsetOffset;
			r.AttachBuffer(writer.Detach());

			SendAsync(r, agentIndex);
		}
Пример #11
0
		void IHttpServerAgent.HandleRequest(BaseConnection c, HttpMessageReader httpReader, ArraySegment<byte> httpContent)
		{
			if (httpReader.Method != Methods.Get)
			{
				var writer = new HttpMessageWriter();
				writer.WriteResponse(StatusCodes.NotAcceptable);

				httpServer.SendResponse(c, writer);
			}
			else
			{
				if (httpReader.RequestUri.Equals(uri1))
				{
					var writer = new HttpMessageWriter();

					writer.WriteStatusLine(StatusCodes.MovedPermanently);
					writer.WriteContentLength(0);
					writer.WriteLocation(c.LocalEndPoint.Protocol == ServerProtocol.Tcp, httpReader.Host.Host, httpReader.Host.Port, uri2);
					writer.WriteCRLF();

					httpServer.SendResponse(c, writer);
				}
				else
				{
					var rawFile = GetFile(httpReader);

					if (rawFile.HasValue == false)
					{
						var writer = new HttpMessageWriter();
						writer.WriteResponse(StatusCodes.NotFound);

						httpServer.SendResponse(c, writer);
					}
					else
					{
						var file = rawFile.Value;

						var writer = new HttpMessageWriter();
						writer.WriteStatusLine(StatusCodes.OK);
						writer.WriteContentType(file.ContentType);
						writer.WriteContentLength(file.Content.Length);
						writer.WriteCRLF();

						httpServer.SendResponse(c, writer);

						httpServer.SendResponse(c, new ArraySegment<byte>(file.Content));
					}
				}
			}
		}
Пример #12
0
 public void CopyAddressesFrom(BaseConnection c)
 {
     ConnectionId = c.Id;
     LocalEndPoint = c.LocalEndPoint;
     RemoteEndPoint = c.RemoteEndPoint;
 }
Пример #13
0
		static void ServersManager_EndConnection(ServersManager<HttpConnection> s, BaseConnection e)
		{
			Console.WriteLine(@"  Connection Closed: {0}", e.RemoteEndPoint.ToString(), e.ToString());
		}