private void DoSend(ByteBuf buf) { try { isSending = true; socket.BeginSend(buf.buf, 0, buf.len, SocketFlags.None, asyncResult => { try { int l = socket.EndSend(asyncResult); buf.Dispose(); isSending = false; }catch (Exception ex) { buf.Dispose(); isSending = false; OnError(ex.Message); } }, null); }catch (Exception ex) { buf.Dispose(); isSending = false; OnError(ex.Message); } }
public static ByteBuf Reserve(ByteBuf src, int len) { ByteBuf dst = Alloc(len); if (dst.maxSize == src.maxSize) { throw new Exception("Bytebuf reserve already to maxsize"); } System.Buffer.BlockCopy(src.buf, 0, dst.buf, 0, src.len); dst.len = src.len; src.Dispose(); return(dst); }
protected ByteBuf EncodeAndPackage(Protocol p) { ByteBuf buf = p.Serialize(); ByteBuf zip = SimpleZlibExt.Zip(buf); //ByteBuf zip = DotNetZlibExt.ZipUnsafe(buf); ByteBuf ret = ByteCache.Alloc(zip.len + 4); ret.Write(zip.len, 0); ret.len = 4; ret.Append(zip); buf.Dispose(); zip.Dispose(); return(ret); }
protected Protocol Decode(ByteBuf raw) { ByteBuf data = SimpleZlibExt.Unzip(raw); //ByteBuf data = DotNetZlibExt.UnzipUnsafe(raw); int prtclType = data.GetInt(0); Protocol p = ProtocolMapping.Instance.CreatePrtcl(prtclType); if (null != p) { p.Deserialize(data, 4, data.len - 4); } raw.Dispose(); data.Dispose(); return(p); }