protected override bool ReleaseHandle()
            {
                try
                {
                    // We are in a finalizer thread at the end of the App and the finalization of the dynamically loaded ZLib happend
                    // to be scheduled first. In such case we have no hope of properly freeing zStream. If the process is dying - we
                    // do not care. In other cases somethign went badly wrong anyway:
                    if (zlibLibraryHandle == null || zlibLibraryHandle.IsInvalid)
                    {
                        return(false);
                    }

                    switch (InitializationState)
                    {
                    case State.NotInitialized:        return(true);

                    case State.InitializedForDeflate: return(DeflateEnd() == ZLibNative.ErrorCode.Ok);

                    case State.InitializedForInflate: return(InflateEnd() == ZLibNative.ErrorCode.Ok);

                    case State.Disposed:              return(true);

                    default: return(false);  // This should never happen. Did we forget one of the State enum values in the switch?
                    }
                }
                finally
                {
                    if (zStreamPtr != null)
                    {
                        Marshal.FreeHGlobal((IntPtr)zStreamPtr);
                        zStreamPtr = null;
                    }
                }
            }
            public ZLibStreamHandle()

                : base(true)
            {
                zStreamPtr = (ZStream *)AllocWithZeroOut(sizeof(ZStream));
                this.initializationState = State.NotInitialized;
                this.handle = IntPtr.Zero;
            }
Exemple #3
0
 public static unsafe extern Constants.RetCode inflateEnd(ZStream *strm);
Exemple #4
0
 public static unsafe Constants.RetCode InflateInit2(ZStream *strm, int windowBits)
 {
     return(inflateInit2_(strm, windowBits, zlibVersion(), sizeof(ZStream)));
 }
Exemple #5
0
 public static unsafe extern Constants.RetCode inflate(ZStream *strm, Constants.Flush flush);
Exemple #6
0
 public static unsafe Constants.RetCode DeflateInit2(ZStream *strm, int level, int method, int windowBits,
                                                     int memLevel, Constants.Strategy strategy)
 {
     return(deflateInit2_(strm, level, method, windowBits, memLevel, strategy, zlibVersion(), sizeof(ZStream)));
 }
Exemple #7
0
 private static unsafe extern Constants.RetCode inflateInit2_(ZStream *strm, int windowBits, byte *version, int streamSize);
Exemple #8
0
 private static unsafe extern Constants.RetCode deflateInit2_(ZStream *strm, int level, int method, int windowBits,
                                                              int memLevel, Constants.Strategy strategy, byte *version, int streamSize);
Exemple #9
0
 public static extern unsafe Constants.RetCode deflate(ZStream *strm, Constants.Flush flush);
Exemple #10
0
 public static extern unsafe Constants.RetCode deflateEnd(ZStream *strm);