跳转到主要内容

sd_varlink_reply_and_upgrade

systemd

3

#include <systemd/sd-varlink.h>

typedef int (*

, int

input_fd

, int

output_fd

, void *

userdata

);

int

sd_json_variant *

parameters

int *

ret_input_fd

int *

ret_output_fd

int

sd_json_variant *

parameters

int

…

int

…

int

callback

Description

These functions implement the server side of a Varlink protocol upgrade. A Varlink client may request an upgrade when invoking a method (see sd_varlink_call(3) and the SD_VARLINK_METHOD_UPGRADE flag passed to method callbacks). If a method is invoked this way, the server may send one final reply and then abandon the Varlink protocol on the connection entirely, handing the underlying socket or pipe file descriptors back to the caller so that an arbitrary, non-Varlink ("raw") protocol may be spoken over them instead. This is useful for methods that negotiate a switch to a streaming or binary protocol, in a manner similar to the Upgrade: mechanism of HTTP.

The returned file descriptors are switched to blocking mode. For bidirectional sockets a single underlying file descriptor carries both directions; in this case ret_input_fd and ret_output_fd are returned as two independent (duplicated) descriptors referring to the same socket, so they may be closed separately. For transports backed by a pair of pipes the two descriptors differ and refer to the distinct read and write ends. Either ret_input_fd or ret_output_fd (but not both) may be NULL; in that case the unwanted direction is shut down (if they refer to the same socket, see shutdown(2)) or closed (if separate file descriptors) rather than returned.

Return Value

On success, sd_varlink_reply_and_upgrade(), sd_varlink_respond_and_upgrade(), sd_varlink_respond_and_upgradeb() and sd_varlink_respond_and_upgradebo() return a positive integer. sd_varlink_bind_upgrade() returns a non-negative integer on success. On failure, they all return a negative errno-style error code.

Errors

Returned errors may indicate the following problems:

-EINVAL
An argument is invalid.

-ENOTCONN
The Varlink connection object is not connected.

-EBUSY
The connection is not currently processing a method call, so there is no reply to send. When returned by sd_varlink_bind_upgrade(), a different upgrade callback was already registered on the connection.

-EPROTO
The currently processed method call did not request a protocol upgrade, hence the connection may not be taken over.

-EBADMSG
The client sent unexpected data before the upgrade completed, i.e. it pipelined raw protocol data before receiving the upgrade reply.

-ENOMEM
Memory allocation failed.

History

See Also

systemd(1), sd-varlink(3), sd_varlink_reply(3), sd_varlink_call(3), sd_varlink_call_and_upgrade(3), sd_varlink_process(3), sd_varlink_set_userdata(3), sd_json_build(3)