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); }
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); } }
static bool ServersManager_Received(ServersManager<BaseConnection2> server, BaseConnection c, ref ServerAsyncEventArgs e) { e.Count = e.BytesTransferred; server.SendAsync(e); e = null; return true; }
static void ServersManager_NewConnection(ServersManager<BaseConnection2> s, BaseConnection e) { Interlocked.Increment(ref openedConnections); }
static void ServersManager_EndConnection(ServersManager<BaseConnection2> s, BaseConnection e) { Interlocked.Increment(ref closedConnections); }
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; }
public void CopyAddressesFrom(BaseConnection c) { this.ConnectionId = c.Id; this.LocalEndPoint = c.LocalEndPoint; this.RemoteEndPoint = c.RemoteEndPoint; }
void IHttpServer.SendResponse(BaseConnection connection, ArraySegment<byte> data) { server.SendResponse(connection, data, index); }
void IHttpServer.SendResponse(BaseConnection connection, HttpMessageWriter writer) { server.SendResponse(connection, writer, index); }
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); }
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)); } } } }
public void CopyAddressesFrom(BaseConnection c) { ConnectionId = c.Id; LocalEndPoint = c.LocalEndPoint; RemoteEndPoint = c.RemoteEndPoint; }
static void ServersManager_EndConnection(ServersManager<HttpConnection> s, BaseConnection e) { Console.WriteLine(@" Connection Closed: {0}", e.RemoteEndPoint.ToString(), e.ToString()); }