Example #1
0
		public void RepackXml(XElement data, Stream destination)
		{
			using(var compressed = destination.Compress(true))
			using(var writer = XmlDictionaryWriter.CreateBinaryWriter(compressed, null, null, false))
			{
				data.Save(writer);
				writer.Flush();
				compressed.Flush();
			}
		}
Example #2
0
		public void Serialize(object instance, Stream destination)
		{
			var serializer = GetXmlSerializer(instance.GetType());

			using(var compressed = destination.Compress(true))
			using(var writer = XmlDictionaryWriter.CreateBinaryWriter(compressed, null, null, false))
			{
				serializer.WriteObject(writer, instance);
			}
		}
Example #3
0
        private bool send(Opcode opcode, Stream stream)
        {
            lock (_forSend)
              {
            var sent = false;

            var src = stream;
            var compressed = false;
            try {
              if (_compression != CompressionMethod.NONE)
              {
            stream = stream.Compress (_compression);
            compressed = true;
              }

              sent = sendFragmented (opcode, stream, _client ? Mask.MASK : Mask.UNMASK, compressed);
            }
            catch (Exception ex) {
              _logger.Fatal (ex.ToString ());
              error ("An exception has occurred.");
            }
            finally {
              if (compressed)
            stream.Dispose ();

              src.Dispose ();
            }

            return sent;
              }
        }
Example #4
0
        // As server, used to broadcast
        internal void Send(Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
        {
            lock (_forSend)
              {
            try {
              Stream cached;
              if (!cache.TryGetValue (_compression, out cached))
              {
            cached = stream.Compress (_compression);
            cache.Add (_compression, cached);
              }
              else
            cached.Position = 0;

              sendFragmented (opcode, cached, Mask.UNMASK, _compression != CompressionMethod.NONE);
            }
            catch (Exception ex) {
              _logger.Fatal (ex.ToString ());
              error ("An exception has occurred.");
            }
              }
        }
Example #5
0
    // As server, used to broadcast
    internal void Send (Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
    {
      lock (_forSend) {
        try {
          Stream cached;
          if (!cache.TryGetValue (_compression, out cached)) {
            cached = stream.Compress (_compression);
            cache.Add (_compression, cached);
          }
          else {
            cached.Position = 0;
          }

          send (opcode, cached, _compression != CompressionMethod.None);
        }
        catch (Exception ex) {
          _logger.Fatal (ex.ToString ());
        }
      }
    }
Example #6
0
    private bool send (Opcode opcode, Stream stream)
    {
      lock (_forSend) {
        var src = stream;
        var compressed = false;
        var sent = false;
        try {
          if (_compression != CompressionMethod.None) {
            stream = stream.Compress (_compression);
            compressed = true;
          }

          sent = send (opcode, stream, compressed);
          if (!sent)
            error ("The sending has been interrupted.", null);
        }
        catch (Exception ex) {
          _logger.Fatal (ex.ToString ());
          error ("An exception has occurred while sending the data.", ex);
        }
        finally {
          if (compressed)
            stream.Dispose ();

          src.Dispose ();
        }

        return sent;
      }
    }
Example #7
0
        // As server, used to broadcast
        internal void Send(Opcode opcode, Stream stream, Dictionary <CompressionMethod, Stream> cache)
        {
            lock (_forSend) {
            try {
              Stream cached;
              if (!cache.TryGetValue (_compression, out cached)) {
            cached = stream.Compress (_compression);
            cache.Add (_compression, cached);
              }
              else
            cached.Position = 0;

              if (_readyState == WebSocketState.Open)
            sendFragmented (opcode, cached, Mask.Unmask, _compression != CompressionMethod.None);
            }
            catch (Exception ex) {
              _logger.Fatal (ex.ToString ());
              error ("An exception has occurred while sending a data.");
            }
              }
        }
        private bool send(Opcode opcode, Stream stream)
        {
            lock (_forSend)
            {
                var src = stream;
                var compressed = false;
                var sent = false;
                try
                {
                    if (_compression != CompressionMethod.None)
                    {
                        stream = stream.Compress(_compression);
                        compressed = true;
                    }

                    sent = send(opcode, Mask.Unmask, stream, compressed);
                    if (!sent)
                        error("Sending a data has been interrupted.");
                }
                catch (Exception ex)
                {
                    error("An exception has occurred while sending a data.", ex);
                }
                finally
                {
                    if (compressed)
                        stream.Dispose();

                    src.Dispose();
                }

                return sent;
            }
        }
Example #9
0
        private void send(Opcode opcode, Stream stream)
        {
            if (_compression == CompressionMethod.NONE || _perFrameCompress) {
                send(opcode, stream, false);
                return;
            }

            using (var compressed = stream.Compress(_compression)) {
                send(opcode, compressed, true);
            }
        }
Example #10
0
        // As server, used to broadcast
        internal void Send(Opcode opcode, Stream stream, Dictionary<CompressionMethod, Stream> cache)
        {
            lock (_forSend)
            {
                try
                {
                    Stream found;
                    if (!cache.TryGetValue(_compression, out found))
                    {
                        found = stream.Compress(_compression);
                        cache.Add(_compression, found);
                    }
                    else
                    {
                        found.Position = 0;
                    }

                    send(opcode, found, _compression != CompressionMethod.None);
                }
                catch (Exception ex)
                {
#if COMPAT
                    Log.Error(ex.ToString());
#else
                    ex.Log();
#endif
                }
            }
        }