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

A 'GI.Gio.Objects.SocketListener.SocketListener' is an object that keeps track of a set
of server sockets and helps you accept sockets from any of the
socket, either sync or async.

If you want to implement a network server, also look at 'GI.Gio.Objects.SocketService.SocketService'
and 'GI.Gio.Objects.ThreadedSocketService.ThreadedSocketService' which are subclass of 'GI.Gio.Objects.SocketListener.SocketListener'
that makes this even easier.
-}

module GI.Gio.Objects.SocketListener
    ( 

-- * Exported types
    SocketListener(..)                      ,
    IsSocketListener                        ,
    toSocketListener                        ,
    noSocketListener                        ,


 -- * Methods
-- ** accept #method:accept#
    SocketListenerAcceptMethodInfo          ,
    socketListenerAccept                    ,


-- ** acceptAsync #method:acceptAsync#
    SocketListenerAcceptAsyncMethodInfo     ,
    socketListenerAcceptAsync               ,


-- ** acceptFinish #method:acceptFinish#
    SocketListenerAcceptFinishMethodInfo    ,
    socketListenerAcceptFinish              ,


-- ** acceptSocket #method:acceptSocket#
    SocketListenerAcceptSocketMethodInfo    ,
    socketListenerAcceptSocket              ,


-- ** acceptSocketAsync #method:acceptSocketAsync#
    SocketListenerAcceptSocketAsyncMethodInfo,
    socketListenerAcceptSocketAsync         ,


-- ** acceptSocketFinish #method:acceptSocketFinish#
    SocketListenerAcceptSocketFinishMethodInfo,
    socketListenerAcceptSocketFinish        ,


-- ** addAddress #method:addAddress#
    SocketListenerAddAddressMethodInfo      ,
    socketListenerAddAddress                ,


-- ** addAnyInetPort #method:addAnyInetPort#
    SocketListenerAddAnyInetPortMethodInfo  ,
    socketListenerAddAnyInetPort            ,


-- ** addInetPort #method:addInetPort#
    SocketListenerAddInetPortMethodInfo     ,
    socketListenerAddInetPort               ,


-- ** addSocket #method:addSocket#
    SocketListenerAddSocketMethodInfo       ,
    socketListenerAddSocket                 ,


-- ** close #method:close#
    SocketListenerCloseMethodInfo           ,
    socketListenerClose                     ,


-- ** new #method:new#
    socketListenerNew                       ,


-- ** setBacklog #method:setBacklog#
    SocketListenerSetBacklogMethodInfo      ,
    socketListenerSetBacklog                ,




 -- * Properties
-- ** listenBacklog #attr:listenBacklog#
    SocketListenerListenBacklogPropertyInfo ,
    constructSocketListenerListenBacklog    ,
    getSocketListenerListenBacklog          ,
    setSocketListenerListenBacklog          ,
    socketListenerListenBacklog             ,




 -- * Signals
-- ** event #signal:event#
    C_SocketListenerEventCallback           ,
    SocketListenerEventCallback             ,
    SocketListenerEventSignalInfo           ,
    afterSocketListenerEvent                ,
    genClosure_SocketListenerEvent          ,
    mk_SocketListenerEventCallback          ,
    noSocketListenerEventCallback           ,
    onSocketListenerEvent                   ,
    wrap_SocketListenerEventCallback        ,




    ) 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.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.Enums as Gio.Enums
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.Socket as Gio.Socket
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketAddress as Gio.SocketAddress
import {-# SOURCE #-} qualified GI.Gio.Objects.SocketConnection as Gio.SocketConnection

newtype SocketListener = SocketListener (ManagedPtr SocketListener)
foreign import ccall "g_socket_listener_get_type"
    c_g_socket_listener_get_type :: IO GType

instance GObject SocketListener where
    gobjectType _ = c_g_socket_listener_get_type
    

class GObject o => IsSocketListener o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError SocketListener a) =>
    IsSocketListener a
#endif
instance IsSocketListener SocketListener
instance GObject.Object.IsObject SocketListener

toSocketListener :: IsSocketListener o => o -> IO SocketListener
toSocketListener = unsafeCastTo SocketListener

noSocketListener :: Maybe SocketListener
noSocketListener = Nothing

type family ResolveSocketListenerMethod (t :: Symbol) (o :: *) :: * where
    ResolveSocketListenerMethod "accept" o = SocketListenerAcceptMethodInfo
    ResolveSocketListenerMethod "acceptAsync" o = SocketListenerAcceptAsyncMethodInfo
    ResolveSocketListenerMethod "acceptFinish" o = SocketListenerAcceptFinishMethodInfo
    ResolveSocketListenerMethod "acceptSocket" o = SocketListenerAcceptSocketMethodInfo
    ResolveSocketListenerMethod "acceptSocketAsync" o = SocketListenerAcceptSocketAsyncMethodInfo
    ResolveSocketListenerMethod "acceptSocketFinish" o = SocketListenerAcceptSocketFinishMethodInfo
    ResolveSocketListenerMethod "addAddress" o = SocketListenerAddAddressMethodInfo
    ResolveSocketListenerMethod "addAnyInetPort" o = SocketListenerAddAnyInetPortMethodInfo
    ResolveSocketListenerMethod "addInetPort" o = SocketListenerAddInetPortMethodInfo
    ResolveSocketListenerMethod "addSocket" o = SocketListenerAddSocketMethodInfo
    ResolveSocketListenerMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveSocketListenerMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveSocketListenerMethod "close" o = SocketListenerCloseMethodInfo
    ResolveSocketListenerMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveSocketListenerMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveSocketListenerMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveSocketListenerMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveSocketListenerMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveSocketListenerMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveSocketListenerMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveSocketListenerMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveSocketListenerMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveSocketListenerMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveSocketListenerMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveSocketListenerMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveSocketListenerMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveSocketListenerMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveSocketListenerMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveSocketListenerMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveSocketListenerMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveSocketListenerMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveSocketListenerMethod "setBacklog" o = SocketListenerSetBacklogMethodInfo
    ResolveSocketListenerMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveSocketListenerMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveSocketListenerMethod l o = O.MethodResolutionFailed l o

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

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

-- signal SocketListener::event
type SocketListenerEventCallback =
    Gio.Enums.SocketListenerEvent ->
    Gio.Socket.Socket ->
    IO ()

noSocketListenerEventCallback :: Maybe SocketListenerEventCallback
noSocketListenerEventCallback = Nothing

type C_SocketListenerEventCallback =
    Ptr () ->                               -- object
    CUInt ->
    Ptr Gio.Socket.Socket ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_SocketListenerEventCallback :: C_SocketListenerEventCallback -> IO (FunPtr C_SocketListenerEventCallback)

genClosure_SocketListenerEvent :: SocketListenerEventCallback -> IO Closure
genClosure_SocketListenerEvent cb = do
    let cb' = wrap_SocketListenerEventCallback cb
    mk_SocketListenerEventCallback cb' >>= newCClosure


wrap_SocketListenerEventCallback ::
    SocketListenerEventCallback ->
    Ptr () ->
    CUInt ->
    Ptr Gio.Socket.Socket ->
    Ptr () ->
    IO ()
wrap_SocketListenerEventCallback _cb _ event socket _ = do
    let event' = (toEnum . fromIntegral) event
    socket' <- (newObject Gio.Socket.Socket) socket
    _cb  event' socket'


onSocketListenerEvent :: (GObject a, MonadIO m) => a -> SocketListenerEventCallback -> m SignalHandlerId
onSocketListenerEvent obj cb = liftIO $ connectSocketListenerEvent obj cb SignalConnectBefore
afterSocketListenerEvent :: (GObject a, MonadIO m) => a -> SocketListenerEventCallback -> m SignalHandlerId
afterSocketListenerEvent obj cb = connectSocketListenerEvent obj cb SignalConnectAfter

connectSocketListenerEvent :: (GObject a, MonadIO m) =>
                              a -> SocketListenerEventCallback -> SignalConnectMode -> m SignalHandlerId
connectSocketListenerEvent obj cb after = liftIO $ do
    let cb' = wrap_SocketListenerEventCallback cb
    cb'' <- mk_SocketListenerEventCallback cb'
    connectSignalFunPtr obj "event" cb'' after

-- VVV Prop "listen-backlog"
   -- Type: TBasicType TInt
   -- Flags: [PropertyReadable,PropertyWritable,PropertyConstruct]
   -- Nullable: (Nothing,Nothing)

getSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> m Int32
getSocketListenerListenBacklog obj = liftIO $ getObjectPropertyInt32 obj "listen-backlog"

setSocketListenerListenBacklog :: (MonadIO m, IsSocketListener o) => o -> Int32 -> m ()
setSocketListenerListenBacklog obj val = liftIO $ setObjectPropertyInt32 obj "listen-backlog" val

constructSocketListenerListenBacklog :: (IsSocketListener o) => Int32 -> IO (GValueConstruct o)
constructSocketListenerListenBacklog val = constructObjectPropertyInt32 "listen-backlog" val

data SocketListenerListenBacklogPropertyInfo
instance AttrInfo SocketListenerListenBacklogPropertyInfo where
    type AttrAllowedOps SocketListenerListenBacklogPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint SocketListenerListenBacklogPropertyInfo = (~) Int32
    type AttrBaseTypeConstraint SocketListenerListenBacklogPropertyInfo = IsSocketListener
    type AttrGetType SocketListenerListenBacklogPropertyInfo = Int32
    type AttrLabel SocketListenerListenBacklogPropertyInfo = "listen-backlog"
    type AttrOrigin SocketListenerListenBacklogPropertyInfo = SocketListener
    attrGet _ = getSocketListenerListenBacklog
    attrSet _ = setSocketListenerListenBacklog
    attrConstruct _ = constructSocketListenerListenBacklog
    attrClear _ = undefined

instance O.HasAttributeList SocketListener
type instance O.AttributeList SocketListener = SocketListenerAttributeList
type SocketListenerAttributeList = ('[ '("listenBacklog", SocketListenerListenBacklogPropertyInfo)] :: [(Symbol, *)])

socketListenerListenBacklog :: AttrLabelProxy "listenBacklog"
socketListenerListenBacklog = AttrLabelProxy

data SocketListenerEventSignalInfo
instance SignalInfo SocketListenerEventSignalInfo where
    type HaskellCallbackType SocketListenerEventSignalInfo = SocketListenerEventCallback
    connectSignal _ = connectSocketListenerEvent

type instance O.SignalList SocketListener = SocketListenerSignalList
type SocketListenerSignalList = ('[ '("event", SocketListenerEventSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method SocketListener::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "SocketListener"}))
-- throws : False
-- Skip return : False

foreign import ccall "g_socket_listener_new" g_socket_listener_new :: 
    IO (Ptr SocketListener)

{- |
Creates a new 'GI.Gio.Objects.SocketListener.SocketListener' with no sockets to listen for.
New listeners can be added with e.g. 'GI.Gio.Objects.SocketListener.socketListenerAddAddress'
or 'GI.Gio.Objects.SocketListener.socketListenerAddInetPort'.

@since 2.22
-}
socketListenerNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m SocketListener
    {- ^ __Returns:__ a new 'GI.Gio.Objects.SocketListener.SocketListener'. -}
socketListenerNew  = liftIO $ do
    result <- g_socket_listener_new
    checkUnexpectedReturnNULL "socketListenerNew" result
    result' <- (wrapObject SocketListener) result
    return result'

-- method SocketListener::accept
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location where #GObject pointer will be stored, or %NULL", 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 (TInterface (Name {namespace = "Gio", name = "SocketConnection"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_socket_listener_accept" g_socket_listener_accept :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr (Ptr GObject.Object.Object) ->      -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Gio.SocketConnection.SocketConnection)

{- |
Blocks waiting for a client to connect to any of the sockets added
to the listener. Returns a 'GI.Gio.Objects.SocketConnection.SocketConnection' for the socket that was
accepted.

If /@sourceObject@/ is not 'Nothing' it will be filled out with the source
object specified when the corresponding socket or address was added
to the listener.

If /@cancellable@/ is not 'Nothing', then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error 'GI.Gio.Enums.IOErrorEnumCancelled' will be returned.

@since 2.22
-}
socketListenerAccept ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore. -}
    -> m (Gio.SocketConnection.SocketConnection,GObject.Object.Object)
    {- ^ __Returns:__ a 'GI.Gio.Objects.SocketConnection.SocketConnection' on success, 'Nothing' on error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAccept listener cancellable = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    sourceObject <- allocMem :: IO (Ptr (Ptr GObject.Object.Object))
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ g_socket_listener_accept listener' sourceObject maybeCancellable
        checkUnexpectedReturnNULL "socketListenerAccept" result
        result' <- (wrapObject Gio.SocketConnection.SocketConnection) result
        sourceObject' <- peek sourceObject
        sourceObject'' <- (newObject GObject.Object.Object) sourceObject'
        touchManagedPtr listener
        whenJust cancellable touchManagedPtr
        freeMem sourceObject
        return (result', sourceObject'')
     ) (do
        freeMem sourceObject
     )

data SocketListenerAcceptMethodInfo
instance (signature ~ (Maybe (b) -> m (Gio.SocketConnection.SocketConnection,GObject.Object.Object)), MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SocketListenerAcceptMethodInfo a signature where
    overloadedMethod _ = socketListenerAccept

-- method SocketListener::accept_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", 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},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback", 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 "user data for the callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_socket_listener_accept_async" g_socket_listener_accept_async :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    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 ()

{- |
This is the asynchronous version of 'GI.Gio.Objects.SocketListener.socketListenerAccept'.

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

@since 2.22
-}
socketListenerAcceptAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' -}
    -> m ()
socketListenerAcceptAsync listener cancellable callback = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            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_socket_listener_accept_async listener' maybeCancellable maybeCallback userData
    touchManagedPtr listener
    whenJust cancellable touchManagedPtr
    return ()

data SocketListenerAcceptAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SocketListenerAcceptAsyncMethodInfo a signature where
    overloadedMethod _ = socketListenerAcceptAsync

-- method SocketListener::accept_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", 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},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Optional #GObject identifying this source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "SocketConnection"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_socket_listener_accept_finish" g_socket_listener_accept_finish :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GObject.Object.Object) ->      -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Gio.SocketConnection.SocketConnection)

{- |
Finishes an async accept operation. See 'GI.Gio.Objects.SocketListener.socketListenerAcceptAsync'

@since 2.22
-}
socketListenerAcceptFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> b
    {- ^ /@result@/: a 'GI.Gio.Interfaces.AsyncResult.AsyncResult'. -}
    -> m (Gio.SocketConnection.SocketConnection,GObject.Object.Object)
    {- ^ __Returns:__ a 'GI.Gio.Objects.SocketConnection.SocketConnection' on success, 'Nothing' on error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAcceptFinish listener result_ = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    result_' <- unsafeManagedPtrCastPtr result_
    sourceObject <- allocMem :: IO (Ptr (Ptr GObject.Object.Object))
    onException (do
        result <- propagateGError $ g_socket_listener_accept_finish listener' result_' sourceObject
        checkUnexpectedReturnNULL "socketListenerAcceptFinish" result
        result' <- (wrapObject Gio.SocketConnection.SocketConnection) result
        sourceObject' <- peek sourceObject
        sourceObject'' <- (newObject GObject.Object.Object) sourceObject'
        touchManagedPtr listener
        touchManagedPtr result_
        freeMem sourceObject
        return (result', sourceObject'')
     ) (do
        freeMem sourceObject
     )

data SocketListenerAcceptFinishMethodInfo
instance (signature ~ (b -> m (Gio.SocketConnection.SocketConnection,GObject.Object.Object)), MonadIO m, IsSocketListener a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo SocketListenerAcceptFinishMethodInfo a signature where
    overloadedMethod _ = socketListenerAcceptFinish

-- method SocketListener::accept_socket
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location where #GObject pointer will be stored, or %NULL.", 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 (TInterface (Name {namespace = "Gio", name = "Socket"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_socket_listener_accept_socket" g_socket_listener_accept_socket :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr (Ptr GObject.Object.Object) ->      -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr Gio.Cancellable.Cancellable ->      -- cancellable : TInterface (Name {namespace = "Gio", name = "Cancellable"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Gio.Socket.Socket)

{- |
Blocks waiting for a client to connect to any of the sockets added
to the listener. Returns the 'GI.Gio.Objects.Socket.Socket' that was accepted.

If you want to accept the high-level 'GI.Gio.Objects.SocketConnection.SocketConnection', not a 'GI.Gio.Objects.Socket.Socket',
which is often the case, then you should use 'GI.Gio.Objects.SocketListener.socketListenerAccept'
instead.

If /@sourceObject@/ is not 'Nothing' it will be filled out with the source
object specified when the corresponding socket or address was added
to the listener.

If /@cancellable@/ is not 'Nothing', then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error 'GI.Gio.Enums.IOErrorEnumCancelled' will be returned.

@since 2.22
-}
socketListenerAcceptSocket ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: optional 'GI.Gio.Objects.Cancellable.Cancellable' object, 'Nothing' to ignore. -}
    -> m (Gio.Socket.Socket,GObject.Object.Object)
    {- ^ __Returns:__ a 'GI.Gio.Objects.Socket.Socket' on success, 'Nothing' on error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAcceptSocket listener cancellable = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    sourceObject <- allocMem :: IO (Ptr (Ptr GObject.Object.Object))
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    onException (do
        result <- propagateGError $ g_socket_listener_accept_socket listener' sourceObject maybeCancellable
        checkUnexpectedReturnNULL "socketListenerAcceptSocket" result
        result' <- (wrapObject Gio.Socket.Socket) result
        sourceObject' <- peek sourceObject
        sourceObject'' <- (newObject GObject.Object.Object) sourceObject'
        touchManagedPtr listener
        whenJust cancellable touchManagedPtr
        freeMem sourceObject
        return (result', sourceObject'')
     ) (do
        freeMem sourceObject
     )

data SocketListenerAcceptSocketMethodInfo
instance (signature ~ (Maybe (b) -> m (Gio.Socket.Socket,GObject.Object.Object)), MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SocketListenerAcceptSocketMethodInfo a signature where
    overloadedMethod _ = socketListenerAcceptSocket

-- method SocketListener::accept_socket_async
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", 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},Arg {argCName = "callback", argType = TInterface (Name {namespace = "Gio", name = "AsyncReadyCallback"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "a #GAsyncReadyCallback", 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 "user data for the callback", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_socket_listener_accept_socket_async" g_socket_listener_accept_socket_async :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    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 ()

{- |
This is the asynchronous version of 'GI.Gio.Objects.SocketListener.socketListenerAcceptSocket'.

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

@since 2.22
-}
socketListenerAcceptSocketAsync ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Maybe (b)
    {- ^ /@cancellable@/: a 'GI.Gio.Objects.Cancellable.Cancellable', or 'Nothing' -}
    -> Maybe (Gio.Callbacks.AsyncReadyCallback)
    {- ^ /@callback@/: a 'GI.Gio.Callbacks.AsyncReadyCallback' -}
    -> m ()
socketListenerAcceptSocketAsync listener cancellable callback = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    maybeCancellable <- case cancellable of
        Nothing -> return nullPtr
        Just jCancellable -> do
            jCancellable' <- unsafeManagedPtrCastPtr jCancellable
            return jCancellable'
    ptrcallback <- callocMem :: IO (Ptr (FunPtr Gio.Callbacks.C_AsyncReadyCallback))
    maybeCallback <- case callback of
        Nothing -> return (castPtrToFunPtr nullPtr)
        Just jCallback -> do
            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_socket_listener_accept_socket_async listener' maybeCancellable maybeCallback userData
    touchManagedPtr listener
    whenJust cancellable touchManagedPtr
    return ()

data SocketListenerAcceptSocketAsyncMethodInfo
instance (signature ~ (Maybe (b) -> Maybe (Gio.Callbacks.AsyncReadyCallback) -> m ()), MonadIO m, IsSocketListener a, Gio.Cancellable.IsCancellable b) => O.MethodInfo SocketListenerAcceptSocketAsyncMethodInfo a signature where
    overloadedMethod _ = socketListenerAcceptSocketAsync

-- method SocketListener::accept_socket_finish
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", 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},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Optional #GObject identifying this source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gio", name = "Socket"}))
-- throws : True
-- Skip return : False

foreign import ccall "g_socket_listener_accept_socket_finish" g_socket_listener_accept_socket_finish :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr Gio.AsyncResult.AsyncResult ->      -- result : TInterface (Name {namespace = "Gio", name = "AsyncResult"})
    Ptr (Ptr GObject.Object.Object) ->      -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr GError) ->                     -- error
    IO (Ptr Gio.Socket.Socket)

{- |
Finishes an async accept operation. See 'GI.Gio.Objects.SocketListener.socketListenerAcceptSocketAsync'

@since 2.22
-}
socketListenerAcceptSocketFinish ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.AsyncResult.IsAsyncResult b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> b
    {- ^ /@result@/: a 'GI.Gio.Interfaces.AsyncResult.AsyncResult'. -}
    -> m (Gio.Socket.Socket,GObject.Object.Object)
    {- ^ __Returns:__ a 'GI.Gio.Objects.Socket.Socket' on success, 'Nothing' on error. /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAcceptSocketFinish listener result_ = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    result_' <- unsafeManagedPtrCastPtr result_
    sourceObject <- allocMem :: IO (Ptr (Ptr GObject.Object.Object))
    onException (do
        result <- propagateGError $ g_socket_listener_accept_socket_finish listener' result_' sourceObject
        checkUnexpectedReturnNULL "socketListenerAcceptSocketFinish" result
        result' <- (wrapObject Gio.Socket.Socket) result
        sourceObject' <- peek sourceObject
        sourceObject'' <- (newObject GObject.Object.Object) sourceObject'
        touchManagedPtr listener
        touchManagedPtr result_
        freeMem sourceObject
        return (result', sourceObject'')
     ) (do
        freeMem sourceObject
     )

data SocketListenerAcceptSocketFinishMethodInfo
instance (signature ~ (b -> m (Gio.Socket.Socket,GObject.Object.Object)), MonadIO m, IsSocketListener a, Gio.AsyncResult.IsAsyncResult b) => O.MethodInfo SocketListenerAcceptSocketFinishMethodInfo a signature where
    overloadedMethod _ = socketListenerAcceptSocketFinish

-- method SocketListener::add_address
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "address", argType = TInterface (Name {namespace = "Gio", name = "SocketAddress"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketAddress", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "type", argType = TInterface (Name {namespace = "Gio", name = "SocketType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketType", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "protocol", argType = TInterface (Name {namespace = "Gio", name = "SocketProtocol"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketProtocol", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Optional #GObject identifying this source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "effective_address", argType = TInterface (Name {namespace = "Gio", name = "SocketAddress"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store the address that was bound to, or %NULL.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : True
-- Skip return : False

foreign import ccall "g_socket_listener_add_address" g_socket_listener_add_address :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr Gio.SocketAddress.SocketAddress ->  -- address : TInterface (Name {namespace = "Gio", name = "SocketAddress"})
    CUInt ->                                -- type : TInterface (Name {namespace = "Gio", name = "SocketType"})
    CUInt ->                                -- protocol : TInterface (Name {namespace = "Gio", name = "SocketProtocol"})
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr Gio.SocketAddress.SocketAddress) -> -- effective_address : TInterface (Name {namespace = "Gio", name = "SocketAddress"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Creates a socket of type /@type@/ and protocol /@protocol@/, binds
it to /@address@/ and adds it to the set of sockets we\'re accepting
sockets from.

Note that adding an IPv6 address, depending on the platform,
may or may not result in a listener that also accepts IPv4
connections.  For more deterministic behavior, see
'GI.Gio.Objects.SocketListener.socketListenerAddInetPort'.

/@sourceObject@/ will be passed out in the various calls
to accept to identify this particular source, which is
useful if you\'re listening on multiple addresses and do
different things depending on what address is connected to.

If successful and /@effectiveAddress@/ is non-'Nothing' then it will
be set to the address that the binding actually occurred at.  This
is helpful for determining the port number that was used for when
requesting a binding to port 0 (ie: \"any port\").  This address, if
requested, belongs to the caller and must be freed.

@since 2.22
-}
socketListenerAddAddress ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.SocketAddress.IsSocketAddress b, GObject.Object.IsObject c) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> b
    {- ^ /@address@/: a 'GI.Gio.Objects.SocketAddress.SocketAddress' -}
    -> Gio.Enums.SocketType
    {- ^ /@type@/: a 'GI.Gio.Enums.SocketType' -}
    -> Gio.Enums.SocketProtocol
    {- ^ /@protocol@/: a 'GI.Gio.Enums.SocketProtocol' -}
    -> Maybe (c)
    {- ^ /@sourceObject@/: Optional 'GI.GObject.Objects.Object.Object' identifying this source -}
    -> m (Gio.SocketAddress.SocketAddress)
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAddAddress listener address type_ protocol sourceObject = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    address' <- unsafeManagedPtrCastPtr address
    let type_' = (fromIntegral . fromEnum) type_
    let protocol' = (fromIntegral . fromEnum) protocol
    maybeSourceObject <- case sourceObject of
        Nothing -> return nullPtr
        Just jSourceObject -> do
            jSourceObject' <- unsafeManagedPtrCastPtr jSourceObject
            return jSourceObject'
    effectiveAddress <- allocMem :: IO (Ptr (Ptr Gio.SocketAddress.SocketAddress))
    onException (do
        _ <- propagateGError $ g_socket_listener_add_address listener' address' type_' protocol' maybeSourceObject effectiveAddress
        effectiveAddress' <- peek effectiveAddress
        effectiveAddress'' <- (wrapObject Gio.SocketAddress.SocketAddress) effectiveAddress'
        touchManagedPtr listener
        touchManagedPtr address
        whenJust sourceObject touchManagedPtr
        freeMem effectiveAddress
        return effectiveAddress''
     ) (do
        freeMem effectiveAddress
     )

data SocketListenerAddAddressMethodInfo
instance (signature ~ (b -> Gio.Enums.SocketType -> Gio.Enums.SocketProtocol -> Maybe (c) -> m (Gio.SocketAddress.SocketAddress)), MonadIO m, IsSocketListener a, Gio.SocketAddress.IsSocketAddress b, GObject.Object.IsObject c) => O.MethodInfo SocketListenerAddAddressMethodInfo a signature where
    overloadedMethod _ = socketListenerAddAddress

-- method SocketListener::add_any_inet_port
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Optional #GObject identifying this source", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt16)
-- throws : True
-- Skip return : False

foreign import ccall "g_socket_listener_add_any_inet_port" g_socket_listener_add_any_inet_port :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr GError) ->                     -- error
    IO Word16

{- |
Listens for TCP connections on any available port number for both
IPv6 and IPv4 (if each is available).

This is useful if you need to have a socket for incoming connections
but don\'t care about the specific port number.

/@sourceObject@/ will be passed out in the various calls
to accept to identify this particular source, which is
useful if you\'re listening on multiple addresses and do
different things depending on what address is connected to.

@since 2.24
-}
socketListenerAddAnyInetPort ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, GObject.Object.IsObject b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Maybe (b)
    {- ^ /@sourceObject@/: Optional 'GI.GObject.Objects.Object.Object' identifying this source -}
    -> m Word16
    {- ^ __Returns:__ the port number, or 0 in case of failure. /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAddAnyInetPort listener sourceObject = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    maybeSourceObject <- case sourceObject of
        Nothing -> return nullPtr
        Just jSourceObject -> do
            jSourceObject' <- unsafeManagedPtrCastPtr jSourceObject
            return jSourceObject'
    onException (do
        result <- propagateGError $ g_socket_listener_add_any_inet_port listener' maybeSourceObject
        touchManagedPtr listener
        whenJust sourceObject touchManagedPtr
        return result
     ) (do
        return ()
     )

data SocketListenerAddAnyInetPortMethodInfo
instance (signature ~ (Maybe (b) -> m Word16), MonadIO m, IsSocketListener a, GObject.Object.IsObject b) => O.MethodInfo SocketListenerAddAnyInetPortMethodInfo a signature where
    overloadedMethod _ = socketListenerAddAnyInetPort

-- method SocketListener::add_inet_port
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "port", argType = TBasicType TUInt16, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an IP port number (non-zero)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Optional #GObject identifying this source", 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_socket_listener_add_inet_port" g_socket_listener_add_inet_port :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Word16 ->                               -- port : TBasicType TUInt16
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Helper function for 'GI.Gio.Objects.SocketListener.socketListenerAddAddress' that
creates a TCP\/IP socket listening on IPv4 and IPv6 (if
supported) on the specified port on all interfaces.

/@sourceObject@/ will be passed out in the various calls
to accept to identify this particular source, which is
useful if you\'re listening on multiple addresses and do
different things depending on what address is connected to.

@since 2.22
-}
socketListenerAddInetPort ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, GObject.Object.IsObject b) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Word16
    {- ^ /@port@/: an IP port number (non-zero) -}
    -> Maybe (b)
    {- ^ /@sourceObject@/: Optional 'GI.GObject.Objects.Object.Object' identifying this source -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAddInetPort listener port sourceObject = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    maybeSourceObject <- case sourceObject of
        Nothing -> return nullPtr
        Just jSourceObject -> do
            jSourceObject' <- unsafeManagedPtrCastPtr jSourceObject
            return jSourceObject'
    onException (do
        _ <- propagateGError $ g_socket_listener_add_inet_port listener' port maybeSourceObject
        touchManagedPtr listener
        whenJust sourceObject touchManagedPtr
        return ()
     ) (do
        return ()
     )

data SocketListenerAddInetPortMethodInfo
instance (signature ~ (Word16 -> Maybe (b) -> m ()), MonadIO m, IsSocketListener a, GObject.Object.IsObject b) => O.MethodInfo SocketListenerAddInetPortMethodInfo a signature where
    overloadedMethod _ = socketListenerAddInetPort

-- method SocketListener::add_socket
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "socket", argType = TInterface (Name {namespace = "Gio", name = "Socket"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a listening #GSocket", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "source_object", argType = TInterface (Name {namespace = "GObject", name = "Object"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "Optional #GObject identifying this source", 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_socket_listener_add_socket" g_socket_listener_add_socket :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Ptr Gio.Socket.Socket ->                -- socket : TInterface (Name {namespace = "Gio", name = "Socket"})
    Ptr GObject.Object.Object ->            -- source_object : TInterface (Name {namespace = "GObject", name = "Object"})
    Ptr (Ptr GError) ->                     -- error
    IO CInt

{- |
Adds /@socket@/ to the set of sockets that we try to accept
new clients from. The socket must be bound to a local
address and listened to.

/@sourceObject@/ will be passed out in the various calls
to accept to identify this particular source, which is
useful if you\'re listening on multiple addresses and do
different things depending on what address is connected to.

The /@socket@/ will not be automatically closed when the /@listener@/ is finalized
unless the listener held the final reference to the socket. Before GLib 2.42,
the /@socket@/ was automatically closed on finalization of the /@listener@/, even
if references to it were held elsewhere.

@since 2.22
-}
socketListenerAddSocket ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a, Gio.Socket.IsSocket b, GObject.Object.IsObject c) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> b
    {- ^ /@socket@/: a listening 'GI.Gio.Objects.Socket.Socket' -}
    -> Maybe (c)
    {- ^ /@sourceObject@/: Optional 'GI.GObject.Objects.Object.Object' identifying this source -}
    -> m ()
    {- ^ /(Can throw 'Data.GI.Base.GError.GError')/ -}
socketListenerAddSocket listener socket sourceObject = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    socket' <- unsafeManagedPtrCastPtr socket
    maybeSourceObject <- case sourceObject of
        Nothing -> return nullPtr
        Just jSourceObject -> do
            jSourceObject' <- unsafeManagedPtrCastPtr jSourceObject
            return jSourceObject'
    onException (do
        _ <- propagateGError $ g_socket_listener_add_socket listener' socket' maybeSourceObject
        touchManagedPtr listener
        touchManagedPtr socket
        whenJust sourceObject touchManagedPtr
        return ()
     ) (do
        return ()
     )

data SocketListenerAddSocketMethodInfo
instance (signature ~ (b -> Maybe (c) -> m ()), MonadIO m, IsSocketListener a, Gio.Socket.IsSocket b, GObject.Object.IsObject c) => O.MethodInfo SocketListenerAddSocketMethodInfo a signature where
    overloadedMethod _ = socketListenerAddSocket

-- method SocketListener::close
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_socket_listener_close" g_socket_listener_close :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    IO ()

{- |
Closes all the sockets in the listener.

@since 2.22
-}
socketListenerClose ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> m ()
socketListenerClose listener = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    g_socket_listener_close listener'
    touchManagedPtr listener
    return ()

data SocketListenerCloseMethodInfo
instance (signature ~ (m ()), MonadIO m, IsSocketListener a) => O.MethodInfo SocketListenerCloseMethodInfo a signature where
    overloadedMethod _ = socketListenerClose

-- method SocketListener::set_backlog
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "listener", argType = TInterface (Name {namespace = "Gio", name = "SocketListener"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GSocketListener", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "listen_backlog", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an integer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "g_socket_listener_set_backlog" g_socket_listener_set_backlog :: 
    Ptr SocketListener ->                   -- listener : TInterface (Name {namespace = "Gio", name = "SocketListener"})
    Int32 ->                                -- listen_backlog : TBasicType TInt
    IO ()

{- |
Sets the listen backlog on the sockets in the listener.

See 'GI.Gio.Objects.Socket.socketSetListenBacklog' for details

@since 2.22
-}
socketListenerSetBacklog ::
    (B.CallStack.HasCallStack, MonadIO m, IsSocketListener a) =>
    a
    {- ^ /@listener@/: a 'GI.Gio.Objects.SocketListener.SocketListener' -}
    -> Int32
    {- ^ /@listenBacklog@/: an integer -}
    -> m ()
socketListenerSetBacklog listener listenBacklog = liftIO $ do
    listener' <- unsafeManagedPtrCastPtr listener
    g_socket_listener_set_backlog listener' listenBacklog
    touchManagedPtr listener
    return ()

data SocketListenerSetBacklogMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m, IsSocketListener a) => O.MethodInfo SocketListenerSetBacklogMethodInfo a signature where
    overloadedMethod _ = socketListenerSetBacklog