// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT package gio import ( "structs" "unsafe" "github.com/ebitengine/purego" "github.com/bnema/puregotk/pkg/core" "github.com/bnema/puregotk/v4/glib" "github.com/bnema/puregotk/v4/gobject" "github.com/bnema/puregotk/v4/gobject/types" ) // Class structure for #GSocketListener. type SocketListenerClass struct { _ structs.HostLayout ParentClass gobject.ObjectClass xChanged uintptr xEvent uintptr xGReserved2 uintptr xGReserved3 uintptr xGReserved4 uintptr xGReserved5 uintptr xGReserved6 uintptr } func (x *SocketListenerClass) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideChanged sets the "changed" callback function. // virtual method called when the set of socket listened to changes func (x *SocketListenerClass) OverrideChanged(cb func(*SocketListener)) { if cb == nil { x.xChanged = 0 } else { x.xChanged = purego.NewCallback(func(ListenerVarp uintptr) { cb(SocketListenerNewFromInternalPtr(ListenerVarp)) }) } } // GetChanged gets the "changed" callback function. // virtual method called when the set of socket listened to changes func (x *SocketListenerClass) GetChanged() func(*SocketListener) { if x.xChanged == 0 { return nil } var rawCallback func(ListenerVarp uintptr) purego.RegisterFunc(&rawCallback, x.xChanged) return func(ListenerVar *SocketListener) { rawCallback(ListenerVar.GoPointer()) } } // OverrideEvent sets the "event" callback function. func (x *SocketListenerClass) OverrideEvent(cb func(*SocketListener, SocketListenerEvent, *Socket)) { if cb == nil { x.xEvent = 0 } else { x.xEvent = purego.NewCallback(func(ListenerVarp uintptr, EventVarp SocketListenerEvent, SocketVarp uintptr) { cb(SocketListenerNewFromInternalPtr(ListenerVarp), EventVarp, SocketNewFromInternalPtr(SocketVarp)) }) } } // GetEvent gets the "event" callback function. func (x *SocketListenerClass) GetEvent() func(*SocketListener, SocketListenerEvent, *Socket) { if x.xEvent == 0 { return nil } var rawCallback func(ListenerVarp uintptr, EventVarp SocketListenerEvent, SocketVarp uintptr) purego.RegisterFunc(&rawCallback, x.xEvent) return func(ListenerVar *SocketListener, EventVar SocketListenerEvent, SocketVar *Socket) { rawCallback(ListenerVar.GoPointer(), EventVar, SocketVar.GoPointer()) } } // OverrideGReserved2 sets the "_g_reserved2" callback function. func (x *SocketListenerClass) OverrideGReserved2(cb func()) { if cb == nil { x.xGReserved2 = 0 } else { x.xGReserved2 = purego.NewCallback(func() { cb() }) } } // GetGReserved2 gets the "_g_reserved2" callback function. func (x *SocketListenerClass) GetGReserved2() func() { if x.xGReserved2 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved2) return func() { rawCallback() } } // OverrideGReserved3 sets the "_g_reserved3" callback function. func (x *SocketListenerClass) OverrideGReserved3(cb func()) { if cb == nil { x.xGReserved3 = 0 } else { x.xGReserved3 = purego.NewCallback(func() { cb() }) } } // GetGReserved3 gets the "_g_reserved3" callback function. func (x *SocketListenerClass) GetGReserved3() func() { if x.xGReserved3 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved3) return func() { rawCallback() } } // OverrideGReserved4 sets the "_g_reserved4" callback function. func (x *SocketListenerClass) OverrideGReserved4(cb func()) { if cb == nil { x.xGReserved4 = 0 } else { x.xGReserved4 = purego.NewCallback(func() { cb() }) } } // GetGReserved4 gets the "_g_reserved4" callback function. func (x *SocketListenerClass) GetGReserved4() func() { if x.xGReserved4 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved4) return func() { rawCallback() } } // OverrideGReserved5 sets the "_g_reserved5" callback function. func (x *SocketListenerClass) OverrideGReserved5(cb func()) { if cb == nil { x.xGReserved5 = 0 } else { x.xGReserved5 = purego.NewCallback(func() { cb() }) } } // GetGReserved5 gets the "_g_reserved5" callback function. func (x *SocketListenerClass) GetGReserved5() func() { if x.xGReserved5 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved5) return func() { rawCallback() } } // OverrideGReserved6 sets the "_g_reserved6" callback function. func (x *SocketListenerClass) OverrideGReserved6(cb func()) { if cb == nil { x.xGReserved6 = 0 } else { x.xGReserved6 = purego.NewCallback(func() { cb() }) } } // GetGReserved6 gets the "_g_reserved6" callback function. func (x *SocketListenerClass) GetGReserved6() func() { if x.xGReserved6 == 0 { return nil } var rawCallback func() purego.RegisterFunc(&rawCallback, x.xGReserved6) return func() { rawCallback() } } type SocketListenerPrivate struct { _ structs.HostLayout } func (x *SocketListenerPrivate) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // A `GSocketListener` 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. // // Add addresses and ports to listen on using // [method@Gio.SocketListener.add_address] and // [method@Gio.SocketListener.add_inet_port]. These will be listened on until // [method@Gio.SocketListener.close] is called. Dropping your final reference to // the `GSocketListener` will not cause [method@Gio.SocketListener.close] to be // called implicitly, as some references to the `GSocketListener` may be held // internally. // // If you want to implement a network server, also look at // [class@Gio.SocketService] and [class@Gio.ThreadedSocketService] which are // subclasses of `GSocketListener` that make this even easier. type SocketListener struct { gobject.Object } var xSocketListenerGLibType func() types.GType func SocketListenerGLibType() types.GType { return xSocketListenerGLibType() } func SocketListenerNewFromInternalPtr(ptr uintptr) *SocketListener { cls := &SocketListener{} cls.Ptr = ptr return cls } var xNewSocketListener func() uintptr // Creates a new #GSocketListener with no sockets to listen for. // New listeners can be added with e.g. g_socket_listener_add_address() // or g_socket_listener_add_inet_port(). func NewSocketListener() *SocketListener { var cls *SocketListener cret := xNewSocketListener() if cret == 0 { return nil } cls = &SocketListener{} cls.Ptr = cret return cls } var xSocketListenerAccept func(uintptr, **gobject.Object, uintptr, **glib.Error) uintptr // Blocks waiting for a client to connect to any of the sockets added // to the listener. Returns a #GSocketConnection for the socket that was // accepted. // // If @source_object is not %NULL 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 %NULL, then the operation can be cancelled by // triggering the cancellable object from another thread. If the operation // was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. func (x *SocketListener) Accept(SourceObjectVar **gobject.Object, CancellableVar *Cancellable) (*SocketConnection, error) { var cls *SocketConnection var cerr *glib.Error cret := xSocketListenerAccept(x.GoPointer(), SourceObjectVar, CancellableVar.GoPointer(), &cerr) if cret == 0 { return nil, cerr } cls = &SocketConnection{} cls.Ptr = cret if cerr == nil { return cls, nil } return cls, cerr } var xSocketListenerAcceptAsync func(uintptr, uintptr, uintptr, uintptr) // This is the asynchronous version of g_socket_listener_accept(). // // When the operation is finished @callback will be // called. You can then call g_socket_listener_accept_finish() // to get the result of the operation. func (x *SocketListener) AcceptAsync(CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) { var CallbackVarRef uintptr if CallbackVar != nil { CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar)) if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok { CallbackVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) { cbFn := *CallbackVar cbFn(arg0, arg1, arg2) } CallbackVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar) } } xSocketListenerAcceptAsync(x.GoPointer(), CancellableVar.GoPointer(), CallbackVarRef, UserDataVar) } var xSocketListenerAcceptFinish func(uintptr, uintptr, **gobject.Object, **glib.Error) uintptr // Finishes an async accept operation. See g_socket_listener_accept_async() func (x *SocketListener) AcceptFinish(ResultVar AsyncResult, SourceObjectVar **gobject.Object) (*SocketConnection, error) { var cls *SocketConnection var cerr *glib.Error cret := xSocketListenerAcceptFinish(x.GoPointer(), ResultVar.GoPointer(), SourceObjectVar, &cerr) if cret == 0 { return nil, cerr } cls = &SocketConnection{} cls.Ptr = cret if cerr == nil { return cls, nil } return cls, cerr } var xSocketListenerAcceptSocket func(uintptr, **gobject.Object, uintptr, **glib.Error) uintptr // Blocks waiting for a client to connect to any of the sockets added // to the listener. Returns the #GSocket that was accepted. // // If you want to accept the high-level #GSocketConnection, not a #GSocket, // which is often the case, then you should use g_socket_listener_accept() // instead. // // If @source_object is not %NULL 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 %NULL, then the operation can be cancelled by // triggering the cancellable object from another thread. If the operation // was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. func (x *SocketListener) AcceptSocket(SourceObjectVar **gobject.Object, CancellableVar *Cancellable) (*Socket, error) { var cls *Socket var cerr *glib.Error cret := xSocketListenerAcceptSocket(x.GoPointer(), SourceObjectVar, CancellableVar.GoPointer(), &cerr) if cret == 0 { return nil, cerr } cls = &Socket{} cls.Ptr = cret if cerr == nil { return cls, nil } return cls, cerr } var xSocketListenerAcceptSocketAsync func(uintptr, uintptr, uintptr, uintptr) // This is the asynchronous version of g_socket_listener_accept_socket(). // // When the operation is finished @callback will be // called. You can then call g_socket_listener_accept_socket_finish() // to get the result of the operation. func (x *SocketListener) AcceptSocketAsync(CancellableVar *Cancellable, CallbackVar *AsyncReadyCallback, UserDataVar uintptr) { var CallbackVarRef uintptr if CallbackVar != nil { CallbackVarPtr := uintptr(unsafe.Pointer(CallbackVar)) if cbRefPtr, ok := glib.GetCallback(CallbackVarPtr); ok { CallbackVarRef = cbRefPtr } else { fcb := func(arg0 uintptr, arg1 uintptr, arg2 uintptr) { cbFn := *CallbackVar cbFn(arg0, arg1, arg2) } CallbackVarRef = purego.NewCallback(fcb) glib.SaveCallbackWithClosure(CallbackVarPtr, CallbackVarRef, CallbackVar) } } xSocketListenerAcceptSocketAsync(x.GoPointer(), CancellableVar.GoPointer(), CallbackVarRef, UserDataVar) } var xSocketListenerAcceptSocketFinish func(uintptr, uintptr, **gobject.Object, **glib.Error) uintptr // Finishes an async accept operation. See g_socket_listener_accept_socket_async() func (x *SocketListener) AcceptSocketFinish(ResultVar AsyncResult, SourceObjectVar **gobject.Object) (*Socket, error) { var cls *Socket var cerr *glib.Error cret := xSocketListenerAcceptSocketFinish(x.GoPointer(), ResultVar.GoPointer(), SourceObjectVar, &cerr) if cret == 0 { return nil, cerr } cls = &Socket{} cls.Ptr = cret if cerr == nil { return cls, nil } return cls, cerr } var xSocketListenerAddAddress func(uintptr, uintptr, SocketType, SocketProtocol, uintptr, **SocketAddress, **glib.Error) bool // 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 // g_socket_listener_add_inet_port(). // // @source_object 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 @effective_address is non-%NULL 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. // // Call g_socket_listener_close() to stop listening on @address; this will not // be done automatically when you drop your final reference to @listener, as // references may be held internally. func (x *SocketListener) AddAddress(AddressVar *SocketAddress, TypeVar SocketType, ProtocolVar SocketProtocol, SourceObjectVar *gobject.Object, EffectiveAddressVar **SocketAddress) (bool, error) { var cerr *glib.Error cret := xSocketListenerAddAddress(x.GoPointer(), AddressVar.GoPointer(), TypeVar, ProtocolVar, SourceObjectVar.GoPointer(), EffectiveAddressVar, &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xSocketListenerAddAnyInetPort func(uintptr, uintptr, **glib.Error) uint16 // 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. // // If possible, the [class@Gio.SocketListener] will listen on both IPv4 and // IPv6 (listening on the same port on both). If listening on one of the socket // families fails, the [class@Gio.SocketListener] will only listen on the other. // If listening on both fails, an error will be returned. // // If you need to distinguish whether listening on IPv4 or IPv6 or both was // successful, connect to [signal@Gio.SocketListener::event]. // // @source_object 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. func (x *SocketListener) AddAnyInetPort(SourceObjectVar *gobject.Object) (uint16, error) { var cerr *glib.Error cret := xSocketListenerAddAnyInetPort(x.GoPointer(), SourceObjectVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xSocketListenerAddInetPort func(uintptr, uint16, uintptr, **glib.Error) bool // Helper function for g_socket_listener_add_address() that // creates a TCP/IP socket listening on IPv4 and IPv6 (if // supported) on the specified port on all interfaces. // // If possible, the [class@Gio.SocketListener] will listen on both IPv4 and // IPv6 (listening on the same port on both). If listening on one of the socket // families fails, the [class@Gio.SocketListener] will only listen on the other. // If listening on both fails, an error will be returned. // // If you need to distinguish whether listening on IPv4 or IPv6 or both was // successful, connect to [signal@Gio.SocketListener::event]. // // @source_object 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. // // Call g_socket_listener_close() to stop listening on @port; this will not // be done automatically when you drop your final reference to @listener, as // references may be held internally. func (x *SocketListener) AddInetPort(PortVar uint16, SourceObjectVar *gobject.Object) (bool, error) { var cerr *glib.Error cret := xSocketListenerAddInetPort(x.GoPointer(), PortVar, SourceObjectVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xSocketListenerAddSocket func(uintptr, uintptr, uintptr, **glib.Error) bool // 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. // // For parallel calls to [class@Gio.SocketListener] methods to work, the socket // must be in non-blocking mode. (See [property@Gio.Socket:blocking].) // // @source_object 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. func (x *SocketListener) AddSocket(SocketVar *Socket, SourceObjectVar *gobject.Object) (bool, error) { var cerr *glib.Error cret := xSocketListenerAddSocket(x.GoPointer(), SocketVar.GoPointer(), SourceObjectVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } var xSocketListenerClose func(uintptr) // Closes all the sockets in the listener. func (x *SocketListener) Close() { xSocketListenerClose(x.GoPointer()) } var xSocketListenerSetBacklog func(uintptr, int) // Sets the listen backlog on the sockets in the listener. This must be called // before adding any sockets, addresses or ports to the #GSocketListener (for // example, by calling g_socket_listener_add_inet_port()) to be effective. // // See g_socket_set_listen_backlog() for details func (x *SocketListener) SetBacklog(ListenBacklogVar int) { xSocketListenerSetBacklog(x.GoPointer(), ListenBacklogVar) } func (c *SocketListener) GoPointer() uintptr { if c == nil { return 0 } return c.Ptr } func (c *SocketListener) SetGoPointer(ptr uintptr) { c.Ptr = ptr } // SetPropertyListenBacklog sets the "listen-backlog" property. // The number of outstanding connections in the listen queue. func (x *SocketListener) SetPropertyListenBacklog(value int) { var v gobject.Value v.Init(gobject.TypeIntVal) v.SetInt(value) x.SetProperty("listen-backlog", &v) } // GetPropertyListenBacklog gets the "listen-backlog" property. // The number of outstanding connections in the listen queue. func (x *SocketListener) GetPropertyListenBacklog() int { var v gobject.Value x.GetProperty("listen-backlog", &v) return v.GetInt() } // Emitted when @listener's activity on @socket changes state. // Note that when @listener is used to listen on both IPv4 and // IPv6, a separate set of signals will be emitted for each, and // the order they happen in is undefined. func (x *SocketListener) ConnectEvent(cb *func(SocketListener, SocketListenerEvent, uintptr)) uint { cbPtr := uintptr(unsafe.Pointer(cb)) if cbRefPtr, ok := glib.GetCallback(cbPtr); ok { handlerID := gobject.SignalConnect(x.GoPointer(), "event", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } fcb := func(clsPtr uintptr, EventVarp SocketListenerEvent, SocketVarp uintptr) { fa := SocketListener{} fa.Ptr = clsPtr cbFn := *cb cbFn(fa, EventVarp, SocketVarp) } cbRefPtr := purego.NewCallback(fcb) glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb) handlerID := gobject.SignalConnect(x.GoPointer(), "event", cbRefPtr) glib.SaveHandlerMapping(handlerID, cbPtr) return handlerID } func init() { core.SetPackageName("GIO", "gio-2.0") core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"}) var libs []uintptr for _, libPath := range core.GetPaths("GIO") { lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL) if err != nil { panic(err) } libs = append(libs, lib) } core.PuregoSafeRegister(&xSocketListenerGLibType, libs, "g_socket_listener_get_type") core.PuregoSafeRegister(&xNewSocketListener, libs, "g_socket_listener_new") core.PuregoSafeRegister(&xSocketListenerAccept, libs, "g_socket_listener_accept") core.PuregoSafeRegister(&xSocketListenerAcceptAsync, libs, "g_socket_listener_accept_async") core.PuregoSafeRegister(&xSocketListenerAcceptFinish, libs, "g_socket_listener_accept_finish") core.PuregoSafeRegister(&xSocketListenerAcceptSocket, libs, "g_socket_listener_accept_socket") core.PuregoSafeRegister(&xSocketListenerAcceptSocketAsync, libs, "g_socket_listener_accept_socket_async") core.PuregoSafeRegister(&xSocketListenerAcceptSocketFinish, libs, "g_socket_listener_accept_socket_finish") core.PuregoSafeRegister(&xSocketListenerAddAddress, libs, "g_socket_listener_add_address") core.PuregoSafeRegister(&xSocketListenerAddAnyInetPort, libs, "g_socket_listener_add_any_inet_port") core.PuregoSafeRegister(&xSocketListenerAddInetPort, libs, "g_socket_listener_add_inet_port") core.PuregoSafeRegister(&xSocketListenerAddSocket, libs, "g_socket_listener_add_socket") core.PuregoSafeRegister(&xSocketListenerClose, libs, "g_socket_listener_close") core.PuregoSafeRegister(&xSocketListenerSetBacklog, libs, "g_socket_listener_set_backlog") }