private void MessageBuilder() { Boolean threadOk = true; while (_connected && threadOk) { try { byte[] lengthInformation = _buffer.getFromStart(4); long messageDataLength = HTSMessage.uIntToLong(lengthInformation[0], lengthInformation[1], lengthInformation[2], lengthInformation[3]); byte[] messageData = _buffer.extractFromStart((int)messageDataLength + 4); // should be long !!! HTSMessage response = HTSMessage.parse(messageData, _logger); _receivedMessagesQueue.Enqueue(response); } catch (ThreadAbortException) { threadOk = false; Thread.ResetAbort(); } catch (Exception ex) { if (_listener != null) { _listener.onError(ex); } else { _logger.ErrorException("[TVHclient] MessageBuilder caught exception : {0} but no error listener is configured!!!", ex, ex.ToString()); } } } }
private void MessageBuilder() { Boolean threadOk = true; while (_connected && threadOk) { if (_messageBuilderThreadTokenSource.IsCancellationRequested) { return; } try { byte[] lengthInformation = _buffer.getFromStart(4); long messageDataLength = HTSMessage.uIntToLong(lengthInformation[0], lengthInformation[1], lengthInformation[2], lengthInformation[3]); byte[] messageData = _buffer.extractFromStart((int)messageDataLength + 4); // should be long !!! HTSMessage response = HTSMessage.parse(messageData, _loggerFactory.CreateLogger <HTSMessage>()); _receivedMessagesQueue.Enqueue(response); } catch (Exception ex) { threadOk = false; if (_listener != null) { _listener.onError(ex); } else { _logger.LogError(ex, "[TVHclient] HTSConnectionAsync.MessageBuilder: exception caught, but no error listener is configured"); } } } }
/** * <p>notifyActionEvent.</p> * * @param type a {@link iqq.im.evt.QQActionEvent.Type} object. * @param target a {@link java.lang.Object} object. */ public void notifyActionEvent(QQActionEvent.Type type, Object target) { QQActionEvent evt = new QQActionEvent(type, target, this); if (proxyListener != null) { proxyListener(evt); } evtQueue.Enqueue(evt); }
public void Close() { try { if (BufferedWrite) { Send(WebSocketMessage.Create(new byte[0], Opcode.Close, MaskOutgoing)); } else { SendReal(WebSocketMessage.Create(new byte[0], Opcode.Close, MaskOutgoing).Serialize()); } } catch { } Closed = true; Client.Close(); // unblock external Receive() calls ReceiveQueue.Enqueue(new byte[0]); }
public void Send(byte[] raw) { try { if (BufferedWrite) { SendQueue.Enqueue(raw); } else { SendReal(raw); } } catch { Close(); } }
public void sendMessage(HTSMessage message, HTSResponseHandler responseHandler) { // loop the sequence number if (_seq == int.MaxValue) { _seq = int.MinValue; } else { _seq++; } // housekeeping very old response handlers if (_responseHandlers.ContainsKey(_seq)) { _responseHandlers.Remove(_seq); } message.putField("seq", _seq); _messagesForSendQueue.Enqueue(message); _responseHandlers.Add(_seq, responseHandler); }
static void Main() { Thread.CurrentThread.Name = "Reader"; Thread writer = new Thread(WriterLoop); writer.Name = "Writer"; var queue = new SizeQueue <int>(100); writer.Start(queue); // reader loop - note this can run parallel // to the writer for (int i = 0; i < 100; i++) { if (i % 10 == 9) { Write(i); } queue.Enqueue(i); Thread.Sleep(5); // pretend it takes time } queue.Close(); Write("exiting"); }
public void AddPrintItem(string item) { printQueue.Enqueue(item); }
public void handleResponse(HTSMessage response) { _responseDataQueue.Enqueue(response); }
public bool OnReceiveData(object packet) { return(queue.Enqueue(packet as IAVFrame)); }
private void ReceiveLoop() { WebSocketMessage message = new WebSocketMessage(); while (Client.Connected && !Closed) { try { var result = WebSocketMessage.FromStream(message, NetworkStream); if (result == null) { Close(); return; } if (message.Final) { if (FragmentStart != null) { if (message.Opcode != Opcode.Continuation) { // control message } else { FragmentBuffer.Write(message.Payload, 0, message.Payload.Length); if (OnDataReceived != null) { OnDataReceived(this, FragmentStart, FragmentBuffer.ToArray()); } ReceiveQueue.Enqueue(FragmentBuffer.ToArray()); FragmentStart = null; FragmentBuffer.SetLength(0); } } else { switch (message.Opcode) { case Opcode.Binary: case Opcode.Text: ReceiveQueue.Enqueue(message.Payload); if (OnDataReceived != null) { OnDataReceived(this, message, message.Payload); } break; case Opcode.Ping: Send(WebSocketMessage.Create(message.Payload, Opcode.Pong, MaskOutgoing)); Log.Info("Received ping"); break; case Opcode.Pong: Log.Info("Received pong"); break; case Opcode.Close: Send(WebSocketMessage.Create(new byte[0], Opcode.Close, MaskOutgoing)); Close(); Log.Info("Received WebSocket close, disconnected"); return; } } } else { if (FragmentStart == null) { // start receiving a fragment FragmentStart = message; FragmentBuffer.SetLength(0); FragmentBuffer.Write(message.Payload, 0, message.Payload.Length); } else { if (message.Opcode != Opcode.Continuation) { // illegal } else { FragmentBuffer.Write(message.Payload, 0, message.Payload.Length); } } } } catch (Exception ex) { Log.Error(ex); Close(); } } }