/// <summary> /// <see cref="ServerLink.OnAcceptInternal"/> /// </summary> protected override bool OnAcceptInternal(LinkSession session) { var tcpSession = (AbstractTcpSession)session; try { if (!base.OnAcceptInternal(session)) { return(false); } var clientSocket = tcpSession.Socket; // Adjust client socket options. clientSocket.NoDelay = NoDelay; tcpSession.BeginReceive(true); Trace.Info("{0} {1} accepted from {2}", Name, tcpSession.InternalHandle, clientSocket.RemoteEndPoint); return(true); } catch (Exception ex) { Trace.Warn("{0} {1} accept error: {2}", Name, tcpSession.InternalHandle, ex); return(false); } }
/// <summary> /// Called internally when an event is ready for preprocessing. /// </summary> internal void OnPreprocess(LinkSession session, Event e) { if (Preprocess != null) { Preprocess(session, e); } }
protected override void OnSessionDisconnectedInternal(int handle, object context) { using (new WriteLock(rwlock)) { if (!ReferenceEquals(session, null)) { session = null; } } }
protected override void OnSessionConnectedInternal(bool result, object context) { if (result) { var session = (LinkSession)context; using (new WriteLock(rwlock)) { this.session = session; } } }
/// <summary> /// Sends out the specified event through this link channel. /// </summary> public override void Send(Event e) { LinkSession currentSession = Session; if (ReferenceEquals(currentSession, null)) { Trace.Warn("{0} dropped event {1}", Name, e); return; } currentSession.Send(e); }
/// <summary> /// Connects to the specified IP address and port. /// </summary> public void Connect(IPAddress ip, int port) { connecting = true; LinkSession session = Session; if (session != null && ((AbstractTcpSession)session).SocketConnected) { Disconnect(); Trace.Info("{0} disconnected to initiate a new connection", Name); } Connect(null, new IPEndPoint(ip, port)); }
public override void InitiateHandshake(LinkSession session) { if (ReferenceEquals(BufferTransform, null)) { return; } var sessionStrategy = (BufferTransformSessionStrategy)session.ChannelStrategy; var bufferTransform = (IBufferTransform)BufferTransform.Clone(); sessionStrategy.BufferTransform = bufferTransform; SignalPool.Acquire(session.InternalHandle).Set(); session.Send(new HandshakeReq { _Transform = false, Data = bufferTransform.InitializeHandshake() }); }
/// <summary> /// Called when a new link session is ready for open. /// </summary> public void InitiateSession(LinkSession session) { if (HasChannelStrategy) { ChannelStrategy.BeforeSessionSetup(session); } if (HasHeartbeatStrategy) { HeartbeatStrategy.BeforeSessionSetup(session); } if (HasChannelStrategy) { ChannelStrategy.InitiateHandshake(session); } else { OnLinkSessionConnectedInternal(true, session); } }
/// <summary> /// <see cref="ClientLink.OnConnectInternal"/> /// </summary> protected override void OnConnectInternal(LinkSession session) { base.OnConnectInternal(session); // Reset the retry counter. retryCount = 0; var tcpSession = (AbstractTcpSession)session; Socket socket = tcpSession.Socket; // Adjust socket options. socket.NoDelay = NoDelay; // Save the remote endpoint to reconnect. remoteEndPoint = socket.RemoteEndPoint; tcpSession.BeginReceive(true); Trace.Info("{0} {1} connected to {2}", Name, tcpSession.InternalHandle, socket.RemoteEndPoint); }
/// <summary> /// Frees managed or unmanaged resources. /// </summary> protected override void Dispose(bool disposing) { if (disposed) { return; } LinkSession session = null; using (new WriteLock(rwlock)) { if (this.session != null) { session = this.session; this.session = null; } } if (session != null) { session.Close(); } base.Dispose(disposing); }
public override void BeforeSessionSetup(LinkSession linkSession) { linkSession.HeartbeatStrategy = new KeepaliveSessionStrategy { Session = linkSession }; }
public override void BeforeSessionSetup(LinkSession linkSession) { linkSession.ChannelStrategy = new BufferTransformSessionStrategy { Session = linkSession }; }
/// <summary> /// Called immediately once a new link session object is created. /// </summary> public virtual void BeforeSessionSetup(LinkSession linkSession) { }
/// <summary> /// Called by a derived link class on a successful connect. /// </summary> protected virtual void OnConnectInternal(LinkSession session) { session.Polarity = true; InitiateSession(session); }
public virtual void InitiateHandshake(LinkSession session) { }
/// <summary> /// Called once an existing link session object is shut down. /// </summary> public virtual void AfterSessionTeardown(LinkSession linkSession) { }
/// <summary> /// Called by a derived link class on a successful accept. /// </summary> protected virtual bool OnAcceptInternal(LinkSession session) { InitiateSession(session); return(true); }
public Diagnostics(LinkSession owner) { this.owner = owner; }