gio

Struct Socket

Source
pub struct Socket { /* private fields */ }
Expand 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 SocketClient, SocketService and SocketConnection. However there may be cases where direct use of GSocket is useful.

GSocket implements the Initable interface, so if it is manually constructed by e.g. glib::Object::new() you must call InitableExt::init() and check the results before using the object. This is done automatically in new() and from_fd(), so these functions can return NULL.

Sockets operate in two general modes, blocking or non-blocking. When in blocking mode all operations (which don’t take an explicit blocking parameter) 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 SocketExt::condition_check(), or SocketExt::condition_wait(). You can also use Gio::Socket::create_source() and attach it to a [type@GLib.MainContext] 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.

Like most other APIs in GLib, GSocket is not inherently thread safe. To use a GSocket concurrently from multiple threads, you must implement your own locking.

§Nagle’s algorithm

Since GLib 2.80, GSocket will automatically set the TCP_NODELAY option on all G_SOCKET_TYPE_STREAM sockets. This disables Nagle’s algorithm as it typically does more harm than good on modern networks.

If your application needs Nagle’s algorithm enabled, call SocketExt::set_option() after constructing a GSocket to enable it: ⚠️ The following code is in c ⚠️

socket = g_socket_new (…, G_SOCKET_TYPE_STREAM, …);
if (socket != NULL)
  {
    g_socket_set_option (socket, IPPROTO_TCP, TCP_NODELAY, FALSE, &local_error);
    // handle error if needed
  }

§Properties

§blocking

Whether I/O on this socket is blocking.

Readable | Writeable

§broadcast

Whether the socket should allow sending to broadcast addresses.

Readable | Writeable

§family

The socket’s address family.

Readable | Writeable | Construct Only

§fd

The socket’s file descriptor.

Readable | Writeable | Construct Only

§keepalive

Whether to keep the connection alive by sending periodic pings.

Readable | Writeable

§listen-backlog

The number of outstanding connections in the listen queue.

Readable | Writeable

§local-address

The local address the socket is bound to.

Readable

§multicast-loopback

Whether outgoing multicast packets loop back to the local host.

Readable | Writeable

§multicast-ttl

Time-to-live out outgoing multicast packets

Readable | Writeable

§protocol

The ID of the protocol to use, or -1 for unknown.

Readable | Writeable | Construct Only

§remote-address

The remote address the socket is connected to.

Readable

§timeout

The timeout in seconds on socket I/O

Readable | Writeable

§ttl

Time-to-live for outgoing unicast packets

Readable | Writeable

§type

The socket’s type.

Readable | Writeable | Construct Only

§Implements

SocketExt, [trait@glib::ObjectExt], DatagramBasedExt, InitableExt, SocketExtManual, DatagramBasedExtManual

GLib type: GObject with reference counted clone semantics.

Implementations§

Source§

impl Socket

Source

pub unsafe fn from_fd(fd: impl IntoRawFd) -> Result<Socket, Error>

Available on Unix only.

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.

On success, the returned #GSocket takes ownership of @fd. On failure, the caller must close @fd themselves.

Since GLib 2.46, it is no longer a fatal error to call this on a non-socket descriptor. Instead, a GError will be set with code IOErrorEnum::Failed

§fd

a native socket file descriptor.

§Returns

a #GSocket or None on error. Free the returned object with g_object_unref().

Source§

impl Socket

Source

pub const NONE: Option<&'static Socket> = None

Source

pub fn new( family: SocketFamily, type_: SocketType, protocol: SocketProtocol, ) -> Result<Socket, Error>

Creates a new #GSocket with the defined family, type and protocol. If @protocol is 0 (SocketProtocol::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.

§family

the socket family to use, e.g. SocketFamily::Ipv4.

§type_

the socket type to use.

§protocol

the id of the protocol to use, or 0 for default.

§Returns

a #GSocket or None on error. Free the returned object with g_object_unref().

Trait Implementations§

Source§

impl AsRawFd for Socket

Available on Unix only.
Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl Clone for Socket

Source§

fn clone(&self) -> Self

Makes a clone of this shared reference.

This increments the strong reference count of the object. Dropping the object will decrement it again.

1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Socket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl HasParamSpec for Socket

Source§

type ParamSpec = ParamSpecObject

Source§

type SetValue = Socket

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(_: &str) -> ParamSpecObjectBuilder<'_, Socket>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for Socket

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Hashes the memory address of this object.

1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Socket

Source§

fn cmp(&self, other: &Self) -> Ordering

Comparison for two GObjects.

Compares the memory addresses of the provided objects.

1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl ParentClassIs for Socket

Source§

impl<OT: ObjectType> PartialEq<OT> for Socket

Source§

fn eq(&self, other: &OT) -> bool

Equality for two GObjects.

Two GObjects are equal if their memory addresses are equal.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<OT: ObjectType> PartialOrd<OT> for Socket

Source§

fn partial_cmp(&self, other: &OT) -> Option<Ordering>

Partial comparison for two GObjects.

Compares the memory addresses of the provided objects.

1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for Socket

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for Socket

Source§

impl IsA<DatagramBased> for Socket

Source§

impl IsA<Initable> for Socket

Auto Trait Implementations§

§

impl Freeze for Socket

§

impl RefUnwindSafe for Socket

§

impl !Send for Socket

§

impl !Sync for Socket

§

impl Unpin for Socket

§

impl UnwindSafe for Socket

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Cast for T
where T: ObjectType,

Source§

fn upcast<T>(self) -> T
where T: ObjectType, Self: IsA<T>,

Upcasts an object to a superclass or interface T. Read more
Source§

fn upcast_ref<T>(&self) -> &T
where T: ObjectType, Self: IsA<T>,

Upcasts an object to a reference of its superclass or interface T. Read more
Source§

fn downcast<T>(self) -> Result<T, Self>
where T: ObjectType, Self: MayDowncastTo<T>,

Tries to downcast to a subclass or interface implementor T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: ObjectType, Self: MayDowncastTo<T>,

Tries to downcast to a reference of its subclass or interface implementor T. Read more
Source§

fn dynamic_cast<T>(self) -> Result<T, Self>
where T: ObjectType,

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while upcast will do many checks at compile-time already. downcast will perform the same checks at runtime as dynamic_cast, but will also ensure some amount of compile-time safety. Read more
Source§

fn dynamic_cast_ref<T>(&self) -> Option<&T>
where T: ObjectType,

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more
Source§

unsafe fn unsafe_cast<T>(self) -> T
where T: ObjectType,

Casts to T unconditionally. Read more
Source§

unsafe fn unsafe_cast_ref<T>(&self) -> &T
where T: ObjectType,

Casts to &T unconditionally. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<O> DatagramBasedExt for O
where O: IsA<DatagramBased>,

Source§

fn condition_check(&self, condition: IOCondition) -> IOCondition

Checks on the readiness of @self to perform operations. The operations specified in @condition are checked for and masked against the currently-satisfied conditions on @self. The result is returned. Read more
Source§

impl<O> DatagramBasedExtManual for O
where O: IsA<DatagramBased>,

Source§

fn create_source<F, C>( &self, condition: IOCondition, cancellable: Option<&C>, name: Option<&str>, priority: Priority, func: F, ) -> Source
where F: FnMut(&Self, IOCondition) -> ControlFlow + 'static, C: IsA<Cancellable>,

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 @self. Read more
Source§

fn create_source_future<C: IsA<Cancellable>>( &self, condition: IOCondition, cancellable: Option<&C>, priority: Priority, ) -> Pin<Box<dyn Future<Output = IOCondition> + 'static>>

Source§

fn create_source_stream<C: IsA<Cancellable>>( &self, condition: IOCondition, cancellable: Option<&C>, priority: Priority, ) -> Pin<Box<dyn Stream<Item = IOCondition> + 'static>>

Source§

fn condition_wait( &self, condition: IOCondition, timeout: Option<Duration>, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Waits for up to @timeout microseconds for condition to become true on @self. If the condition is met, true is returned. Read more
Source§

fn receive_messages<'v, V: IntoIterator<Item = &'v mut [&'v mut [u8]]>, C: IsA<Cancellable>>( &self, messages: &mut [InputMessage<'_>], flags: i32, timeout: Option<Duration>, cancellable: Option<&C>, ) -> Result<usize, Error>

Receive one or more data messages from @self in one go. Read more
Source§

fn send_messages<C: IsA<Cancellable>>( &self, messages: &mut [OutputMessage<'_>], flags: i32, timeout: Option<Duration>, cancellable: Option<&C>, ) -> Result<usize, Error>

Send one or more data messages from @self in one go. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<O> InitableExt for O
where O: IsA<Initable>,

Source§

unsafe fn init( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Initializes the object implementing the interface. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<U> IsSubclassableExt for U

Source§

impl<T> ObjectExt for T
where T: ObjectType,

Source§

fn is<U>(&self) -> bool
where U: StaticType,

Returns true if the object is an instance of (can be cast to) T.
Source§

fn type_(&self) -> Type

Returns the type of the object.
Source§

fn object_class(&self) -> &Class<Object>

Returns the ObjectClass of the object. Read more
Source§

fn class(&self) -> &Class<T>
where T: IsClass,

Returns the class of the object.
Source§

fn class_of<U>(&self) -> Option<&Class<U>>
where U: IsClass,

Returns the class of the object in the given type T. Read more
Source§

fn interface<U>(&self) -> Option<InterfaceRef<'_, U>>
where U: IsInterface,

Returns the interface T of the object. Read more
Source§

fn set_property(&self, property_name: &str, value: impl Into<Value>)

Sets the property property_name of the object to value value. Read more
Source§

fn set_property_from_value(&self, property_name: &str, value: &Value)

Sets the property property_name of the object to value value. Read more
Source§

fn set_properties(&self, property_values: &[(&str, &dyn ToValue)])

Sets multiple properties of the object at once. Read more
Source§

fn set_properties_from_value(&self, property_values: &[(&str, Value)])

Sets multiple properties of the object at once. Read more
Source§

fn property<V>(&self, property_name: &str) -> V
where V: for<'b> FromValue<'b> + 'static,

Gets the property property_name of the object and cast it to the type V. Read more
Source§

fn property_value(&self, property_name: &str) -> Value

Gets the property property_name of the object. Read more
Source§

fn has_property(&self, property_name: &str) -> bool

Check if the object has a property property_name.
Source§

fn has_property_with_type(&self, property_name: &str, type_: Type) -> bool

Check if the object has a property property_name of the given type_.
Source§

fn property_type(&self, property_name: &str) -> Option<Type>

Get the type of the property property_name of this object. Read more
Source§

fn find_property(&self, property_name: &str) -> Option<ParamSpec>

Get the ParamSpec of the property property_name of this object.
Source§

fn list_properties(&self) -> PtrSlice<ParamSpec>

Return all ParamSpec of the properties of this object.
Source§

fn freeze_notify(&self) -> PropertyNotificationFreezeGuard

Freeze all property notifications until the return guard object is dropped. Read more
Source§

unsafe fn set_qdata<QD>(&self, key: Quark, value: QD)
where QD: 'static,

Set arbitrary data on this object with the given key. Read more
Source§

unsafe fn qdata<QD>(&self, key: Quark) -> Option<NonNull<QD>>
where QD: 'static,

Return previously set arbitrary data of this object with the given key. Read more
Source§

unsafe fn steal_qdata<QD>(&self, key: Quark) -> Option<QD>
where QD: 'static,

Retrieve previously set arbitrary data of this object with the given key. Read more
Source§

unsafe fn set_data<QD>(&self, key: &str, value: QD)
where QD: 'static,

Set arbitrary data on this object with the given key. Read more
Source§

unsafe fn data<QD>(&self, key: &str) -> Option<NonNull<QD>>
where QD: 'static,

Return previously set arbitrary data of this object with the given key. Read more
Source§

unsafe fn steal_data<QD>(&self, key: &str) -> Option<QD>
where QD: 'static,

Retrieve previously set arbitrary data of this object with the given key. Read more
Source§

fn block_signal(&self, handler_id: &SignalHandlerId)

Block a given signal handler. Read more
Source§

fn unblock_signal(&self, handler_id: &SignalHandlerId)

Unblock a given signal handler.
Source§

fn stop_signal_emission(&self, signal_id: SignalId, detail: Option<Quark>)

Stop emission of the currently emitted signal.
Source§

fn stop_signal_emission_by_name(&self, signal_name: &str)

Stop emission of the currently emitted signal by the (possibly detailed) signal name.
Source§

fn connect<F>( &self, signal_name: &str, after: bool, callback: F, ) -> SignalHandlerId
where F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,

Connect to the signal signal_name on this object. Read more
Source§

fn connect_id<F>( &self, signal_id: SignalId, details: Option<Quark>, after: bool, callback: F, ) -> SignalHandlerId
where F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,

Connect to the signal signal_id on this object. Read more
Source§

fn connect_local<F>( &self, signal_name: &str, after: bool, callback: F, ) -> SignalHandlerId
where F: Fn(&[Value]) -> Option<Value> + 'static,

Connect to the signal signal_name on this object. Read more
Source§

fn connect_local_id<F>( &self, signal_id: SignalId, details: Option<Quark>, after: bool, callback: F, ) -> SignalHandlerId
where F: Fn(&[Value]) -> Option<Value> + 'static,

Connect to the signal signal_id on this object. Read more
Source§

unsafe fn connect_unsafe<F>( &self, signal_name: &str, after: bool, callback: F, ) -> SignalHandlerId
where F: Fn(&[Value]) -> Option<Value>,

Connect to the signal signal_name on this object. Read more
Source§

unsafe fn connect_unsafe_id<F>( &self, signal_id: SignalId, details: Option<Quark>, after: bool, callback: F, ) -> SignalHandlerId
where F: Fn(&[Value]) -> Option<Value>,

Connect to the signal signal_id on this object. Read more
Source§

fn connect_closure( &self, signal_name: &str, after: bool, closure: RustClosure, ) -> SignalHandlerId

Connect a closure to the signal signal_name on this object. Read more
Source§

fn connect_closure_id( &self, signal_id: SignalId, details: Option<Quark>, after: bool, closure: RustClosure, ) -> SignalHandlerId

Connect a closure to the signal signal_id on this object. Read more
Source§

fn watch_closure(&self, closure: &impl AsRef<Closure>)

Limits the lifetime of closure to the lifetime of the object. When the object’s reference count drops to zero, the closure will be invalidated. An invalidated closure will ignore any calls to invoke_with_values, or invoke when using Rust closures.
Source§

fn emit<R>(&self, signal_id: SignalId, args: &[&dyn ToValue]) -> R

Emit signal by signal id. Read more
Source§

fn emit_with_values(&self, signal_id: SignalId, args: &[Value]) -> Option<Value>

Same as Self::emit but takes Value for the arguments.
Source§

fn emit_by_name<R>(&self, signal_name: &str, args: &[&dyn ToValue]) -> R

Emit signal by its name. Read more
Source§

fn emit_by_name_with_values( &self, signal_name: &str, args: &[Value], ) -> Option<Value>

Emit signal by its name. Read more
Source§

fn emit_by_name_with_details<R>( &self, signal_name: &str, details: Quark, args: &[&dyn ToValue], ) -> R

Emit signal by its name with details. Read more
Source§

fn emit_by_name_with_details_and_values( &self, signal_name: &str, details: Quark, args: &[Value], ) -> Option<Value>

Emit signal by its name with details. Read more
Source§

fn emit_with_details<R>( &self, signal_id: SignalId, details: Quark, args: &[&dyn ToValue], ) -> R

Emit signal by signal id with details. Read more
Source§

fn emit_with_details_and_values( &self, signal_id: SignalId, details: Quark, args: &[Value], ) -> Option<Value>

Emit signal by signal id with details. Read more
Source§

fn disconnect(&self, handler_id: SignalHandlerId)

Disconnect a previously connected signal handler.
Source§

fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId
where F: Fn(&T, &ParamSpec) + Send + Sync + 'static,

Connect to the notify signal of the object. Read more
Source§

fn connect_notify_local<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId
where F: Fn(&T, &ParamSpec) + 'static,

Connect to the notify signal of the object. Read more
Source§

unsafe fn connect_notify_unsafe<F>( &self, name: Option<&str>, f: F, ) -> SignalHandlerId
where F: Fn(&T, &ParamSpec),

Connect to the notify signal of the object. Read more
Source§

fn notify(&self, property_name: &str)

Notify that the given property has changed its value. Read more
Source§

fn notify_by_pspec(&self, pspec: &ParamSpec)

Notify that the given property has changed its value. Read more
Source§

fn downgrade(&self) -> WeakRef<T>

Downgrade this object to a weak reference.
Source§

fn add_weak_ref_notify<F>(&self, f: F) -> WeakRefNotify<T>
where F: FnOnce() + Send + 'static,

Add a callback to be notified when the Object is disposed.
Source§

fn add_weak_ref_notify_local<F>(&self, f: F) -> WeakRefNotify<T>
where F: FnOnce() + 'static,

Add a callback to be notified when the Object is disposed. Read more
Source§

fn bind_property<'a, 'f, 't, O>( &'a self, source_property: &'a str, target: &'a O, target_property: &'a str, ) -> BindingBuilder<'a, 'f, 't>
where O: ObjectType,

Bind property source_property on this object to the target_property on the target object. Read more
Source§

fn ref_count(&self) -> u32

Returns the strong reference count of this object.
Source§

unsafe fn run_dispose(&self)

Runs the dispose mechanism of the object. Read more
Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<O> SocketExt for O
where O: IsA<Socket>,

Source§

fn accept( &self, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<Socket, Error>

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. Read more
Source§

fn bind( &self, address: &impl IsA<SocketAddress>, allow_reuse: bool, ) -> Result<(), Error>

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. Read more
Source§

fn check_connect_result(&self) -> Result<(), Error>

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. Read more
Source§

fn close(&self) -> Result<(), Error>

Closes the socket, shutting down any active connection. Read more
Source§

fn condition_check(&self, condition: IOCondition) -> IOCondition

Checks on the readiness of @self to perform operations. The operations specified in @condition are checked for and masked against the currently-satisfied conditions on @self. The result is returned. Read more
Source§

fn condition_timed_wait( &self, condition: IOCondition, timeout_us: i64, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Waits for up to @timeout_us microseconds for @condition to become true on @self. If the condition is met, true is returned. Read more
Source§

fn condition_wait( &self, condition: IOCondition, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Waits for @condition to become true on @self. When the condition is met, true is returned. Read more
Source§

fn connect( &self, address: &impl IsA<SocketAddress>, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Connect the socket to the specified remote address. Read more
Source§

fn connection_factory_create_connection(&self) -> SocketConnection

Creates a #GSocketConnection subclass of the right type for @self. Read more
Source§

fn available_bytes(&self) -> isize

Get the amount of data pending in the OS input buffer, without blocking. Read more
Source§

fn is_blocking(&self) -> bool

Gets the blocking mode of the socket. For details on blocking I/O, see g_socket_set_blocking(). Read more
Source§

fn is_broadcast(&self) -> bool

Gets the broadcast setting on @self; if true, it is possible to send packets to broadcast addresses. Read more
Source§

fn credentials(&self) -> Result<Credentials, Error>

Returns the credentials of the foreign process connected to this socket, if any (e.g. it is only supported for SocketFamily::Unix sockets). Read more
Source§

fn family(&self) -> SocketFamily

Gets the socket family of the socket. Read more
Source§

fn is_keepalive(&self) -> bool

Gets the keepalive mode of the socket. For details on this, see g_socket_set_keepalive(). Read more
Source§

fn listen_backlog(&self) -> i32

Gets the listen backlog setting of the socket. For details on this, see g_socket_set_listen_backlog(). Read more
Source§

fn local_address(&self) -> Result<SocketAddress, Error>

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. Read more
Source§

fn is_multicast_loopback(&self) -> bool

Gets the multicast loopback setting on @self; if true (the default), outgoing multicast packets will be looped back to multicast listeners on the same host. Read more
Source§

fn multicast_ttl(&self) -> u32

Gets the multicast time-to-live setting on @self; see g_socket_set_multicast_ttl() for more details. Read more
Source§

fn option(&self, level: i32, optname: i32) -> Result<i32, Error>

Gets the value of an integer-valued option on @self, as with getsockopt(). (If you need to fetch a non-integer-valued option, you will need to call getsockopt() directly.) Read more
Source§

fn protocol(&self) -> SocketProtocol

Gets the socket protocol id the socket was created with. In case the protocol is unknown, -1 is returned. Read more
Source§

fn remote_address(&self) -> Result<SocketAddress, Error>

Try to get the remote address of a connected socket. This is only useful for connection oriented sockets that have been connected. Read more
Source§

fn socket_type(&self) -> SocketType

Gets the socket type of the socket. Read more
Source§

fn timeout(&self) -> u32

Gets the timeout setting of the socket. For details on this, see g_socket_set_timeout(). Read more
Source§

fn ttl(&self) -> u32

Gets the unicast time-to-live setting on @self; see g_socket_set_ttl() for more details. Read more
Source§

fn is_closed(&self) -> bool

Checks whether a socket is closed. Read more
Source§

fn is_connected(&self) -> bool

Check whether the socket is connected. This is only useful for connection-oriented sockets. Read more
Source§

fn join_multicast_group( &self, group: &impl IsA<InetAddress>, source_specific: bool, iface: Option<&str>, ) -> Result<(), Error>

Registers @self to receive multicast messages sent to @group. @self must be a SocketType::Datagram socket, and must have been bound to an appropriate interface and port with g_socket_bind(). Read more
Source§

fn join_multicast_group_ssm( &self, group: &impl IsA<InetAddress>, source_specific: Option<&impl IsA<InetAddress>>, iface: Option<&str>, ) -> Result<(), Error>

Registers @self to receive multicast messages sent to @group. @self must be a SocketType::Datagram socket, and must have been bound to an appropriate interface and port with g_socket_bind(). Read more
Source§

fn leave_multicast_group( &self, group: &impl IsA<InetAddress>, source_specific: bool, iface: Option<&str>, ) -> Result<(), Error>

Removes @self from the multicast group defined by @group, @iface, and @source_specific (which must all have the same values they had when you joined the group). Read more
Source§

fn leave_multicast_group_ssm( &self, group: &impl IsA<InetAddress>, source_specific: Option<&impl IsA<InetAddress>>, iface: Option<&str>, ) -> Result<(), Error>

Removes @self from the multicast group defined by @group, @iface, and @source_specific (which must all have the same values they had when you joined the group). Read more
Source§

fn listen(&self) -> Result<(), Error>

Marks the socket as a server socket, i.e. a socket that is used to accept incoming requests using g_socket_accept(). Read more
Source§

fn set_blocking(&self, blocking: bool)

Sets the blocking mode of the socket. In blocking mode all operations (which don’t take an explicit blocking parameter) block until they succeed or there is an error. In non-blocking mode all functions return results immediately or with a IOErrorEnum::WouldBlock error. Read more
Source§

fn set_broadcast(&self, broadcast: bool)

Sets whether @self should allow sending to broadcast addresses. This is false by default. Read more
Source§

fn set_keepalive(&self, keepalive: bool)

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. Read more
Source§

fn set_listen_backlog(&self, backlog: i32)

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. Read more
Source§

fn set_multicast_loopback(&self, loopback: bool)

Sets whether outgoing multicast packets will be received by sockets listening on that multicast address on the same host. This is true by default. Read more
Source§

fn set_multicast_ttl(&self, ttl: u32)

Sets the time-to-live for outgoing multicast datagrams on @self. By default, this is 1, meaning that multicast packets will not leave the local network. Read more
Source§

fn set_option(&self, level: i32, optname: i32, value: i32) -> Result<(), Error>

Sets the value of an integer-valued option on @self, as with setsockopt(). (If you need to set a non-integer-valued option, you will need to call setsockopt() directly.) Read more
Source§

fn set_timeout(&self, timeout: u32)

Sets the time in seconds after which I/O operations on @self will time out if they have not yet completed. Read more
Source§

fn set_ttl(&self, ttl: u32)

Sets the time-to-live for outgoing unicast packets on @self. By default the platform-specific default value is used. Read more
Source§

fn shutdown( &self, shutdown_read: bool, shutdown_write: bool, ) -> Result<(), Error>

Shut down part or all of a full-duplex connection. Read more
Source§

fn speaks_ipv4(&self) -> bool

Checks if a socket is capable of speaking IPv4. Read more
Source§

fn type_(&self) -> SocketType

The socket’s type.
Source§

fn connect_blocking_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_broadcast_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_keepalive_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_listen_backlog_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_local_address_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_multicast_loopback_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_multicast_ttl_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_remote_address_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_timeout_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId

Source§

fn connect_ttl_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

Source§

impl<O> SocketExtManual for O
where O: IsA<Socket>,

Source§

fn receive<B: AsMut<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, cancellable: Option<&C>, ) -> Result<usize, Error>

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 None. Read more
Source§

fn receive_from<B: AsMut<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, cancellable: Option<&C>, ) -> Result<(usize, SocketAddress), Error>

Receive data (up to @size bytes) from a socket. Read more
Source§

fn receive_message<C: IsA<Cancellable>>( &self, address: Option<&mut Option<SocketAddress>>, vectors: &mut [InputVector<'_>], control_messages: Option<&mut SocketControlMessages>, flags: i32, cancellable: Option<&C>, ) -> Result<(usize, i32), Error>

Receive data from a socket. For receiving multiple messages, see g_socket_receive_messages(); for easier use, see g_socket_receive() and g_socket_receive_from(). Read more
Source§

fn receive_messages<C: IsA<Cancellable>>( &self, messages: &mut [InputMessage<'_>], flags: i32, cancellable: Option<&C>, ) -> Result<usize, Error>

Receive multiple data messages from @self in one go. This is the most complicated and fully-featured version of this call. For easier use, see g_socket_receive(), g_socket_receive_from(), and g_socket_receive_message(). Read more
Source§

fn receive_with_blocking<B: AsMut<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, blocking: bool, cancellable: Option<&C>, ) -> Result<usize, Error>

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 @self’s properties. Read more
Source§

fn send<B: AsRef<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, cancellable: Option<&C>, ) -> Result<usize, Error>

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 None. Read more
Source§

fn send_message<P: IsA<SocketAddress>, C: IsA<Cancellable>>( &self, address: Option<&P>, vectors: &[OutputVector<'_>], messages: &[SocketControlMessage], flags: i32, cancellable: Option<&C>, ) -> Result<usize, Error>

Send data to @address on @self. For sending multiple messages see g_socket_send_messages(); for easier use, see g_socket_send() and g_socket_send_to(). Read more
Source§

fn send_message_with_timeout<P: IsA<SocketAddress>, C: IsA<Cancellable>>( &self, address: Option<&P>, vectors: &[OutputVector<'_>], messages: &[SocketControlMessage], flags: i32, timeout: Option<Duration>, cancellable: Option<&C>, ) -> Result<(PollableReturn, usize), Error>

Available on crate feature v2_60 only.
This behaves exactly the same as g_socket_send_message(), except that the choice of timeout behavior is determined by the @timeout_us argument rather than by @self’s properties. Read more
Source§

fn send_messages<C: IsA<Cancellable>>( &self, messages: &mut [OutputMessage<'_>], flags: i32, cancellable: Option<&C>, ) -> Result<usize, Error>

Send multiple data messages from @self in one go. This is the most complicated and fully-featured version of this call. For easier use, see g_socket_send(), g_socket_send_to(), and g_socket_send_message(). Read more
Source§

fn send_to<B: AsRef<[u8]>, P: IsA<SocketAddress>, C: IsA<Cancellable>>( &self, address: Option<&P>, buffer: B, cancellable: Option<&C>, ) -> Result<usize, Error>

Tries to send @size bytes from @buffer to @address. If @address is None then the message is sent to the default receiver (set by g_socket_connect()). Read more
Source§

fn send_with_blocking<B: AsRef<[u8]>, C: IsA<Cancellable>>( &self, buffer: B, blocking: bool, cancellable: Option<&C>, ) -> Result<usize, Error>

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 @self’s properties. Read more
Source§

fn fd<T: FromRawFd>(&self) -> T

Available on Unix only.
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. Read more
Source§

fn create_source<F, C>( &self, condition: IOCondition, cancellable: Option<&C>, name: Option<&str>, priority: Priority, func: F, ) -> Source
where F: FnMut(&Self, IOCondition) -> ControlFlow + 'static, C: IsA<Cancellable>,

Source§

fn create_source_future<C: IsA<Cancellable>>( &self, condition: IOCondition, cancellable: Option<&C>, priority: Priority, ) -> Pin<Box<dyn Future<Output = IOCondition> + 'static>>

Source§

fn create_source_stream<C: IsA<Cancellable>>( &self, condition: IOCondition, cancellable: Option<&C>, priority: Priority, ) -> Pin<Box<dyn Stream<Item = IOCondition> + 'static>>

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,

Source§

impl<Super, Sub> MayDowncastTo<Sub> for Super
where Super: IsA<Super>, Sub: IsA<Super>,