Struct glommio::net::UnixDatagram[][src]

pub struct UnixDatagram { /* fields omitted */ }
Expand description

A Unix Datagram Socket.

Implementations

Creates an unnamed pair of connected Unix Datagram sockets.

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let (mut p1, mut p2) = UnixDatagram::pair().unwrap();
    let sz = p1.send(&[65u8; 1]).await.unwrap();
    let mut buf = [0u8; 1];
    let sz = p2.recv(&mut buf).await.unwrap();
})

Creates a Unix Datagram socket bound to the specified address.

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let listener = UnixDatagram::bind("/tmp/named_dgram").unwrap();
    println!("Listening on {:?}", listener.local_addr().unwrap());
});

Creates a Unix Datagram socket which is not bound to any address.

Connects an unbounded Unix Datagram socket to a remote address, allowing the send and recv methods to be used to send data and also applies filters to only receive data from the specified address.

If addr yields multiple addresses, connect will be attempted with each of the addresses until the underlying OS function returns no error. Note that usually, a successful connect call does not specify that there is a remote server listening on the port, rather, such an error would only be detected after the first send. If the OS returns an error for each of the specified addresses, the error returned from the last connection attempt (the last address) is returned.

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let receiver = UnixDatagram::bind("/tmp/dgram").unwrap();
    let sender = UnixDatagram::unbound().unwrap();
    sender.connect("/tmp/dgram").await.unwrap();
});

Sets the buffer size used on the receive path

gets the buffer size used

Receives single datagram on the socket from the remote address to which it is connected, without removing the message from input queue. On success, returns the number of bytes peeked.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

To use this function, connect must have been called

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let receiver = UnixDatagram::bind("/tmp/dgram").unwrap();
    let sender = UnixDatagram::unbound().unwrap();
    sender.connect("/tmp/dgram").await.unwrap();
    sender.send(&[1; 1]).await.unwrap();
    let mut buf = vec![0; 32];
    let sz = receiver.peek(&mut buf).await.unwrap();
    assert_eq!(sz, 1);
})

Receives a single datagram message on the socket, without removing it from the queue. On success, returns the number of bytes read and the origin.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

Returns the socket address of the remote peer this socket was connected to.

Returns the socket address of the local half of this Unix Datagram connection.

Receives a single datagram message on the socket from the remote address to which it is connected.

On success, returns the number of bytes read. The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

To use this function, connect must have been called

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let receiver = UnixDatagram::bind("/tmp/dgram").unwrap();
    let sender = UnixDatagram::unbound().unwrap();
    sender.connect("/tmp/dgram").await.unwrap();
    sender.send(&[1; 1]).await.unwrap();
    let mut buf = vec![0; 32];
    let sz = receiver.recv(&mut buf).await.unwrap();
    assert_eq!(sz, 1);
})

Receives a single datagram message on the socket. On success, returns the number of bytes read and the origin.

The function must be called with valid byte array buf of sufficient size to hold the message bytes. If a message is too long to fit in the supplied buffer, excess bytes may be discarded.

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let receiver = UnixDatagram::bind("/tmp/dgram").unwrap();
    let sender = UnixDatagram::unbound().unwrap();
    sender.send_to(&[1; 1], "/tmp/dgram").await.unwrap();
    let mut buf = vec![0; 32];
    let (sz, _addr) = receiver.recv_from(&mut buf).await.unwrap();
    assert_eq!(sz, 1);
})

Sends data on the socket to the given address. On success, returns the number of bytes written.

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let sender = UnixDatagram::unbound().unwrap();
    sender.send_to(&[1; 1], "/tmp/dgram").await.unwrap();
})

Sends data on the socket to the remote address to which it is connected.

UnixDatagram::connect will connect this socket to a remote address. This method will fail if the socket is not connected.

Examples

use glommio::{net::UnixDatagram, LocalExecutor};

let ex = LocalExecutor::default();
ex.run(async move {
    let receiver = UnixDatagram::bind("/tmp/dgram").unwrap();
    let sender = UnixDatagram::unbound().unwrap();
    sender.connect("/tmp/dgram").await.unwrap();
    sender.send(&[1; 1]).await.unwrap();
})

[UnixDatagram::connect]: UnixDatagram::connect

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more