Ejemplo n.º 1
0
        public async Task <ReceivedWapMessage> CallMethod(IWapMessage msg, CancellationToken ct = default(CancellationToken))
        {
            MethodCall call = new MethodCall();

            call.Messsage = msg;
            var hdlr = ct.Register(call.CompletionSource.SetCanceled);
            await _methodCalls.Add(msg.SequenceNumber, call, ct);

            try
            {
                await SendMesssage(msg);

                var ret = await call.CompletionSource.Task;
                return(ret);
            }
            finally
            {
                hdlr.Dispose();
                await _methodCalls.Remove(msg.SequenceNumber); // cancellation ignored as we usually get here when the task is cancelled already but we still want to remove the call
            }
        }
        protected async Task <bool> SendMesssage(IWapMessage msg)
        {
            if (!Running)
            {
                return(false);
            }

            List <byte> sendList = new List <byte>();

            sendList.Add(StartByte);
            sendList.AddRange(EscapeBytes(msg.GetBytes()));
            sendList.Add(EndByte);

            await _txSem.WaitAsync().ConfigureAwait(false);

            await _stream.WriteAsync(sendList.ToArray(), 0, sendList.Count).ConfigureAwait(false);

            await _stream.FlushAsync().ConfigureAwait(false);

            _txSem.Release();

            return(true);
        }
Ejemplo n.º 3
0
 public Task <bool> SendEventMessage(IWapMessage msg)
 {
     return(SendMesssage(msg));
 }