Example #1
0
        private static IPAddress PtrToAddress(IntPtr ptr)
        {
            IPAddress address = null;

            if (ptr != IntPtr.Zero)
            {
                IntPtr buf     = Stdlib.malloc(256);
                IntPtr addrPtr = avahi_address_snprint(buf, 256, ptr);
                address = IPAddress.Parse(GLib.Marshaller.Utf8PtrToString(addrPtr));

                Stdlib.free(addrPtr);
            }

            return(address);
        }
Example #2
0
        private BPSEvent(int domain, uint code, BPSEventPayload payload, Action <BPSEvent> completionFunction, bool recordCompletion)
            : this(IntPtr.Zero, true)
        {
            if (domain < 0 || domain > BPS_EVENT_DOMAIN_MAX)
            {
                throw new ArgumentOutOfRangeException("domain", domain, "0 <= domain < BPS_EVENT_DOMAIN_MAX");
            }
            if (code > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException("code", code, "0 <= code < UInt16.MaxValue");
            }
            Util.GetBPSOrException();
            var payloadPtr = payload.GetDataPointer();
            var success    = bps_event_create(out handle, (uint)domain, code, payloadPtr, EventCompletion) != BPS.BPS_SUCCESS;

            if (payloadPtr != IntPtr.Zero)
            {
                if (!success)
                {
                    BPSEventPayload.FreeDataPointer(payloadPtr);
                }
                Stdlib.free(payloadPtr);
            }
            if (success)
            {
                if (recordCompletion)
                {
                    handleToCallback.Add(handle, completionFunction);
                }
            }
            else
            {
                Util.ThrowExceptionForLastErrno();
            }
            IsDisposable = true;
        }
Example #3
0
 public static void FreeHeap(IntPtr ptr)
 {
     Stdlib.free(ptr);
 }