Sets our main struct and passes it to the parent class
Creates a new GSocket with the defined family, type and protocol. If protocol is 0 (G_SOCKET_PROTOCOL_DEFAULT) the default protocol type for the family and type is used. The protocol is a family and type specific int that specifies what kind of protocol to use. GSocketProtocol lists several common ones. Many families only support one protocol, and use 0 for this, others support several and using 0 means to use the default protocol for the family and type. The protocol id is passed directly to the operating system, so you can use protocols not listed in GSocketProtocol if you know the protocol number used for it. Since 2.22
Creates a new GSocket from a native file descriptor or winsock SOCKET handle. This reads all the settings from the file descriptor so that all properties should work. Note that the file descriptor will be set to non-blocking mode, independent on the blocking mode of the GSocket. Since 2.22
Accept incoming connections on a connection-based socket. This removes the first outstanding connection request from the listening socket and creates a GSocket object for it. The socket must be bound to a local address with g_socket_bind() and must be listening for incoming connections (g_socket_listen()). If there are no outstanding connections then the operation will block or return G_IO_ERROR_WOULD_BLOCK if non-blocking I/O is enabled. To be notified of an incoming connection, wait for the G_IO_IN condition. Since 2.22
When a socket is created it is attached to an address family, but it doesn't have an address in this family. g_socket_bind() assigns the address (sometimes called name) of the socket. It is generally required to bind to a local address before you can receive connections. (See g_socket_listen() and g_socket_accept() ). In certain situations, you may also want to bind a socket that will be used to initiate connections, though this is not normally required. allow_reuse should be TRUE for server sockets (sockets that you will eventually call g_socket_accept() on), and FALSE for client sockets. (Specifically, if it is TRUE, then g_socket_bind() will set the SO_REUSEADDR flag on the socket, allowing it to bind address even if that address was previously used by another socket that has not yet been fully cleaned-up by the kernel. Failing to set this flag on a server socket may cause the bind call to return G_IO_ERROR_ADDRESS_IN_USE if the server program is stopped and then immediately restarted.) Since 2.22
Checks and resets the pending connect error for the socket. This is used to check for errors when g_socket_connect() is used in non-blocking mode. Since 2.22
Closes the socket, shutting down any active connection. Closing a socket does not wait for all outstanding I/O operations to finish, so the caller should not rely on them to be guaranteed to complete even if the close returns with no error. Once the socket is closed, all other operations will return G_IO_ERROR_CLOSED. Closing a socket multiple times will not return an error. Sockets will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible. Beware that due to the way that TCP works, it is possible for recently-sent data to be lost if either you close a socket while the G_IO_IN condition is set, or else if the remote connection tries to send something to you after you close the socket but before it has finished reading all of the data you sent. There is no easy generic way to avoid this problem; the easiest fix is to design the network protocol such that the client will never send data "out of turn". Another solution is for the server to half-close the connection by calling g_socket_shutdown() with only the shutdown_write flag set, and then wait for the client to notice this and close its side of the connection, after which the server can safely call g_socket_close(). (This is what GTcpConnection does if you call g_tcp_connection_set_graceful_disconnect(). But of course, this only works if the client will close its connection after the server does.) Since 2.22
Checks on the readiness of socket to perform operations. The operations specified in condition are checked for and masked against the currently-satisfied conditions on socket. The result is returned. Note that on Windows, it is possible for an operation to return G_IO_ERROR_WOULD_BLOCK even immediately after g_socket_condition_check() has claimed that the socket is ready for writing. Rather than calling g_socket_condition_check() and then writing to the socket if it succeeds, it is generally better to simply try writing to the socket 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. This call never blocks. Since 2.22
Waits for condition to become true on socket. When the condition is met, TRUE is returned. If cancellable is cancelled before the condition is met, or if the socket has a timeout set and it is reached before the condition is met, then FALSE is returned and error, if non-NULL, is set to the appropriate value (G_IO_ERROR_CANCELLED or G_IO_ERROR_TIMED_OUT). Since 2.22
Connect the socket to the specified remote address. For connection oriented socket this generally means we attempt to make a connection to the address. For a connection-less socket it sets the default address for g_socket_send() and discards all incoming datagrams from other sources. Generally connection oriented sockets can only connect once, but connection-less sockets can connect multiple times to change the default address. If the connect call needs to do network I/O it will block, unless non-blocking I/O is enabled. Then G_IO_ERROR_PENDING is returned and the user can be notified of the connection finishing by waiting for the G_IO_OUT condition. The result of the connection can then be checked with g_socket_check_connect_result(). Since 2.22
Creates a GSource that can be attached to a GMainContext to monitor for the availibility of the specified condition on the socket. The callback on the source is of the GSocketSourceFunc type. It is meaningless to specify G_IO_ERR or G_IO_HUP in condition; these conditions will always be reported output if they are true. cancellable if not NULL 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(). If socket has a timeout set, and it is reached before condition occurs, the source will then trigger anyway, reporting G_IO_IN or G_IO_OUT depending on condition. However, socket will have been marked as having had a timeout, and so the next GSocket I/O method you call will then fail with a G_IO_ERROR_TIMED_OUT. Since 2.22
Gets the blocking mode of the socket. For details on blocking I/O, see g_socket_set_blocking(). Since 2.22
Returns the credentials of the foreign process connected to this socket, if any (e.g. it is only supported for G_SOCKET_FAMILY_UNIX sockets). If this operation isn't supported on the OS, the method fails with the G_IO_ERROR_NOT_SUPPORTED error. On Linux this is implemented by reading the SO_PEERCRED option on the underlying socket. Other ways to obtain credentials from a foreign peer includes the GUnixCredentialsMessage type and g_unix_connection_send_credentials() / g_unix_connection_receive_credentials() functions. Since 2.26
Gets the socket family of the socket. Since 2.22
Returns the underlying OS socket object. On unix this is a socket file descriptor, and on windows this is a Winsock2 SOCKET handle. This may be useful for doing platform specific or otherwise unusual operations on the socket. Since 2.22
Gets the keepalive mode of the socket. For details on this, see g_socket_set_keepalive(). Since 2.22
Gets the listen backlog setting of the socket. For details on this, see g_socket_set_listen_backlog(). Since 2.22
Try to get the local address of a bound socket. This is only useful if the socket has been bound to a local address, either explicitly or implicitly when connecting. Since 2.22
Gets the socket protocol id the socket was created with. In case the protocol is unknown, -1 is returned. Since 2.22
Try to get the remove address of a connected socket. This is only useful for connection oriented sockets that have been connected. Since 2.22
Gets the socket type of the socket. Since 2.22
the main Gtk struct as a void*
Gets the timeout setting of the socket. For details on this, see g_socket_set_timeout(). Since 2.26
Checks whether a socket is closed. Since 2.22
Check whether the socket is connected. This is only useful for connection-oriented sockets. Since 2.22
Marks the socket as a server socket, i.e. a socket that is used to accept incoming requests using g_socket_accept(). Before calling this the socket must be bound to a local address using g_socket_bind(). To set the maximum amount of outstanding clients, use g_socket_set_listen_backlog(). Since 2.22
Receive data (up to size bytes) from a socket. This is mainly used by connection-oriented sockets; it is identical to g_socket_receive_from() with address set to NULL. For G_SOCKET_TYPE_DATAGRAM and G_SOCKET_TYPE_SEQPACKET sockets, g_socket_receive() will always read either 0 or 1 complete messages from the socket. If the received message is too large to fit in buffer, then the data beyond size bytes will be discarded, without any explicit indication that this has occurred. For G_SOCKET_TYPE_STREAM sockets, g_socket_receive() can return any number of bytes, up to size. If more than size bytes have been received, the additional data will be returned in future calls to g_socket_receive(). If the socket is in blocking mode the call will block until there is some data to receive or there is an error. If there is no data available and the socket is in non-blocking mode, a G_IO_ERROR_WOULD_BLOCK error will be returned. To be notified when data is available, wait for the G_IO_IN condition. On error -1 is returned and error is set accordingly. Since 2.22
Receive data (up to size bytes) from a socket. If address is non-NULL then address will be set equal to the source address of the received packet. address is owned by the caller. See g_socket_receive() for additional information. Since 2.22
Receive data from a socket. This is the most complicated and fully-featured version of this call. For easier use, see g_socket_receive() and g_socket_receive_from(). If address is non-NULL then address will be set equal to the source address of the received packet. address is owned by the caller. vector must point to an array of GInputVector structs and num_vectors must be the length of this array. These structs describe the buffers that received data will be scattered into. If num_vectors is -1, then vectors is assumed to be terminated by a GInputVector with a NULL buffer pointer. As a special case, if num_vectors is 0 (in which case, vectors may of course be NULL), then a single byte is received and discarded. This is to facilitate the common practice of sending a single '\0' byte for the purposes of transferring ancillary data. messages, if non-NULL, will be set to point to a newly-allocated array of GSocketControlMessage instances or NULL if no such messages was received. These correspond to the control messages received from the kernel, one GSocketControlMessage per message from the kernel. This array is NULL-terminated and must be freed by the caller using g_free() after calling g_object_unref() on each element. If messages is NULL, any control messages received will be discarded. num_messages, if non-NULL, will be set to the number of control messages received. If both messages and num_messages are non-NULL, then num_messages gives the number of GSocketControlMessage instances in messages (ie: not including the NULL terminator). flags is an in/out parameter. 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 (and g_socket_receive_message() may pass system-specific flags out). As with g_socket_receive(), data may be discarded if socket is G_SOCKET_TYPE_DATAGRAM or G_SOCKET_TYPE_SEQPACKET and you do not provide enough buffer space to read a complete message. You can pass G_SOCKET_MSG_PEEK in flags to peek at the current message without removing it from the receive queue, but there is no portable way to find out the length of the message other than by reading it into a sufficiently-large buffer. If the socket is in blocking mode the call will block until there is some data to receive or there is an error. If there is no data available and the socket is in non-blocking mode, a G_IO_ERROR_WOULD_BLOCK error will be returned. To be notified when data is available, wait for the G_IO_IN condition. On error -1 is returned and error is set accordingly. Since 2.22
This behaves exactly the same as g_socket_receive(), except that the choice of blocking or non-blocking behavior is determined by the blocking argument rather than by socket's properties. Since 2.26
Tries to send size bytes from buffer on the socket. This is mainly used by connection-oriented sockets; it is identical to g_socket_send_to() with address set to NULL. If the socket is in blocking mode the call will block until there is space for the data in the socket queue. If there is no space available and the socket is in non-blocking mode a G_IO_ERROR_WOULD_BLOCK error will be returned. To be notified when space is available, wait for the G_IO_OUT condition. Note though that you may still receive G_IO_ERROR_WOULD_BLOCK from g_socket_send() 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.) On error -1 is returned and error is set accordingly. Since 2.22
Send data to address on socket. This is the most complicated and fully-featured version of this call. For easier use, see g_socket_send() and g_socket_send_to(). If address is NULL then the message is sent to the default receiver (set by g_socket_connect()). vectors must point to an array of GOutputVector structs and num_vectors must be the length of this array. (If num_vectors is -1, then vectors is assumed to be terminated by a GOutputVector with a NULL buffer pointer.) The GOutputVector structs describe the buffers that the sent data will be gathered from. Using multiple GOutputVectors is more memory-efficient than manually copying data from multiple sources into a single buffer, and more network-efficient than making multiple calls to g_socket_send(). messages, if non-NULL, is taken to point to an array of num_messages GSocketControlMessage instances. These correspond to the control messages to be sent on the socket. If num_messages is -1 then messages is treated as a NULL-terminated array. 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. If the socket is in blocking mode the call will block until there is space for the data in the socket queue. If there is no space available and the socket is in non-blocking mode a G_IO_ERROR_WOULD_BLOCK error will be returned. To be notified when space is available, wait for the G_IO_OUT condition. Note though that you may still receive G_IO_ERROR_WOULD_BLOCK from g_socket_send() 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.) On error -1 is returned and error is set accordingly. Since 2.22
Tries to send size bytes from buffer to address. If address is NULL then the message is sent to the default receiver (set by g_socket_connect()). See g_socket_send() for additional information. Since 2.22
This behaves exactly the same as g_socket_send(), except that the choice of blocking or non-blocking behavior is determined by the blocking argument rather than by socket's properties. Since 2.26
Sets the blocking mode of the socket. In blocking mode all operations block until they succeed or there is an error. In non-blocking mode all functions return results immediately or with a G_IO_ERROR_WOULD_BLOCK error. All sockets are created in blocking mode. However, note that the platform level socket is always non-blocking, and blocking mode is a GSocket level feature. Since 2.22
Sets or unsets the SO_KEEPALIVE flag on the underlying socket. When this flag is set on a socket, the system will attempt to verify that the remote socket endpoint is still present if a sufficiently long period of time passes with no data being exchanged. If the system is unable to verify the presence of the remote endpoint, it will automatically close the connection. This option is only functional on certain kinds of sockets. (Notably, G_SOCKET_PROTOCOL_TCP sockets.) The exact time between pings is system- and protocol-dependent, but will normally be at least two hours. Most commonly, you would set this flag on a server socket if you want to allow clients to remain idle for long periods of time, but also want to ensure that connections are eventually garbage-collected if clients crash or become unreachable. Since 2.22
Sets the maximum number of outstanding connections allowed when listening on this socket. If more clients than this are connecting to the socket and the application is not handling them on time then the new connections will be refused. Note that this must be called before g_socket_listen() and has no effect if called after that. Since 2.22
Sets the time in seconds after which I/O operations on socket will time out if they have not yet completed. On a blocking socket, this means that any blocking GSocket operation will time out after timeout seconds of inactivity, returning G_IO_ERROR_TIMED_OUT. On a non-blocking socket, calls to g_socket_condition_wait() will also fail with G_IO_ERROR_TIMED_OUT after the given time. Sources created with g_socket_create_source() will trigger after timeout seconds of inactivity, with the requested condition set, at which point calling g_socket_receive(), g_socket_send(), g_socket_check_connect_result(), etc, will fail with G_IO_ERROR_TIMED_OUT. If timeout is 0 (the default), operations will never time out on their own. Note that if an I/O operation is interrupted by a signal, this may cause the timeout to be reset. Since 2.26
Shut down part of a full-duplex connection. If shutdown_read is TRUE then the recieving side of the connection is shut down, and further reading is disallowed. If shutdown_write is TRUE then the sending side of the connection is shut down, and further writing is disallowed. It is allowed for both shutdown_read and shutdown_write to be TRUE. One example where this is used is graceful disconnect for TCP connections where you close the sending side, then wait for the other side to close the connection, thus ensuring that the other side saw all sent data. Since 2.22
Checks if a socket is capable of speaking IPv4. IPv4 sockets are capable of speaking IPv4. On some operating systems and under some combinations of circumstances IPv6 sockets are also capable of speaking IPv4. See RFC 3493 section 3.7 for more information. No other types of sockets are currently considered as being capable of speaking IPv4. Since 2.22
the main Gtk struct
the main Gtk struct
the main Gtk struct as a void*
Gets a D Object from the objects table of associations.
The notify signal is emitted on an object when one of its properties has been changed. Note that getting this signal doesn't guarantee that the value of the property has actually changed, it may also be emitted when the setter for the property is called to reinstate the previous value. This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the It is important to note that you must use canonical parameter names as detail strings for the notify signal. See Also GParamSpecObject, g_param_spec_object()
Installs a new property. This is usually done in the class initializer. Note that it is possible to redefine a property in a derived class, by installing a property with the same name. This can be useful at times, e.g. to change the range of allowed values or the default value.
Installs new properties from an array of GParamSpecs. This is usually done in the class initializer. The property id of each property is the index of each GParamSpec in the pspecs array. The property id of 0 is treated specially by GObject and it should not be used to store a GParamSpec. This function should be used if you plan to use a static array of GParamSpecs and g_object_notify_by_pspec(). For instance, this Since 2.26
Looks up the GParamSpec for a property of a class.
Get an array of GParamSpec* for all properties of a class.
Registers property_id as referring to a property with the name name in a parent class or in an interface implemented by oclass. This allows this class to override a property implementation in a parent class or to provide the implementation of a property from an interface. Note Internally, overriding is implemented by creating a property of type GParamSpecOverride; generally operations that query the properties of the object class, such as g_object_class_find_property() or g_object_class_list_properties() will return the overridden property. However, in one case, the construct_properties argument of the constructor virtual function, the GParamSpecOverride is passed instead, so that the param_id field of the GParamSpec will be correct. For virtually all uses, this makes no difference. If you need to get the overridden property, you can call g_param_spec_get_redirect_target(). Since 2.4
Add a property to an interface; this is only useful for interfaces that are added to GObject-derived types. Adding a property to an interface forces all objects classes with that interface to have a compatible property. The compatible property could be a newly created GParamSpec, but normally g_object_class_override_property() will be used so that the object class only needs to provide an implementation and inherits the property description, default value, bounds, and so forth from the interface property. This function is meant to be called from the interface's default vtable initialization function (the class_init member of GTypeInfo.) It must not be called after after class_init has been called for any object types implementing this interface. Since 2.4
Find the GParamSpec with the given name for an interface. Generally, the interface vtable passed in as g_iface will be the default vtable from g_type_default_interface_ref(), or, if you know the interface has already been loaded, g_type_default_interface_peek(). Since 2.4
Lists the properties of an interface.Generally, the interface vtable passed in as g_iface will be the default vtable from g_type_default_interface_ref(), or, if you know the interface has already been loaded, g_type_default_interface_peek(). Since 2.4
Increases the reference count of object.
Decreases the reference count of object. When its reference count drops to 0, the object is finalized (i.e. its memory is freed).
Increase the reference count of object, and possibly remove the floating reference, if object has a floating reference. In other words, if the object is floating, then this call "assumes ownership" of the floating reference, converting it to a normal reference by clearing the floating flag while leaving the reference count unchanged. If the object is not floating, then this call adds a new normal reference increasing the reference count by one. Since 2.10
Clears a reference to a GObject. object_ptr must not be NULL. If the reference is NULL then this function does nothing. Otherwise, the reference count of the object is decreased and the pointer is set to NULL. This function is threadsafe and modifies the pointer atomically, using memory barriers where needed. A macro is also included that allows this function to be used without pointer casts. Since 2.28
Checks whether object has a floating reference. Since 2.10
This function is intended for GObject implementations to re-enforce a floating object reference. Doing this is seldomly required: all GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling g_object_ref_sink(). Since 2.10
Adds a weak reference callback to an object. Weak references are used for notification when an object is finalized. They are called "weak references" because they allow you to safely hold a pointer to an object without calling g_object_ref() (g_object_ref() adds a strong reference, that is, forces the object to stay alive).
Removes a weak reference callback to an object.
Adds a weak reference from weak_pointer to object to indicate that the pointer located at weak_pointer_location is only valid during the lifetime of object. When the object is finalized, weak_pointer will be set to NULL.
Removes a weak reference from object that was previously added using g_object_add_weak_pointer(). The weak_pointer_location has to match the one used with g_object_add_weak_pointer().
Increases the reference count of the object by one and sets a callback to be called when all other references to the object are dropped, or when this is already the last reference to the object and another reference is established. This functionality is intended for binding object to a proxy object managed by another memory manager. This is done with two paired references: the strong reference added by g_object_add_toggle_ref() and a reverse reference to the proxy object which is either a strong reference or weak reference. The setup is that when there are no other references to object, only a weak reference is held in the reverse direction from object to the proxy object, but when there are other references held to object, a strong reference is held. The notify callback is called when the reference from object to the proxy object should be toggled from strong to weak (is_last_ref true) or weak to strong (is_last_ref false). Since a (normal) reference must be held to the object before calling g_object_toggle_ref(), the initial state of the reverse link is always strong. Multiple toggle references may be added to the same gobject, however if there are multiple toggle references to an object, none of them will ever be notified until all but one are removed. For this reason, you should only ever use a toggle reference if there is important state in the proxy object. Since 2.8
Removes a reference added with g_object_add_toggle_ref(). The reference count of the object is decreased by one. Since 2.8
Emits a "notify" signal for the property property_name on object. When possible, eg. when signaling a property change from within the class that registered the property, you should use g_object_notify_by_pspec() instead.
Emits a "notify" signal for the property specified by pspec on object. This function omits the property name lookup, hence it is faster than g_object_notify(). One way to avoid using g_object_notify() from within the class that registered the properties, and using g_object_notify_by_pspec() instead, is to store the GParamSpec used with Since 2.26
Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. This is necessary for accessors that modify multiple properties to prevent premature notification while the object is still being modified.
Reverts the effect of a previous call to g_object_freeze_notify(). The freeze count is decreased on object and when it reaches zero, all queued "notify" signals are emitted. It is an error to call this function when the freeze count is zero.
Gets a named field from the objects table of associations (see g_object_set_data()).
Each object carries around a table of associations from strings to pointers. This function lets you set an association. If the object already had an association with that name, the old association will be destroyed.
Like g_object_set_data() except it adds notification for when the association is destroyed, either by setting it to a different value or when the object is destroyed. Note that the destroy callback is not called if data is NULL.
Remove a specified datum from the object's data associations, without invoking the association's destroy handler.
This function gets back user data pointers stored via g_object_set_qdata().
This sets an opaque, named pointer on an object. The name is specified through a GQuark (retrived e.g. via g_quark_from_static_string()), and the pointer can be gotten back from the object with g_object_get_qdata() until the object is finalized. Setting a previously set user data pointer, overrides (frees) the old pointer set, using NULL as pointer essentially removes the data stored.
This function works like g_object_set_qdata(), but in addition, a void (*destroy) (gpointer) function may be specified which is called with data as argument when the object is finalized, or the data is being overwritten by a call to g_object_set_qdata() with the same quark.
This function gets back user data pointers stored via g_object_set_qdata() and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update
Sets a property on an object.
Gets a property of an object. value must have been initialized to the expected type of the property (or a type to which the expected type can be transformed) using g_value_init(). In general, a copy is made of the property contents and the caller is responsible for freeing the memory by calling g_value_unset(). Note that g_object_get_property() is really intended for language bindings, g_object_get() is much more convenient for C programming.
Sets properties on an object.
Gets properties of an object. In general, a copy is made of the property contents and the caller is responsible for freeing the memory in the appropriate manner for the type, for instance by calling g_free() or g_object_unref(). See g_object_get().
This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling g_closure_invalidate() on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, g_object_ref() and g_object_unref() are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.
Releases all references to other objects. This can be used to break reference cycles. This functions should only be called from object system implementations.
the main Gtk struct as a void*
Initializes the object implementing the interface. This must be done before any real use of the object after initial construction. Implementations may also support cancellation. If cancellable is not NULL, then initialization 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. If cancellable is not NULL and the object doesn't support cancellable initialization the error G_IO_ERROR_NOT_SUPPORTED will be returned. If this function is not called, or returns with an error then all operations on the object should fail, generally returning the error G_IO_ERROR_NOT_INITIALIZED. Implementations of this method must be idempotent, i.e. multiple calls to this function with the same argument should return the same results. Only the first call initializes the object, further calls return the result of the first call. This is so that its safe to implement the singleton pattern in the GObject constructor function. Since 2.22
Helper function for constructing GInitiable object. This is similar to g_object_new_valist() but also initializes the object and returns NULL, setting an error on failure. Since 2.22
Helper function for constructing GInitiable object. This is similar to g_object_newv() but also initializes the object and returns NULL, setting an error on failure. Since 2.22
Description A GSocket is a low-level networking primitive. It is a more or less direct mapping of the BSD socket API in a portable GObject based API. It supports both the UNIX socket implementations and winsock2 on Windows. GSocket is the platform independent base upon which the higher level network primitives are based. Applications are not typically meant to use it directly, but rather through classes like GSocketClient, GSocketService and GSocketConnection. However there may be cases where direct use of GSocket is useful. GSocket implements the GInitable interface, so if it is manually constructed by e.g. g_object_new() you must call g_initable_init() and check the results before using the object. This is done automatically in g_socket_new() and g_socket_new_from_fd(), so these functions can return NULL. Sockets operate in two general modes, blocking or non-blocking. When in blocking mode all operations block until the requested operation is finished or there is an error. In non-blocking mode all calls that would block return immediately with a G_IO_ERROR_WOULD_BLOCK error. To know when a call would successfully run you can call g_socket_condition_check(), or g_socket_condition_wait(). You can also use g_socket_create_source() and attach it to a GMainContext to get callbacks when I/O is possible. Note that all sockets are always set to non blocking mode in the system, and blocking mode is emulated in GSocket. When working in non-blocking mode 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. GSockets can be either connection oriented or datagram based. For connection oriented types you must first establish a connection by either connecting to an address or accepting a connection from another address. For connectionless socket types the target/source address is specified or received in each I/O operation. All socket file descriptors are set to be close-on-exec. Note that creating a GSocket causes the signal SIGPIPE to be ignored for the remainder of the program. If you are writing a command-line utility that uses GSocket, you may need to take into account the fact that your program will not automatically be killed if it tries to write to stdout after it has been closed.