    {- |
    Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
    License    : LGPL-2.1
    Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

    This is the subclass of 'GI.Gio.Objects.SocketConnection.SocketConnection' that is created
    for UNIX domain sockets.

    It contains functions to do some of the UNIX socket specific
    functionality like passing file descriptors.

    Note that @\<gio\/gunixconnection.h>@ belongs to the UNIX-specific
    GIO interfaces, thus you have to use the @gio-unix-2.0.pc@
    pkg-config file when using it.

    /Since: 2.22/
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Gio.Objects.UnixConnection
        (

    -- * Exported types
        UnixConnection(..)                      ,
        IsUnixConnection                        ,
        toUnixConnection                        ,
        noUnixConnection                        ,

     -- * Methods
    -- ** receiveCredentials #method:receiveCredentials#

    #if ENABLE_OVERLOADING
        UnixConnectionReceiveCredentialsMethodInfo,
    #endif
        unixConnectionReceiveCredentials        ,

    -- ** receiveCredentialsAsync #method:receiveCredentialsAsync#

    #if ENABLE_OVERLOADING
        UnixConnectionReceiveCredentialsAsyncMethodInfo,
    #endif
        unixConnectionReceiveCredentialsAsync   ,

    -- ** receiveCredentialsFinish #method:receiveCredentialsFinish#

    #if ENABLE_OVERLOADING
        UnixConnectionReceiveCredentialsFinishMethodInfo,
    #endif
        unixConnectionReceiveCredentialsFinish  ,

    -- ** receiveFd #method:receiveFd#

    #if ENABLE_OVERLOADING
        UnixConnectionReceiveFdMethodInfo       ,
    #endif
        unixConnectionReceiveFd                 ,

    -- ** sendCredentials #method:sendCredentials#

    #if ENABLE_OVERLOADING
        UnixConnectionSendCredentialsMethodInfo ,
    #endif
        unixConnectionSendCredentials           ,

    -- ** sendCredentialsAsync #method:sendCredentialsAsync#

    #if ENABLE_OVERLOADING
        UnixConnectionSendCredentialsAsyncMethodInfo,
    #endif
        unixConnectionSendCredentialsAsync      ,

    -- ** sendCredentialsFinish #method:sendCredentialsFinish#

    #if ENABLE_OVERLOADING
        UnixConnectionSendCredentialsFinishMethodInfo,
    #endif
        unixConnectionSendCredentialsFinish     ,

    -- ** sendFd #method:sendFd#

    #if ENABLE_OVERLOADING
        UnixConnectionSendFdMethodInfo          ,
    #endif
        unixConnectionSendFd                    ,

        ) where

    import Data.GI.Base.ShortPrelude
    import qualified Data.GI.Base.ShortPrelude as SP
    import qualified Data.GI.Base.Overloading as O
    import qualified Prelude as P

    import qualified Data.GI.Base.Attributes as GI.Attributes
    import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
    import qualified Data.GI.Base.GError as B.GError
    import qualified Data.GI.Base.GVariant as B.GVariant
    import qualified Data.GI.Base.GValue as B.GValue
    import qualified Data.GI.Base.GParamSpec as B.GParamSpec
    import qualified Data.GI.Base.CallStack as B.CallStack
    import qualified Data.Text as T
    import qualified Data.ByteString.Char8 as B
    import qualified Data.Map as Map
    import qualified Foreign.Ptr as FP

    import qualified GI.GObject.Objects.Object as GObject.Object
    import qualified GI.Gio.Callbacks as Gio.Callbacks
    import {-# SOURCE #-} qualified GI.Gio.Interfaces.AsyncResult as Gio.AsyncResult
    import {-# SOURCE #-} qualified GI.Gio.Objects.Cancellable as Gio.Cancellable
    import {-# SOURCE #-} qualified GI.Gio.Objects.Credentials as Gio.Credentials
    import {-# SOURCE #-} qualified GI.Gio.Objects.IOStream as Gio.IOStream
    import {-# SOURCE #-} qualified GI.Gio.Objects.SocketConnection as Gio.SocketConnection

    -- | Memory-managed wrapper type.
    newtype UnixConnection = UnixConnection (ManagedPtr UnixConnection)
    foreign import ccall "g_unix_connection_get_type"
        c_g_unix_connection_get_type :: IO GType

    instance GObject UnixConnection where
        gobjectType _ = c_g_unix_connection_get_type

    -- | Type class for types which can be safely cast to `UnixConnection`, for instance with `toUnixConnection`.
    class GObject o => IsUnixConnection o
    #if MIN_VERSION_base(4,9,0)
    instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError UnixConnection a) =>
        IsUnixConnection a
    #endif
    instance IsUnixConnection UnixConnection
    instance Gio.SocketConnection.IsSocketConnection UnixConnection
    instance Gio.IOStream.IsIOStream UnixConnection
    instance GObject.Object.IsObject UnixConnection

    -- | Cast to `UnixConnection`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
    toUnixConnection :: (MonadIO m, IsUnixConnection o) => o -> m UnixConnection
    toUnixConnection = liftIO . unsafeCastTo UnixConnection

    -- | A convenience alias for `Nothing` :: `Maybe` `UnixConnection`.
    noUnixConnection :: Maybe UnixConnection
    noUnixConnection = Nothing

    #if ENABLE_OVERLOADING
    type family ResolveUnixConnectionMethod (t :: Symbol) (o :: *) :: * where
        ResolveUnixConnectionMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
        ResolveUnixConnectionMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
        ResolveUnixConnectionMethod "clearPending" o = Gio.IOStream.IOStreamClearPendingMethodInfo
        ResolveUnixConnectionMethod "close" o = Gio.IOStream.IOStreamCloseMethodInfo
        ResolveUnixConnectionMethod "closeAsync" o = Gio.IOStream.IOStreamCloseAsyncMethodInfo
        ResolveUnixConnectionMethod "closeFinish" o = Gio.IOStream.IOStreamCloseFinishMethodInfo
        ResolveUnixConnectionMethod "connect" o = Gio.SocketConnection.SocketConnectionConnectMethodInfo
        ResolveUnixConnectionMethod "connectAsync" o = Gio.SocketConnection.SocketConnectionConnectAsyncMethodInfo
        ResolveUnixConnectionMethod "connectFinish" o = Gio.SocketConnection.SocketConnectionConnectFinishMethodInfo
        ResolveUnixConnectionMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
        ResolveUnixConnectionMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
        ResolveUnixConnectionMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
        ResolveUnixConnectionMethod "hasPending" o = Gio.IOStream.IOStreamHasPendingMethodInfo
        ResolveUnixConnectionMethod "isClosed" o = Gio.IOStream.IOStreamIsClosedMethodInfo
        ResolveUnixConnectionMethod "isConnected" o = Gio.SocketConnection.SocketConnectionIsConnectedMethodInfo
        ResolveUnixConnectionMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
        ResolveUnixConnectionMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
        ResolveUnixConnectionMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
        ResolveUnixConnectionMethod "receiveCredentials" o = UnixConnectionReceiveCredentialsMethodInfo
        ResolveUnixConnectionMethod "receiveCredentialsAsync" o = UnixConnectionReceiveCredentialsAsyncMethodInfo
        ResolveUnixConnectionMethod "receiveCredentialsFinish" o = UnixConnectionReceiveCredentialsFinishMethodInfo
        ResolveUnixConnectionMethod "receiveFd" o = UnixConnectionReceiveFdMethodInfo
        ResolveUnixConnectionMethod "ref" o = GObject.Object.ObjectRefMethodInfo
        ResolveUnixConnectionMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
        ResolveUnixConnectionMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
        ResolveUnixConnectionMethod "sendCredentials" o = UnixConnectionSendCredentialsMethodInfo
        ResolveUnixConnectionMethod "sendCredentialsAsync" o = UnixConnectionSendCredentialsAsyncMethodInfo
        ResolveUnixConnectionMethod "sendCredentialsFinish" o = UnixConnectionSendCredentialsFinishMethodInfo
        ResolveUnixConnectionMethod "sendFd" o = UnixConnectionSendFdMethodInfo
        ResolveUnixConnectionMethod "spliceAsync" o = Gio.IOStream.IOStreamSpliceAsyncMethodInfo
        ResolveUnixConnectionMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
        ResolveUnixConnectionMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
        ResolveUnixConnectionMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
        ResolveUnixConnectionMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
        ResolveUnixConnectionMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
        ResolveUnixConnectionMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
        ResolveUnixConnectionMethod "getInputStream" o = Gio.IOStream.IOStreamGetInputStreamMethodInfo
        ResolveUnixConnectionMethod "getLocalAddress" o = Gio.SocketConnection.SocketConnectionGetLocalAddressMethodInfo
        ResolveUnixConnectionMethod "getOutputStream" o = Gio.IOStream.IOStreamGetOutputStreamMethodInfo
        ResolveUnixConnectionMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
        ResolveUnixConnectionMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
        ResolveUnixConnectionMethod "getRemoteAddress" o = Gio.SocketConnection.SocketConnectionGetRemoteAddressMethodInfo
        ResolveUnixConnectionMethod "getSocket" o = Gio.SocketConnection.SocketConnectionGetSocketMethodInfo
        ResolveUnixConnectionMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
        ResolveUnixConnectionMethod "setPending" o = Gio.IOStream.IOStreamSetPendingMethodInfo
        ResolveUnixConnectionMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
        ResolveUnixConnectionMethod l o = O.MethodResolutionFailed l o

    instance (info ~ ResolveUnixConnectionMethod t UnixConnection, O.MethodInfo info UnixConnection p) => O.IsLabelProxy t (UnixConnection -> p) where
        fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

    #if MIN_VERSION_base(4,9,0)
    instance (info ~ ResolveUnixConnectionMethod t UnixConnection, O.MethodInfo info UnixConnection p) => O.IsLabel t (UnixConnection -> p) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
    #else
        fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
    #endif
    #endif

    #endif

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList UnixConnection
    type instance O.AttributeList UnixConnection = UnixConnectionAttributeList
    type UnixConnectionAttributeList = ('[ '("closed", Gio.IOStream.IOStreamClosedPropertyInfo), '("inputStream", Gio.IOStream.IOStreamInputStreamPropertyInfo), '("outputStream", Gio.IOStream.IOStreamOutputStreamPropertyInfo), '("socket", Gio.SocketConnection.SocketConnectionSocketPropertyInfo)] :: [(Symbol, *)])
    #endif

    #if ENABLE_OVERLOADING
    #endif

    #if ENABLE_OVERLOADING
    type instance O.SignalList UnixConnection = UnixConnectionSignalList
    type UnixConnectionSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

    #endif

    -- method UnixConnection::receive_credentials
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixConnection.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A #GCancellable or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "Gio", name = "Credentials"}))
    -- throws : True
    -- Skip return : False

    foreign import ccall "g_unix_connection_receive_credentials" g_unix_connection_receive_credentials ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
        Ptr (Ptr GError) ->                     -- error
        IO (Ptr Gio.Credentials.Credentials)

    {- |
    Receives credentials from the sending end of the connection.  The
    sending end has to call 'GI.Gio.Objects.UnixConnection.unixConnectionSendCredentials' (or
    similar) for this to work.

    As well as reading the credentials this also reads (and discards) a
    single byte from the stream, as this is required for credentials
    passing to work on some implementations.

    Other ways to exchange credentials with a foreign peer includes the
    'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage' type and 'GI.Gio.Objects.Socket.socketGetCredentials' function.

    /Since: 2.26/
    -}
    unixConnectionReceiveCredentials ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) =>
        a
        {- ^ /@connection@/: A 'GI.Gio.Objects.UnixConnection.UnixConnection'. -}
        -> Maybe (b)
        {- ^ /@cancellable@/: A 'GI.Gio.Objects.Cancellable.Cancellable' or 'Nothing'. -}
        -> m Gio.Credentials.Credentials
        {- ^ __Returns:__ Received credentials on success (free with
    'GI.GObject.Objects.Object.objectUnref'), 'Nothing' if /@error@/ is set. /(Can throw 'Data.GI.Base.GError.GError')/ -}
    unixConnectionReceiveCredentials connection cancellable = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        maybeCancellable <- case cancellable of
            Nothing -> return nullPtr
            Just jCancellable -> do
                jCancellable' <- unsafeManagedPtrCastPtr jCancellable
                return jCancellable'
        onException (do
            result <- propagateGError $ g_unix_connection_receive_credentials connection' maybeCancellable
            checkUnexpectedReturnNULL "unixConnectionReceiveCredentials" result
            result' <- (wrapObject Gio.Credentials.Credentials) result
            touchManagedPtr connection
            whenJust cancellable touchManagedPtr
            return result'
         ) (do
            return ()
         )

    #if ENABLE_OVERLOADING
    data UnixConnectionReceiveCredentialsMethodInfo
    instance (signature ~ (Maybe (b) -> m Gio.Credentials.Credentials), MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) => O.MethodInfo UnixConnectionReceiveCredentialsMethodInfo a signature where
        overloadedMethod _ = unixConnectionReceiveCredentials

    #endif

    -- method UnixConnection::receive_credentials_async
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixConnection.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "optional #GCancellable object, %NULL to ignore.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback to call when the request is satisfied", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the data to pass to callback function", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_unix_connection_receive_credentials_async" g_unix_connection_receive_credentials_async ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
        FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
        Ptr () ->                               -- user_data : TBasicType TPtr
        IO ()

    {- |
    Asynchronously receive credentials.

    For more details, see 'GI.Gio.Objects.UnixConnection.unixConnectionReceiveCredentials' which is
    the synchronous version of this call.

    When the operation is finished, /@callback@/ will be called. You can then call
    'GI.Gio.Objects.UnixConnection.unixConnectionReceiveCredentialsFinish' to get the result of the operation.

    /Since: 2.32/
    -}
    unixConnectionReceiveCredentialsAsync ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) =>
        a
        {- ^ /@connection@/: A 'GI.Gio.Objects.UnixConnection.UnixConnection'. -}
        -> Maybe (b)
        {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore. -}
        -> Maybe (Gio.Callbacks.AsyncReadyCallback)
        {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' to call when the request is satisfied -}
        -> m ()
    unixConnectionReceiveCredentialsAsync connection cancellable callback = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        maybeCancellable <- case cancellable of
            Nothing -> return nullPtr
            Just jCancellable -> do
                jCancellable' <- unsafeManagedPtrCastPtr jCancellable
                return jCancellable'
        maybeCallback <- case callback of
            Nothing -> return (castPtrToFunPtr nullPtr)
            Just jCallback -> do
                ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
                jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
                poke ptrcallback jCallback'
                return jCallback'
        let userData = nullPtr
        g_unix_connection_receive_credentials_async connection' maybeCancellable maybeCallback userData
        touchManagedPtr connection
        whenJust cancellable touchManagedPtr
        return ()

    #if ENABLE_OVERLOADING
    data UnixConnectionReceiveCredentialsAsyncMethodInfo
    instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) => O.MethodInfo UnixConnectionReceiveCredentialsAsyncMethodInfo a signature where
        overloadedMethod _ = unixConnectionReceiveCredentialsAsync

    #endif

    -- method UnixConnection::receive_credentials_finish
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixConnection.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GAsyncResult.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "Gio", name = "Credentials"}))
    -- throws : True
    -- Skip return : False

    foreign import ccall "g_unix_connection_receive_credentials_finish" g_unix_connection_receive_credentials_finish ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
        Ptr (Ptr GError) ->                     -- error
        IO (Ptr Gio.Credentials.Credentials)

    {- |
    Finishes an asynchronous receive credentials operation started with
    'GI.Gio.Objects.UnixConnection.unixConnectionReceiveCredentialsAsync'.

    /Since: 2.32/
    -}
    unixConnectionReceiveCredentialsFinish ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.AsyncResult.IsAsyncResult b) =>
        a
        {- ^ /@connection@/: A 'GI.Gio.Objects.UnixConnection.UnixConnection'. -}
        -> b
        {- ^ /@result@/: a 'GI.Gio.Interfaces.AsyncResult.AsyncResult'. -}
        -> m Gio.Credentials.Credentials
        {- ^ __Returns:__ a 'GI.Gio.Objects.Credentials.Credentials', or 'Nothing' on error.
        Free the returned object with 'GI.GObject.Objects.Object.objectUnref'. /(Can throw 'Data.GI.Base.GError.GError')/ -}
    unixConnectionReceiveCredentialsFinish connection result_ = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        result_' <- unsafeManagedPtrCastPtr result_
        onException (do
            result <- propagateGError $ g_unix_connection_receive_credentials_finish connection' result_'
            checkUnexpectedReturnNULL "unixConnectionReceiveCredentialsFinish" result
            result' <- (wrapObject Gio.Credentials.Credentials) result
            touchManagedPtr connection
            touchManagedPtr result_
            return result'
         ) (do
            return ()
         )

    #if ENABLE_OVERLOADING
    data UnixConnectionReceiveCredentialsFinishMethodInfo
    instance (signature ~ (b -> m Gio.Credentials.Credentials), MonadIO m, IsUnixConnection a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo UnixConnectionReceiveCredentialsFinishMethodInfo a signature where
        overloadedMethod _ = unixConnectionReceiveCredentialsFinish

    #endif

    -- method UnixConnection::receive_fd
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GUnixConnection", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "optional #GCancellable object, %NULL to ignore", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TInt)
    -- throws : True
    -- Skip return : False

    foreign import ccall "g_unix_connection_receive_fd" g_unix_connection_receive_fd ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
        Ptr (Ptr GError) ->                     -- error
        IO Int32

    {- |
    Receives a file descriptor from the sending end of the connection.
    The sending end has to call 'GI.Gio.Objects.UnixConnection.unixConnectionSendFd' for this
    to work.

    As well as reading the fd this also reads a single byte from the
    stream, as this is required for fd passing to work on some
    implementations.

    /Since: 2.22/
    -}
    unixConnectionReceiveFd ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) =>
        a
        {- ^ /@connection@/: a 'GI.Gio.Objects.UnixConnection.UnixConnection' -}
        -> Maybe (b)
        {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore -}
        -> m Int32
        {- ^ __Returns:__ a file descriptor on success, -1 on error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
    unixConnectionReceiveFd connection cancellable = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        maybeCancellable <- case cancellable of
            Nothing -> return nullPtr
            Just jCancellable -> do
                jCancellable' <- unsafeManagedPtrCastPtr jCancellable
                return jCancellable'
        onException (do
            result <- propagateGError $ g_unix_connection_receive_fd connection' maybeCancellable
            touchManagedPtr connection
            whenJust cancellable touchManagedPtr
            return result
         ) (do
            return ()
         )

    #if ENABLE_OVERLOADING
    data UnixConnectionReceiveFdMethodInfo
    instance (signature ~ (Maybe (b) -> m Int32), MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) => O.MethodInfo UnixConnectionReceiveFdMethodInfo a signature where
        overloadedMethod _ = unixConnectionReceiveFd

    #endif

    -- method UnixConnection::send_credentials
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixConnection.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "A #GCancellable or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : True
    -- Skip return : False

    foreign import ccall "g_unix_connection_send_credentials" g_unix_connection_send_credentials ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
        Ptr (Ptr GError) ->                     -- error
        IO CInt

    {- |
    Passes the credentials of the current user the receiving side
    of the connection. The receiving end has to call
    'GI.Gio.Objects.UnixConnection.unixConnectionReceiveCredentials' (or similar) to accept the
    credentials.

    As well as sending the credentials this also writes a single NUL
    byte to the stream, as this is required for credentials passing to
    work on some implementations.

    Other ways to exchange credentials with a foreign peer includes the
    'GI.Gio.Objects.UnixCredentialsMessage.UnixCredentialsMessage' type and 'GI.Gio.Objects.Socket.socketGetCredentials' function.

    /Since: 2.26/
    -}
    unixConnectionSendCredentials ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) =>
        a
        {- ^ /@connection@/: A 'GI.Gio.Objects.UnixConnection.UnixConnection'. -}
        -> Maybe (b)
        {- ^ /@cancellable@/: A 'GI.Gio.Objects.Cancellable.Cancellable' or 'Nothing'. -}
        -> m ()
        {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
    unixConnectionSendCredentials connection cancellable = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        maybeCancellable <- case cancellable of
            Nothing -> return nullPtr
            Just jCancellable -> do
                jCancellable' <- unsafeManagedPtrCastPtr jCancellable
                return jCancellable'
        onException (do
            _ <- propagateGError $ g_unix_connection_send_credentials connection' maybeCancellable
            touchManagedPtr connection
            whenJust cancellable touchManagedPtr
            return ()
         ) (do
            return ()
         )

    #if ENABLE_OVERLOADING
    data UnixConnectionSendCredentialsMethodInfo
    instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) => O.MethodInfo UnixConnectionSendCredentialsMethodInfo a signature where
        overloadedMethod _ = unixConnectionSendCredentials

    #endif

    -- method UnixConnection::send_credentials_async
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixConnection.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "optional #GCancellable object, %NULL to ignore.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback to call when the request is satisfied", sinceVersion = Nothing}, argScope = ScopeTypeAsync, argClosure = 3, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "user_data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the data to pass to callback function", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_unix_connection_send_credentials_async" g_unix_connection_send_credentials_async ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
        FunPtr Gio.Callbacks.C_AsyncReadyCallback -> -- callback : TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"})
        Ptr () ->                               -- user_data : TBasicType TPtr
        IO ()

    {- |
    Asynchronously send credentials.

    For more details, see 'GI.Gio.Objects.UnixConnection.unixConnectionSendCredentials' which is
    the synchronous version of this call.

    When the operation is finished, /@callback@/ will be called. You can then call
    'GI.Gio.Objects.UnixConnection.unixConnectionSendCredentialsFinish' to get the result of the operation.

    /Since: 2.32/
    -}
    unixConnectionSendCredentialsAsync ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) =>
        a
        {- ^ /@connection@/: A 'GI.Gio.Objects.UnixConnection.UnixConnection'. -}
        -> Maybe (b)
        {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore. -}
        -> Maybe (Gio.Callbacks.AsyncReadyCallback)
        {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' to call when the request is satisfied -}
        -> m ()
    unixConnectionSendCredentialsAsync connection cancellable callback = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        maybeCancellable <- case cancellable of
            Nothing -> return nullPtr
            Just jCancellable -> do
                jCancellable' <- unsafeManagedPtrCastPtr jCancellable
                return jCancellable'
        maybeCallback <- case callback of
            Nothing -> return (castPtrToFunPtr nullPtr)
            Just jCallback -> do
                ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
                jCallback' <- Gio.Callbacks.mk_AsyncReadyCallback (Gio.Callbacks.wrap_AsyncReadyCallback (Just ptrcallback) (Gio.Callbacks.drop_closures_AsyncReadyCallback jCallback))
                poke ptrcallback jCallback'
                return jCallback'
        let userData = nullPtr
        g_unix_connection_send_credentials_async connection' maybeCancellable maybeCallback userData
        touchManagedPtr connection
        whenJust cancellable touchManagedPtr
        return ()

    #if ENABLE_OVERLOADING
    data UnixConnectionSendCredentialsAsyncMethodInfo
    instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) => O.MethodInfo UnixConnectionSendCredentialsAsyncMethodInfo a signature where
        overloadedMethod _ = unixConnectionSendCredentialsAsync

    #endif

    -- method UnixConnection::send_credentials_finish
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "A #GUnixConnection.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "result", argType = TInterface (Name {namespace = "Gio", name = "AsyncResult"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GAsyncResult.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : True
    -- Skip return : False

    foreign import ccall "g_unix_connection_send_credentials_finish" g_unix_connection_send_credentials_finish ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
        Ptr (Ptr GError) ->                     -- error
        IO CInt

    {- |
    Finishes an asynchronous send credentials operation started with
    'GI.Gio.Objects.UnixConnection.unixConnectionSendCredentialsAsync'.

    /Since: 2.32/
    -}
    unixConnectionSendCredentialsFinish ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.AsyncResult.IsAsyncResult b) =>
        a
        {- ^ /@connection@/: A 'GI.Gio.Objects.UnixConnection.UnixConnection'. -}
        -> b
        {- ^ /@result@/: a 'GI.Gio.Interfaces.AsyncResult.AsyncResult'. -}
        -> m ()
        {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
    unixConnectionSendCredentialsFinish connection result_ = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        result_' <- unsafeManagedPtrCastPtr result_
        onException (do
            _ <- propagateGError $ g_unix_connection_send_credentials_finish connection' result_'
            touchManagedPtr connection
            touchManagedPtr result_
            return ()
         ) (do
            return ()
         )

    #if ENABLE_OVERLOADING
    data UnixConnectionSendCredentialsFinishMethodInfo
    instance (signature ~ (b -> m ()), MonadIO m, IsUnixConnection a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo UnixConnectionSendCredentialsFinishMethodInfo a signature where
        overloadedMethod _ = unixConnectionSendCredentialsFinish

    #endif

    -- method UnixConnection::send_fd
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "connection", argType = TInterface (Name {namespace = "Gio", name = "UnixConnection"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GUnixConnection", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "fd", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a file descriptor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cancellable", argType = TInterface (Name {namespace = "Gio", name = "Cancellable"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "optional #GCancellable object, %NULL to ignore.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : True
    -- Skip return : False

    foreign import ccall "g_unix_connection_send_fd" g_unix_connection_send_fd ::
        Ptr UnixConnection ->                   -- connection : TInterface (Name {namespace = "Gio", name = "UnixConnection"})
        Int32 ->                                -- fd : TBasicType TInt
        Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
        Ptr (Ptr GError) ->                     -- error
        IO CInt

    {- |
    Passes a file descriptor to the receiving side of the
    connection. The receiving end has to call 'GI.Gio.Objects.UnixConnection.unixConnectionReceiveFd'
    to accept the file descriptor.

    As well as sending the fd this also writes a single byte to the
    stream, as this is required for fd passing to work on some
    implementations.

    /Since: 2.22/
    -}
    unixConnectionSendFd ::
        (B.CallStack.HasCallStack, MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) =>
        a
        {- ^ /@connection@/: a 'GI.Gio.Objects.UnixConnection.UnixConnection' -}
        -> Int32
        {- ^ /@fd@/: a file descriptor -}
        -> Maybe (b)
        {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore. -}
        -> m ()
        {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
    unixConnectionSendFd connection fd cancellable = liftIO $ do
        connection' <- unsafeManagedPtrCastPtr connection
        maybeCancellable <- case cancellable of
            Nothing -> return nullPtr
            Just jCancellable -> do
                jCancellable' <- unsafeManagedPtrCastPtr jCancellable
                return jCancellable'
        onException (do
            _ <- propagateGError $ g_unix_connection_send_fd connection' fd maybeCancellable
            touchManagedPtr connection
            whenJust cancellable touchManagedPtr
            return ()
         ) (do
            return ()
         )

    #if ENABLE_OVERLOADING
    data UnixConnectionSendFdMethodInfo
    instance (signature ~ (Int32 -> Maybe (b) -> m ()), MonadIO m, IsUnixConnection a, Gio.Cancellable.IsCancellable b) => O.MethodInfo UnixConnectionSendFdMethodInfo a signature where
        overloadedMethod _ = unixConnectionSendFd

    #endif