pub struct LinkServer { /* private fields */ }
Expand description

WSTP link server.

This is a wrapper around the WSLinkServer C type.

Usage

TODO: Document the two different methods for accepting new Link connections from this type (waiting and an async callback).

Implementations

Create a new LinkServer bound to the specified address.

Use Link::connect_to_link_server to connect to a LinkServer.

Examples
use wstp::LinkServer;

let server = LinkServer::bind("127.0.0.1:8080").unwrap();

Create a new link server.

It is not possible to register a callback function to accept new link connections after the link server has been created. Use LinkServer::new_with_callback() if that functionality is desired.

Use LinkServer::accept() to accept new connections to the link server.

The callback is required to be Send so that it can be called from the link server’s background thread, which accepts incoming connections.

'static bound

The 'static bound is required to prevent the callback closure from capturing a reference to non-static data that it might outlive, for example a local variable:

use std::sync::Mutex;
use wstp::LinkServer;

let mut counter = Mutex::new(0);

let server = LinkServer::new_with_callback(
    11235,
    // Error: the closure may outlive borrowed value `counter`
    |_| *counter.lock().unwrap() += 1
);

println!("counter: {}", counter.lock().unwrap());

Note that the reasoning for the Send and 'static constraints is similiar to that for std::thread::spawn(), whose documentation may be a useful additional reference.

Returns the TCPIP port number used by this link server.

WSTP C API Documentation: WSPortFromLinkServer

Fallible variant of LinkServer::port().

Returns the IP address of the interface used by this link server.

WSTP C API Documentation: WSInterfaceFromLinkServer

Fallible variant of LinkServer::interface().

Close this link server.

This link server will stop accepting new connections, and unbind from the network port it is attached to.

WSTP C API Documentation: WSShutdownLinkServer

Accept a new incoming connection to this link server.

This method blocks the current thread indefinitely until a connection is made to the port this link server is bound to.

Use LinkServer::new_with_callback() to create a link server which accepts connections asyncronously via a callback function.

WSTP C API Documentation: WSWaitForNewLinkFromLinkServer

Returns an iterator over the connections being received on this server.

The returned iterator will never return None. Iterating over it is equivalent to calling LinkServer::accept in a loop.

Returns the raw WSLinkServer C type wrapped by this LinkServer.

Trait Implementations

Formats the value using the given formatter. Read more
Executes the destructor for this type. 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

Returns the argument unchanged.

Calls U::from(self).

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

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.