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 T)

🔬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, type_: Option<Type>) -> bool

Check if the object has a property property_name of the given type_. Read more
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>,