/// <summary> /// Raises an event if the link is disconnected. /// </summary> /// <param name="e">The link connection.</param> protected virtual void OnDisconnectingLink(LinkEventArgs e) { lock (_OnEventLink_ThreadLock) { Disconnecting?.Invoke(this, e); } }
internal static void WorkOnEmptyBuffer(Object threadContext) { while (true) { LinkEventArgs LinkEA = null; lock (_CallOnEmptyBuffer_Lock) { LinkEA = _CallOnEmptyBufferQueue.Dequeue(); } if (LinkEA.lnk.IsConnected) { LinkEA.lnk.OnEmptyBuffer(LinkEA); } lock (_CallOnEmptyBuffer_Lock) { if (_CallOnEmptyBufferQueue.Count == 0) { IsInOnEmptyBufferQueue = false; break; } } } }
/// <summary> /// Raises an event when a new client is connected. /// </summary> /// <param name="e">Contains the connection link.</param> protected virtual void OnNewLink(LinkEventArgs e) { lock (e.lnk._OnEventLink_ThreadLock) { NewLink?.Invoke(this, e); } }
private bool GetPackets() { SendFound = false; lock (link.SendData_Lock) { if (link.SendDataPortalArrayOUTPUT[0] == null) { return(true); } for (int x = 0; x < link.SendDataPortalArrayOUTPUT.Length; x++) { if (link.SendDataPortalArrayOUTPUT[x].Count > 0) { byteData = link.SendDataPortalArrayOUTPUT[x].Dequeue(); SendFound = true; if (byteData._CallEmpybuffer) { _CallEmptyBuffer = true; } break; } } if (!SendFound) { IsInSendQueue = false; //Debug.WriteLine("no data"); //if _CallEmptyBuffer is set, trigger an event to get more data if (_CallEmptyBuffer) { _CallEmptyBuffer = false; LinkEventArgs args = new LinkEventArgs() { lnk = link }; lock (_CallOnEmptyBuffer_Lock) { _CallOnEmptyBufferQueue.Enqueue(args); } QueueOnEmptyBuffer(); } return(true); } } return(false); }
private void NewEventWorker(object threadContext) { List <Link> LinkListTEMP = GetNewLinkList(); while (LinkListTEMP.Count != 0) { foreach (Link lnk in LinkListTEMP) { LinkEventArgs args = new LinkEventArgs() { lnk = lnk }; OnNewLink(args); } LinkListTEMP = GetNewLinkList(); } }
internal void RemoveFromConnectionList(Connection con) { if (con == null) { return; } lock (_ConnectionList_ThreadLock) { _ConnectionList.Remove(con); LinkEventArgs args = new LinkEventArgs() { lnk = con.link }; OnDisconnectingLink(args); } }
/// <summary> /// Close the connection and free all resources. /// </summary> public void Dispose() { //Debug.WriteLine("Link.Dispose called"); lock (_DisposeLock) { //SendData(); //Debug.WriteLine("Link.Dispose called"); if (Disposed) { //Debug.WriteLine("Link.Dispose abort"); return; } else { Disposed = true; } } Connect.Dispose(); /*lock (_Static_ThreadLock) * { * if (LinkList.Contains(this)) LinkList.Remove(this); * }*/ if (Connect.server != null) { Connect.server.RemoveFromConnectionList(Connect); } lock (SendData_Lock) { for (int x = 0; x < SendDataPortalArray.Length; x++) { if (SendDataPortalArray[x] != null) { SendDataPortalArray[x].Clear(); SendDataPortalArray[x] = null; } } for (int x = 0; x < SendDataPortalArrayOUTPUT.Length; x++) { SendDataPortalArrayOUTPUT[x] = null; } } Connect._PCollection.RemoveDisconectingLinkFromRequest(this); if (!Teardown) { Teardown = true; LinkEventArgs args = new LinkEventArgs() { lnk = this }; //OnDisconnectingLink(args); ThreadPool.QueueUserWorkItem(EventWorker, args); } //Debug.WriteLine("Link.Dispose ended"); }
/// <summary> /// Raises an event if the Buffer of this link is empty. The 'OnEmptybuffer' parameter must set when a packet is send. /// </summary> /// <param name="e">The link connection.</param> protected internal virtual void OnEmptyBuffer(LinkEventArgs e) { EmptyBuffer?.Invoke(this, e); }