// 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/types" ) // Provides an interface for socket-like objects which have datagram semantics, // following the Berkeley sockets API. The interface methods are thin wrappers // around the corresponding virtual methods, and no pre-processing of inputs is // implemented — so implementations of this API must handle all functionality // documented in the interface methods. type DatagramBasedInterface struct { _ structs.HostLayout GIface uintptr xReceiveMessages uintptr xSendMessages uintptr xCreateSource uintptr xConditionCheck uintptr xConditionWait uintptr } func (x *DatagramBasedInterface) GoPointer() uintptr { return uintptr(unsafe.Pointer(x)) } // OverrideReceiveMessages sets the "receive_messages" callback function. // Virtual method for g_datagram_based_receive_messages(). func (x *DatagramBasedInterface) OverrideReceiveMessages(cb func(DatagramBased, []InputMessage, uint, int, int64, *Cancellable) int) { if cb == nil { x.xReceiveMessages = 0 } else { x.xReceiveMessages = purego.NewCallback(func(DatagramBasedVarp uintptr, MessagesVarp []InputMessage, NumMessagesVarp uint, FlagsVarp int, TimeoutVarp int64, CancellableVarp uintptr) int { return cb(&DatagramBasedBase{Ptr: DatagramBasedVarp}, MessagesVarp, NumMessagesVarp, FlagsVarp, TimeoutVarp, CancellableNewFromInternalPtr(CancellableVarp)) }) } } // GetReceiveMessages gets the "receive_messages" callback function. // Virtual method for g_datagram_based_receive_messages(). func (x *DatagramBasedInterface) GetReceiveMessages() func(DatagramBased, []InputMessage, uint, int, int64, *Cancellable) int { if x.xReceiveMessages == 0 { return nil } var rawCallback func(DatagramBasedVarp uintptr, MessagesVarp []InputMessage, NumMessagesVarp uint, FlagsVarp int, TimeoutVarp int64, CancellableVarp uintptr) int purego.RegisterFunc(&rawCallback, x.xReceiveMessages) return func(DatagramBasedVar DatagramBased, MessagesVar []InputMessage, NumMessagesVar uint, FlagsVar int, TimeoutVar int64, CancellableVar *Cancellable) int { return rawCallback(DatagramBasedVar.GoPointer(), MessagesVar, NumMessagesVar, FlagsVar, TimeoutVar, CancellableVar.GoPointer()) } } // OverrideSendMessages sets the "send_messages" callback function. // Virtual method for g_datagram_based_send_messages(). func (x *DatagramBasedInterface) OverrideSendMessages(cb func(DatagramBased, []OutputMessage, uint, int, int64, *Cancellable) int) { if cb == nil { x.xSendMessages = 0 } else { x.xSendMessages = purego.NewCallback(func(DatagramBasedVarp uintptr, MessagesVarp []OutputMessage, NumMessagesVarp uint, FlagsVarp int, TimeoutVarp int64, CancellableVarp uintptr) int { return cb(&DatagramBasedBase{Ptr: DatagramBasedVarp}, MessagesVarp, NumMessagesVarp, FlagsVarp, TimeoutVarp, CancellableNewFromInternalPtr(CancellableVarp)) }) } } // GetSendMessages gets the "send_messages" callback function. // Virtual method for g_datagram_based_send_messages(). func (x *DatagramBasedInterface) GetSendMessages() func(DatagramBased, []OutputMessage, uint, int, int64, *Cancellable) int { if x.xSendMessages == 0 { return nil } var rawCallback func(DatagramBasedVarp uintptr, MessagesVarp []OutputMessage, NumMessagesVarp uint, FlagsVarp int, TimeoutVarp int64, CancellableVarp uintptr) int purego.RegisterFunc(&rawCallback, x.xSendMessages) return func(DatagramBasedVar DatagramBased, MessagesVar []OutputMessage, NumMessagesVar uint, FlagsVar int, TimeoutVar int64, CancellableVar *Cancellable) int { return rawCallback(DatagramBasedVar.GoPointer(), MessagesVar, NumMessagesVar, FlagsVar, TimeoutVar, CancellableVar.GoPointer()) } } // OverrideCreateSource sets the "create_source" callback function. // Virtual method for g_datagram_based_create_source(). func (x *DatagramBasedInterface) OverrideCreateSource(cb func(DatagramBased, glib.IOCondition, *Cancellable) *glib.Source) { if cb == nil { x.xCreateSource = 0 } else { x.xCreateSource = purego.NewCallback(func(DatagramBasedVarp uintptr, ConditionVarp glib.IOCondition, CancellableVarp uintptr) *glib.Source { return cb(&DatagramBasedBase{Ptr: DatagramBasedVarp}, ConditionVarp, CancellableNewFromInternalPtr(CancellableVarp)) }) } } // GetCreateSource gets the "create_source" callback function. // Virtual method for g_datagram_based_create_source(). func (x *DatagramBasedInterface) GetCreateSource() func(DatagramBased, glib.IOCondition, *Cancellable) *glib.Source { if x.xCreateSource == 0 { return nil } var rawCallback func(DatagramBasedVarp uintptr, ConditionVarp glib.IOCondition, CancellableVarp uintptr) *glib.Source purego.RegisterFunc(&rawCallback, x.xCreateSource) return func(DatagramBasedVar DatagramBased, ConditionVar glib.IOCondition, CancellableVar *Cancellable) *glib.Source { return rawCallback(DatagramBasedVar.GoPointer(), ConditionVar, CancellableVar.GoPointer()) } } // OverrideConditionCheck sets the "condition_check" callback function. // Virtual method for g_datagram_based_condition_check(). func (x *DatagramBasedInterface) OverrideConditionCheck(cb func(DatagramBased, glib.IOCondition) glib.IOCondition) { if cb == nil { x.xConditionCheck = 0 } else { x.xConditionCheck = purego.NewCallback(func(DatagramBasedVarp uintptr, ConditionVarp glib.IOCondition) glib.IOCondition { return cb(&DatagramBasedBase{Ptr: DatagramBasedVarp}, ConditionVarp) }) } } // GetConditionCheck gets the "condition_check" callback function. // Virtual method for g_datagram_based_condition_check(). func (x *DatagramBasedInterface) GetConditionCheck() func(DatagramBased, glib.IOCondition) glib.IOCondition { if x.xConditionCheck == 0 { return nil } var rawCallback func(DatagramBasedVarp uintptr, ConditionVarp glib.IOCondition) glib.IOCondition purego.RegisterFunc(&rawCallback, x.xConditionCheck) return func(DatagramBasedVar DatagramBased, ConditionVar glib.IOCondition) glib.IOCondition { return rawCallback(DatagramBasedVar.GoPointer(), ConditionVar) } } // OverrideConditionWait sets the "condition_wait" callback function. // Virtual method for // // g_datagram_based_condition_wait(). func (x *DatagramBasedInterface) OverrideConditionWait(cb func(DatagramBased, glib.IOCondition, int64, *Cancellable) bool) { if cb == nil { x.xConditionWait = 0 } else { x.xConditionWait = purego.NewCallback(func(DatagramBasedVarp uintptr, ConditionVarp glib.IOCondition, TimeoutVarp int64, CancellableVarp uintptr) bool { return cb(&DatagramBasedBase{Ptr: DatagramBasedVarp}, ConditionVarp, TimeoutVarp, CancellableNewFromInternalPtr(CancellableVarp)) }) } } // GetConditionWait gets the "condition_wait" callback function. // Virtual method for // // g_datagram_based_condition_wait(). func (x *DatagramBasedInterface) GetConditionWait() func(DatagramBased, glib.IOCondition, int64, *Cancellable) bool { if x.xConditionWait == 0 { return nil } var rawCallback func(DatagramBasedVarp uintptr, ConditionVarp glib.IOCondition, TimeoutVarp int64, CancellableVarp uintptr) bool purego.RegisterFunc(&rawCallback, x.xConditionWait) return func(DatagramBasedVar DatagramBased, ConditionVar glib.IOCondition, TimeoutVar int64, CancellableVar *Cancellable) bool { return rawCallback(DatagramBasedVar.GoPointer(), ConditionVar, TimeoutVar, CancellableVar.GoPointer()) } } // Interface for socket-like objects with datagram semantics. // // A `GDatagramBased` is a networking interface for representing datagram-based // communications. It is a more or less direct mapping of the core parts of the // BSD socket API in a portable GObject interface. It is implemented by // [class@Gio.Socket], which wraps the UNIX socket API on UNIX and winsock2 on Windows. // // `GDatagramBased` is entirely platform independent, and is intended to be used // alongside higher-level networking APIs such as [class@Gio.IOStream]. // // It uses vectored scatter/gather I/O by default, allowing for many messages // to be sent or received in a single call. Where possible, implementations of // the interface should take advantage of vectored I/O to minimise processing // or system calls. For example, `GSocket` uses `recvmmsg()` and `sendmmsg()` // where possible. Callers should take advantage of scatter/gather I/O (the use of // multiple buffers per message) to avoid unnecessary copying of data to // assemble or disassemble a message. // // Each `GDatagramBased` operation has a timeout parameter which may be negative // for blocking behaviour, zero for non-blocking behaviour, or positive for // timeout behaviour. A blocking operation blocks until finished or there is an // error. A non-blocking operation will return immediately with a // `G_IO_ERROR_WOULD_BLOCK` error if it cannot make progress. A timeout operation // will block until the operation is complete or the timeout expires; if the // timeout expires it will return what progress it made, or // `G_IO_ERROR_TIMED_OUT` if no progress was made. To know when a call would // successfully run you can call [method@Gio.DatagramBased.condition_check] or // [method@Gio.DatagramBased.condition_wait]. You can also use // [method@Gio.DatagramBased.create_source] and attach it to a [struct@GLib.MainContext] // to get callbacks when I/O is possible. // // When running a non-blocking operation applications should always be able to // handle getting a `G_IO_ERROR_WOULD_BLOCK` error even when some other function // said that I/O was possible. This can easily happen in case of a race // condition in the application, but it can also happen for other reasons. For // instance, on Windows a socket is always seen as writable until a write // returns `G_IO_ERROR_WOULD_BLOCK`. // // As with `GSocket`, `GDatagramBased`s can be either connection oriented (for // example, SCTP) or connectionless (for example, UDP). `GDatagramBased`s must be // datagram-based, not stream-based. The interface does not cover connection // establishment — use methods on the underlying type to establish a connection // before sending and receiving data through the `GDatagramBased` API. For // connectionless socket types the target/source address is specified or // received in each I/O operation. // // Like most other APIs in GLib, `GDatagramBased` is not inherently thread safe. // To use a `GDatagramBased` concurrently from multiple threads, you must // implement your own locking. type DatagramBased interface { GoPointer() uintptr SetGoPointer(uintptr) ConditionCheck(ConditionVar glib.IOCondition) glib.IOCondition ConditionWait(ConditionVar glib.IOCondition, TimeoutVar int64, CancellableVar *Cancellable) (bool, error) CreateSource(ConditionVar glib.IOCondition, CancellableVar *Cancellable) *glib.Source ReceiveMessages(MessagesVar []InputMessage, NumMessagesVar uint, FlagsVar int, TimeoutVar int64, CancellableVar *Cancellable) (int, error) SendMessages(MessagesVar []OutputMessage, NumMessagesVar uint, FlagsVar int, TimeoutVar int64, CancellableVar *Cancellable) (int, error) } var xDatagramBasedGLibType func() types.GType func DatagramBasedGLibType() types.GType { return xDatagramBasedGLibType() } type DatagramBasedBase struct { Ptr uintptr } func (x *DatagramBasedBase) GoPointer() uintptr { if x == nil { return 0 } return x.Ptr } func (x *DatagramBasedBase) SetGoPointer(ptr uintptr) { x.Ptr = ptr } // Checks on the readiness of @datagram_based to perform operations. The // operations specified in @condition are checked for and masked against the // currently-satisfied conditions on @datagram_based. The result is returned. // // %G_IO_IN will be set in the return value if data is available to read with // g_datagram_based_receive_messages(), or if the connection is closed remotely // (EOS); and if the datagram_based has not been closed locally using some // implementation-specific method (such as g_socket_close() or // g_socket_shutdown() with @shutdown_read set, if it’s a #GSocket). // // If the connection is shut down or closed (by calling g_socket_close() or // g_socket_shutdown() with @shutdown_read set, if it’s a #GSocket, for // example), all calls to this function will return %G_IO_ERROR_CLOSED. // // %G_IO_OUT will be set if it is expected that at least one byte can be sent // using g_datagram_based_send_messages() without blocking. It will not be set // if the datagram_based has been closed locally. // // %G_IO_HUP will be set if the connection has been closed locally. // // %G_IO_ERR will be set if there was an asynchronous error in transmitting data // previously enqueued using g_datagram_based_send_messages(). // // Note that on Windows, it is possible for an operation to return // %G_IO_ERROR_WOULD_BLOCK even immediately after // g_datagram_based_condition_check() has claimed that the #GDatagramBased is // ready for writing. Rather than calling g_datagram_based_condition_check() and // then writing to the #GDatagramBased if it succeeds, it is generally better to // simply try writing right away, and try again later if the initial attempt // returns %G_IO_ERROR_WOULD_BLOCK. // // It is meaningless to specify %G_IO_ERR or %G_IO_HUP in @condition; these // conditions will always be set in the output if they are true. Apart from // these flags, the output is guaranteed to be masked by @condition. // // This call never blocks. func (x *DatagramBasedBase) ConditionCheck(ConditionVar glib.IOCondition) glib.IOCondition { cret := XGDatagramBasedConditionCheck(x.GoPointer(), ConditionVar) return cret } // Waits for up to @timeout microseconds for condition to become true on // @datagram_based. If the condition is met, %TRUE is returned. // // If @cancellable is cancelled before the condition is met, or if @timeout is // reached before the condition is met, then %FALSE is returned and @error is // set appropriately (%G_IO_ERROR_CANCELLED or %G_IO_ERROR_TIMED_OUT). func (x *DatagramBasedBase) ConditionWait(ConditionVar glib.IOCondition, TimeoutVar int64, CancellableVar *Cancellable) (bool, error) { var cerr *glib.Error cret := XGDatagramBasedConditionWait(x.GoPointer(), ConditionVar, TimeoutVar, CancellableVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } // Creates a #GSource that can be attached to a #GMainContext to monitor for // the availability of the specified @condition on the #GDatagramBased. The // #GSource keeps a reference to the @datagram_based. // // The callback on the source is of the #GDatagramBasedSourceFunc type. // // It is meaningless to specify %G_IO_ERR or %G_IO_HUP in @condition; these // conditions will always be reported in the callback if they are true. // // If non-%NULL, @cancellable can be used to cancel the source, which will // cause the source to trigger, reporting the current condition (which is // likely 0 unless cancellation happened at the same time as a condition // change). You can check for this in the callback using // g_cancellable_is_cancelled(). func (x *DatagramBasedBase) CreateSource(ConditionVar glib.IOCondition, CancellableVar *Cancellable) *glib.Source { cret := XGDatagramBasedCreateSource(x.GoPointer(), ConditionVar, CancellableVar.GoPointer()) return cret } // Receive one or more data messages from @datagram_based in one go. // // @messages must point to an array of #GInputMessage structs and // @num_messages must be the length of this array. Each #GInputMessage // contains a pointer to an array of #GInputVector structs describing the // buffers that the data received in each message will be written to. // // @flags modify how all messages are received. The commonly available // arguments for this are available in the #GSocketMsgFlags enum, but the // values there are the same as the system values, and the flags // are passed in as-is, so you can pass in system-specific flags too. These // flags affect the overall receive operation. Flags affecting individual // messages are returned in #GInputMessage.flags. // // The other members of #GInputMessage are treated as described in its // documentation. // // If @timeout is negative the call will block until @num_messages have been // received, the connection is closed remotely (EOS), @cancellable is cancelled, // or an error occurs. // // If @timeout is 0 the call will return up to @num_messages without blocking, // or %G_IO_ERROR_WOULD_BLOCK if no messages are queued in the operating system // to be received. // // If @timeout is positive the call will block on the same conditions as if // @timeout were negative. If the timeout is reached // before any messages are received, %G_IO_ERROR_TIMED_OUT is returned, // otherwise it will return the number of messages received before timing out. // (Note: This is effectively the behaviour of `MSG_WAITFORONE` with // recvmmsg().) // // To be notified when messages are available, wait for the %G_IO_IN condition. // Note though that you may still receive %G_IO_ERROR_WOULD_BLOCK from // g_datagram_based_receive_messages() even if you were previously notified of a // %G_IO_IN condition. // // If the remote peer closes the connection, any messages queued in the // underlying receive buffer will be returned, and subsequent calls to // g_datagram_based_receive_messages() will return 0 (with no error set). // // If the connection is shut down or closed (by calling g_socket_close() or // g_socket_shutdown() with @shutdown_read set, if it’s a #GSocket, for // example), all calls to this function will return %G_IO_ERROR_CLOSED. // // On error -1 is returned and @error is set accordingly. An error will only // be returned if zero messages could be received; otherwise the number of // messages successfully received before the error will be returned. If // @cancellable is cancelled, %G_IO_ERROR_CANCELLED is returned as with any // other error. func (x *DatagramBasedBase) ReceiveMessages(MessagesVar []InputMessage, NumMessagesVar uint, FlagsVar int, TimeoutVar int64, CancellableVar *Cancellable) (int, error) { var cerr *glib.Error cret := XGDatagramBasedReceiveMessages(x.GoPointer(), MessagesVar, NumMessagesVar, FlagsVar, TimeoutVar, CancellableVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } // Send one or more data messages from @datagram_based in one go. // // @messages must point to an array of #GOutputMessage structs and // @num_messages must be the length of this array. Each #GOutputMessage // contains an address to send the data to, and a pointer to an array of // #GOutputVector structs to describe the buffers that the data to be sent // for each message will be gathered from. // // @flags modify how the message is sent. The commonly available arguments // for this are available in the #GSocketMsgFlags enum, but the // values there are the same as the system values, and the flags // are passed in as-is, so you can pass in system-specific flags too. // // The other members of #GOutputMessage are treated as described in its // documentation. // // If @timeout is negative the call will block until @num_messages have been // sent, @cancellable is cancelled, or an error occurs. // // If @timeout is 0 the call will send up to @num_messages without blocking, // or will return %G_IO_ERROR_WOULD_BLOCK if there is no space to send messages. // // If @timeout is positive the call will block on the same conditions as if // @timeout were negative. If the timeout is reached before any messages are // sent, %G_IO_ERROR_TIMED_OUT is returned, otherwise it will return the number // of messages sent before timing out. // // To be notified when messages can be sent, wait for the %G_IO_OUT condition. // Note though that you may still receive %G_IO_ERROR_WOULD_BLOCK from // g_datagram_based_send_messages() even if you were previously notified of a // %G_IO_OUT condition. (On Windows in particular, this is very common due to // the way the underlying APIs work.) // // If the connection is shut down or closed (by calling g_socket_close() or // g_socket_shutdown() with @shutdown_write set, if it’s a #GSocket, for // example), all calls to this function will return %G_IO_ERROR_CLOSED. // // On error -1 is returned and @error is set accordingly. An error will only // be returned if zero messages could be sent; otherwise the number of messages // successfully sent before the error will be returned. If @cancellable is // cancelled, %G_IO_ERROR_CANCELLED is returned as with any other error. func (x *DatagramBasedBase) SendMessages(MessagesVar []OutputMessage, NumMessagesVar uint, FlagsVar int, TimeoutVar int64, CancellableVar *Cancellable) (int, error) { var cerr *glib.Error cret := XGDatagramBasedSendMessages(x.GoPointer(), MessagesVar, NumMessagesVar, FlagsVar, TimeoutVar, CancellableVar.GoPointer(), &cerr) if cerr == nil { return cret, nil } return cret, cerr } var XGDatagramBasedConditionCheck func(uintptr, glib.IOCondition) glib.IOCondition var XGDatagramBasedConditionWait func(uintptr, glib.IOCondition, int64, uintptr, **glib.Error) bool var XGDatagramBasedCreateSource func(uintptr, glib.IOCondition, uintptr) *glib.Source var XGDatagramBasedReceiveMessages func(uintptr, []InputMessage, uint, int, int64, uintptr, **glib.Error) int var XGDatagramBasedSendMessages func(uintptr, []OutputMessage, uint, int, int64, uintptr, **glib.Error) int 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(&xDatagramBasedGLibType, libs, "g_datagram_based_get_type") core.PuregoSafeRegister(&XGDatagramBasedConditionCheck, libs, "g_datagram_based_condition_check") core.PuregoSafeRegister(&XGDatagramBasedConditionWait, libs, "g_datagram_based_condition_wait") core.PuregoSafeRegister(&XGDatagramBasedCreateSource, libs, "g_datagram_based_create_source") core.PuregoSafeRegister(&XGDatagramBasedReceiveMessages, libs, "g_datagram_based_receive_messages") core.PuregoSafeRegister(&XGDatagramBasedSendMessages, libs, "g_datagram_based_send_messages") }