TAPI for socket API remote calls
Overview
// typedefs typedef enum rpc_msg_flags_mode rpc_msg_flags_mode; typedef enum rpc_msghdr_field_mode rpc_msghdr_field_mode; typedef struct rpc_msghdr rpc_msghdr; typedef struct rpc_tcp_info rpc_tcp_info; typedef union rpc_sockopt_value rpc_sockopt_value; // enums enum rpc_msg_flags_mode; enum rpc_msghdr_field_mode; // structs struct rpc_mmsghdr; struct rpc_msghdr; struct rpc_tcp_info; // unions union rpc_sockopt_value; // global functions static int socket_domain_by_af(int af); static rpc_socket_domain rpc_socket_domain_by_af(int af); static rpc_socket_domain rpc_socket_domain_by_addr(const struct sockaddr* addr); int rpc_socket(rcf_rpc_server* rpcs, rpc_socket_domain domain, rpc_socket_type type, rpc_socket_proto protocol); int rpc_shutdown(rcf_rpc_server* rpcs, int s, rpc_shut_how how); ssize_t rpc_send(rcf_rpc_server* rpcs, int s, const void* buf, size_t len, rpc_send_recv_flags flags); ssize_t rpc_sendto(rcf_rpc_server* rpcs, int s, const void* buf, size_t len, rpc_send_recv_flags flags, const struct sockaddr* to); ssize_t rpc_sendto_raw(rcf_rpc_server* rpcs, int s, const void* buf, size_t len, rpc_send_recv_flags flags, const struct sockaddr* to, socklen_t tolen); ssize_t rpc_recv_gen(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags, size_t rbuflen); static ssize_t rpc_recv(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags); ssize_t rpc_recvfrom_gen(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags, struct sockaddr* from, socklen_t* fromlen, size_t rbuflen, socklen_t rfrombuflen); static ssize_t rpc_recvfrom(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags, struct sockaddr* from, socklen_t* fromlen); const char* msghdr_rpc2str(const rpc_msghdr* rpc_msg, te_string* str); const char* mmsghdrs_rpc2str(const struct rpc_mmsghdr* rpc_mmsgs, unsigned int num, te_string* str); struct cmsghdr* rpc_cmsg_firsthdr(rpc_msghdr* rpc_msg); struct cmsghdr* rpc_cmsg_nxthdr(rpc_msghdr* rpc_msg, struct cmsghdr* cmsg); static int tapi_send_recv_flags_rand(void); void tapi_rpc_msghdr_msg_flags_init_check(bool enable); ssize_t rpc_sendmsg(rcf_rpc_server* rpcs, int s, const struct rpc_msghdr* msg, rpc_send_recv_flags flags); ssize_t rpc_recvmsg(rcf_rpc_server* rpcs, int s, struct rpc_msghdr* msg, rpc_send_recv_flags flags); ssize_t rpc_sendbuf_gen(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t buf_off, size_t len, rpc_send_recv_flags flags); static ssize_t rpc_sendbuf(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t len, rpc_send_recv_flags flags); static ssize_t rpc_sendbuf_off(rcf_rpc_server* rpcs, int s, rpc_ptr_off* buf, size_t len, rpc_send_recv_flags flags); ssize_t rpc_send_msg_more(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t first_len, size_t second_len); ssize_t rpc_send_msg_more_ext(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t first_len, size_t second_len, tarpc_send_function first_func, tarpc_send_function second_func, bool set_nodelay); ssize_t rpc_send_one_byte_many(rcf_rpc_server* rpcs, int s, int duration); tarpc_ssize_t rpc_recvbuf_gen(rcf_rpc_server* rpcs, int fd, rpc_ptr buf, size_t buf_off, size_t count, rpc_send_recv_flags flags); static tarpc_ssize_t rpc_recvbuf(rcf_rpc_server* rpcs, int fd, rpc_ptr buf, size_t count, rpc_send_recv_flags flags); static tarpc_ssize_t rpc_recvbuf_off(rcf_rpc_server* rpcs, int fd, rpc_ptr_off* buf, size_t count, rpc_send_recv_flags flags); int rpc_cmsg_data_parse_ip_pktinfo(rcf_rpc_server* rpcs, uint8_t* data, uint32_t data_len, struct in_addr* ipi_spec_dst, struct in_addr* ipi_addr, int* ipi_ifindex); int rpc_bind(rcf_rpc_server* rpcs, int s, const struct sockaddr* my_addr); int rpc_bind_len(rcf_rpc_server* rpcs, int s, const struct sockaddr* my_addr, socklen_t addrlen); int rpc_bind_raw(rcf_rpc_server* rpcs, int s, const struct sockaddr* my_addr, socklen_t addrlen); int rpc_check_port_is_free(rcf_rpc_server* rpcs, uint16_t port); int rpc_connect(rcf_rpc_server* rpcs, int s, const struct sockaddr* addr); int rpc_connect_raw(rcf_rpc_server* rpcs, int s, const struct sockaddr* addr, socklen_t addrlen); int rpc_listen(rcf_rpc_server* rpcs, int s, int backlog); int rpc_accept_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen, socklen_t raddrlen); int rpc_accept4_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen, socklen_t raddrlen, int flags); static int rpc_accept(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen); static int rpc_accept4(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen, int flags); int rpc_getsockopt_gen(rcf_rpc_server* rpcs, int s, rpc_socklevel level, rpc_sockopt optname, void* optval, void* raw_optval, socklen_t* raw_optlen, socklen_t raw_roptlen); static int rpc_getsockopt_raw(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, void* raw_optval, socklen_t* raw_optlen); static int rpc_getsockopt(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, void* optval); int rpc_setsockopt_gen(rcf_rpc_server* rpcs, int s, rpc_socklevel level, rpc_sockopt optname, const void* optval, const void* raw_optval, socklen_t raw_optlen, socklen_t raw_roptlen); static int rpc_setsockopt_raw(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, const void* raw_optval, socklen_t raw_optlen); static int rpc_setsockopt(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, const void* optval); static int rpc_setsockopt_int(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, int optval); int rpc_setsockopt_check_int(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, int optval); int rpc_getsockname_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen, socklen_t rnamelen); static int rpc_getsockname(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen); int rpc_getpeername_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen, socklen_t rnamelen); static int rpc_getpeername(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen); int rpc_recvmmsg_alt(rcf_rpc_server* rpcs, int fd, struct rpc_mmsghdr* mmsg, unsigned int vlen, rpc_send_recv_flags flags, struct tarpc_timespec* timeout); int rpc_sendmmsg_alt(rcf_rpc_server* rpcs, int fd, struct rpc_mmsghdr* mmsg, unsigned int vlen, rpc_send_recv_flags flags); int rpc_socket_connect_close(rcf_rpc_server* rpcs, rpc_socket_domain domain, const struct sockaddr* addr, uint32_t time2run); int rpc_socket_listen_close(rcf_rpc_server* rpcs, rpc_socket_domain domain, const struct sockaddr* addr, uint32_t time2run); void tapi_rpc_provoke_arp_resolution(rcf_rpc_server* rpcs, const struct sockaddr* addr); // macros #define RPC_CMSG_FIRSTHDR(_rpc_msg) #define RPC_CMSG_NXTHDR(_rpc_msg, _cmsg)
Detailed Documentation
Typedefs
typedef enum rpc_msg_flags_mode rpc_msg_flags_mode
Flags set which determines behavior of msg_flags processing. In general default value is 0
in this case a random value is passed in msg_flags field and then returned value will be checked:
for recvmsg()-like functions returned value has to be zero unless the cases when some flags are really expected;
for sendmsg()-like functions the field must be unchanged.
typedef enum rpc_msghdr_field_mode rpc_msghdr_field_mode
Processing mode for rpc_msghdr fields
typedef struct rpc_msghdr rpc_msghdr
Store information about message
typedef union rpc_sockopt_value rpc_sockopt_value
Storage sufficient for any fixed-size socket option value
Global Functions
static int socket_domain_by_af(int af)
Get socket domain native for the address family.
Parameters:
af |
An address family |
Returns:
Domain
static rpc_socket_domain rpc_socket_domain_by_af(int af)
Get RPC socket domain native for the address family.
Parameters:
af |
An address family |
Returns:
RPC domain
static rpc_socket_domain rpc_socket_domain_by_addr(const struct sockaddr* addr)
Get RPC socket domain native for the address.
Parameters:
addr |
An address |
Returns:
RPC domain
int rpc_socket(rcf_rpc_server* rpcs, rpc_socket_domain domain, rpc_socket_type type, rpc_socket_proto protocol)
Create an endpoint for communication on the RPC server side.
Parameters:
rpcs |
RPC server handle |
domain |
communication domain. Select the protocol family used for communication supported protocol families are difined in |
type |
defines the semantic of communication. Current defined types can be found in |
protocol |
specifies the protocol to be used. If protocol is set to RPC_PROTO_DEF, the system selects the default protocol number for the socket domain and type specified. |
Returns:
The socket descriptor to be used. Otherwise -1 is returned when error occurred
int rpc_shutdown(rcf_rpc_server* rpcs, int s, rpc_shut_how how)
End communication on socket descriptor s in one or both directions on RPC server side.
For more information about shutdown() see its corresponding manual page
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
how |
specifies the shutdown condition and can be specified in the following ways:
|
Returns:
0 on success -1 on error and error code is set appropriately to RPC_XXX where XXX - standard errno for shutdown()
ssize_t rpc_send(rcf_rpc_server* rpcs, int s, const void* buf, size_t len, rpc_send_recv_flags flags)
Transmit a message to socket descriptor s on RPC server side.
See send() manual page for more information
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
buf |
pointer to buffer containing the message to be sent |
len |
length of the message in bytes |
flags |
bitwise OR of zero or more of the following flags:
|
Returns:
number of bytes actually sent, otherwise -1.
ssize_t rpc_sendto(rcf_rpc_server* rpcs, int s, const void* buf, size_t len, rpc_send_recv_flags flags, const struct sockaddr* to)
Transmit a message to descriptor s. This operation takes place on RPC server side.
See sendto() manual page for more information about flags and error code set when this routine failed.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
buf |
pointer to buffer containing message to be sent |
len |
message length in bytes |
flags |
bitwise OR of zero or more of the following flags:
|
to |
target address |
Returns:
Number of bytes sent, otherwise -1.
ssize_t rpc_recv_gen(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags, size_t rbuflen)
Generic routine for receiving messages and store them in the buffer buf of length len. This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
buf |
pointer to buffer which store received messages |
len |
buffer length passed to recv() |
flags |
bitwise OR of zero or more of the following flags:
|
rbuflen |
size of the buffer buf |
Returns:
Number of bytes received, otherwise -1
static ssize_t rpc_recv(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags)
Receive messages and store them in the buffer buf of length len. This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
buf |
pointer to buffer which store received messages |
len |
size of the buffer buf |
flags |
bitwise OR of zero or more of the following flags:
|
Returns:
Number of bytes received, otherwise -1 when error occurred
ssize_t rpc_recvfrom_gen(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags, struct sockaddr* from, socklen_t* fromlen, size_t rbuflen, socklen_t rfrombuflen)
Generic routine for receiving data from a connected or non-connected socket. This operation takes place on RPC server side. Behavior of this routine depends on specified RPC operation: RCF_RPC_CALL
- return immediately without waiting for remote procedure to complete (non-blocking call). RCF_RPC_WAIT
- wait for non-blocking call to complete RCF_RPC_CALL_WAIT
- wait for remote procedure to complete before returning (blocking call)
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor |
buf |
pointer to buffer which store received data |
len |
size of the buffer buf |
flags |
bitwise OR of zero or more of the following flags:
|
from |
pointer to source address of the message or NULL (OUT) |
fromlen |
size of source address from |
rbuflen |
number of bytes to be received. |
rfrombuflen |
size of source address from (if not NULL) |
Returns:
Number of bytes received, otherwise -1
static ssize_t rpc_recvfrom(rcf_rpc_server* rpcs, int s, void* buf, size_t len, rpc_send_recv_flags flags, struct sockaddr* from, socklen_t* fromlen)
Receive data from a connected or non-connected socket. This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor |
buf |
pointer to buffer which store received data |
len |
size of the buffer buf |
flags |
bitwise OR of zero or more of the following flags:
|
from |
pointer to source address of the message or NULL (OUT) |
fromlen |
size of source address from. |
Returns:
Number of bytes received, otherwise -1
const char* msghdr_rpc2str(const rpc_msghdr* rpc_msg, te_string* str)
Append rpc_msghdr string representation to string.
Parameters:
rpc_msg |
Pointer to rpc_msghdr structure. |
str |
Pointer to te_string. |
Returns:
Pointer to updated character string.
const char* mmsghdrs_rpc2str(const struct rpc_mmsghdr* rpc_mmsgs, unsigned int num, te_string* str)
Append string representation of array of rpc_mmsghdr structures to string.
Parameters:
rpc_mmsgs |
Pointer to array of rpc_mmsghdr structures. |
num |
Number of elements in the array. |
str |
Pointer to te_string. |
Returns:
Pointer to updated character string.
struct cmsghdr* rpc_cmsg_firsthdr(rpc_msghdr* rpc_msg)
Get the first cmsghdr from control data stored in rpc_msghdr.
Parameters:
rpc_msg |
Pointer to rpc_msghdr structure. |
Returns:
Pointer to the first cmsghdr.
struct cmsghdr* rpc_cmsg_nxthdr(rpc_msghdr* rpc_msg, struct cmsghdr* cmsg)
Get the next cmsghdr from control data stored in rpc_msghdr.
Parameters:
rpc_msg |
Pointer to rpc_msghdr structure. |
cmsg |
Pointer to the current cmsghdr structure. |
Returns:
Pointer to the next cmsghdr.
static int tapi_send_recv_flags_rand(void)
Generate a random value in range [0, RPC_MSG_UNKNOWN) for msg_flags initialization.
void tapi_rpc_msghdr_msg_flags_init_check(bool enable)
Enable/disable rpc_msghdr.msg_flags flags value initialization and check inside RPCs. The function can be used in the test body to control behavior. It does not require any rollback actions.
By default the flags value is initialized and checked in all RPCs where rpc_msg is used.
Parameters:
enable |
Set |
ssize_t rpc_sendmsg(rcf_rpc_server* rpcs, int s, const struct rpc_msghdr* msg, rpc_send_recv_flags flags)
Send message to a connected or non-connected socket. This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
msg |
pointer to a rpc_msghdr structure that hold the message to be sent |
flags |
bitwise OR of zero or more of the following flags:
|
Returns:
Length of message, otherwise -1 is returned when an error occurred
ssize_t rpc_recvmsg(rcf_rpc_server* rpcs, int s, struct rpc_msghdr* msg, rpc_send_recv_flags flags)
Receive data from connected or non-connected socket This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
msg |
pointer to a rpc_msghdr structure that hold the received message |
flags |
bitwise OR of zero or more of the flags; see rpc_recv for more information |
Returns:
Length of received data, otherwise -1 when an error occurred.
ssize_t rpc_sendbuf_gen(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t buf_off, size_t len, rpc_send_recv_flags flags)
Transmit a message to socket descriptor s on RPC server side. This operation takes place on RPC server side and buffer is stored on the same side.
See send() manual page for more information
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
buf |
RPC pointer to buffer containing the message to be sent |
buf_off |
offset in the buffer above |
len |
length of the message in bytes |
flags |
bitwise OR of zero or more of the flags; see rpc_send for more information |
Returns:
number of bytes actually sent, otherwise -1.
ssize_t rpc_send_msg_more(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t first_len, size_t second_len)
Call send() two times to send two data portions, first time - with MSG_MORE
flag, the second time - without it.
See send() manual page for more information
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor |
buf |
RPC pointer to buffer containing data to be sent |
first_len |
Length of the first portion of data (to be sent with |
second_len |
Length of the second portion of data (to be sent without |
Returns:
On success, number of bytes actually sent, otherwise -1
.
ssize_t rpc_send_msg_more_ext(rcf_rpc_server* rpcs, int s, rpc_ptr buf, size_t first_len, size_t second_len, tarpc_send_function first_func, tarpc_send_function second_func, bool set_nodelay)
Call a sending function two times to send two data portions, the first time - with MSG_MORE
flag, the second time - without it.
Parameters:
rpcs |
RPC server handle. |
s |
Socket descriptor. |
buf |
RPC pointer to buffer containing data to be sent. |
first_len |
Length of the first portion of data (to be sent with |
second_len |
Length of the second portion of data (to be sent without |
first_func |
Sending function for the first data portion. |
second_func |
Sending function for the second data portion. |
set_nodelay |
If |
Returns:
On success, number of bytes actually sent, otherwise -1
.
ssize_t rpc_send_one_byte_many(rcf_rpc_server* rpcs, int s, int duration)
Transmit many 1-byte messages to socket descriptor s on RPC server side by using send(MSG_DONTWAIT
) calls.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
duration |
Duration of the loop (in seconds) |
Returns:
On succes, number of bytes actually sent, otherwise -1.
tarpc_ssize_t rpc_recvbuf_gen(rcf_rpc_server* rpcs, int fd, rpc_ptr buf, size_t buf_off, size_t count, rpc_send_recv_flags flags)
Receive messages and store them in the buffer buf of length len. This operation takes place on RPC server side and buffer is stored on the same side.
Parameters:
rpcs |
RPC server handle |
fd |
socket descriptor |
buf |
RPC pointer to buffer which store received messages |
buf_off |
size of the buffer buf |
flags |
bitwise OR of zero or more of the following flags:
|
Returns:
Number of bytes received, otherwise -1 when error occurred
int rpc_cmsg_data_parse_ip_pktinfo(rcf_rpc_server* rpcs, uint8_t* data, uint32_t data_len, struct in_addr* ipi_spec_dst, struct in_addr* ipi_addr, int* ipi_ifindex)
Parse TA-dependent in_pktinfo structure type data returned in msg_control data field of rpc_msghdr during rpc_recvmsg() call in case when IP_PKTINFO option is enabled on socket.
Parameters:
rpcs |
RPC server handle |
data |
msg_control data |
data_len |
msg_control data length |
ipi_spec_dst |
ipi_spec_dst value of in_pktinfo type data (OUT) |
ipi_addr |
ipi_addr value of in_pktinfo type data (OUT) |
ipi_ifindex |
ipi_ifindex value of in_pktinfo type data (OUT) |
Returns:
Status code
int rpc_bind(rcf_rpc_server* rpcs, int s, const struct sockaddr* my_addr)
Assign a name to an unnamed socket. When o socket is created, it exists in an address family, but it does not have a name assigned to it. Servers use bind() to associate themselves with a well-known port. This operation takes place on RPC server side.
See bind manual page for more infrormation.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
my_addr |
pointer to a sockaddr structure |
Returns:
0 on success or -1 on failure
int rpc_bind_len(rcf_rpc_server* rpcs, int s, const struct sockaddr* my_addr, socklen_t addrlen)
The same as rpc_bind(), but there is addrlen parameter. It is used to specify length to be passed to bind().
int rpc_check_port_is_free(rcf_rpc_server* rpcs, uint16_t port)
Check that given port
is free on the given pco
.
int rpc_connect(rcf_rpc_server* rpcs, int s, const struct sockaddr* addr)
Attempt to associate a socket descriptor s with a peer process at address addr. This operation takes place on RPC server side.
See connect manual page for more information
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
addr |
peer address to which the socket has to be connected |
Returns:
0 on success or -1 on failure
int rpc_listen(rcf_rpc_server* rpcs, int s, int backlog)
Try to listen for incoming connections for connection oriented sockets This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
s |
listening socket descriptor |
backlog |
maximum number of connections waiting to be accepted |
Returns:
0 on success or -1 on failure
int rpc_accept_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen, socklen_t raddrlen)
This generic routine extract the first connection request of the queue of pending connections, allocate a new descriptor for the connected socket. This operation takes place on RPC server side. The behavior of this routine depends on specified RPC operation: RCF_RPC_CALL
- return immediately without waiting for remote procedure to complete (non-blocking call). RCF_RPC_WAIT
- wait for non-blocking call to complete RCF_RPC_CALL_WAIT
- wait for remote procedure to complete before returning (blocking call)
Parameters:
rpcs |
RPC server handle |
s |
listening socket descriptor |
addr |
pointer to a sockaddr structure |
addrlen |
pointer to size of structure pointed by addr. On return contain the actual size of the returned in addr address |
raddrlen |
real size of addr |
Returns:
Socket for new connection or -1
int rpc_accept4_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen, socklen_t raddrlen, int flags)
This function does the same thing as rpc_gen_accept() but also take flags parameter (where SOCK_CLOEXEC and/or SOCK_NONBLOCK flags can be set). This operation takes place on RPC server side.
The behavior of this routine depends on specified RPC operation: RCF_RPC_CALL
- return immediately without waiting for remote procedure to complete (non-blocking call). RCF_RPC_WAIT
- wait for non-blocking call to complete RCF_RPC_CALL_WAIT
- wait for remote procedure to complete before returning (blocking call)
Parameters:
rpcs |
RPC server handle |
s |
listening socket descriptor |
addr |
pointer to a sockaddr structure |
addrlen |
pointer to size of structure pointed by addr. On return contain the actual size of the returned in addr address |
raddrlen |
real size of addr |
flags |
RPC_SOCK_NONBCLOCK, RPC_SOCK_CLOEXEC flags can be set |
Returns:
Socket for new connection or -1
static int rpc_accept(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen)
Extract the first connection request of the queue of pending connections, allocate a new descriptor for the connected socket This operation takes place on RPC server side. The behavior of this routine depends on specified RPC operation: RCF_RPC_CALL
- return immediately without waiting for remote procedure to complete (non-blocking call). RCF_RPC_WAIT
- wait for non-blocking call to complete RCF_RPC_CALL_WAIT
- wait for remote procedure to complete before returning (blocking call)
Parameters:
rpcs |
RPC server handle |
s |
listening socket descriptor |
addr |
pointer to a sockaddr structure |
addrlen |
contain size of structure pointed by addr. On return contain the actual size of the returned in addr address |
Returns:
Socket for new connection or -1
static int rpc_accept4(rcf_rpc_server* rpcs, int s, struct sockaddr* addr, socklen_t* addrlen, int flags)
This function does the same thing as rpc_gen_accept() but also take flags parameter (where SOCK_CLOEXEC and/or SOCK_NONBLOCK flags can be set).
This operation takes place on RPC server side. The behavior of this routine depends on specified RPC operation: RCF_RPC_CALL
- return immediately without waiting for remote procedure to complete (non-blocking call). RCF_RPC_WAIT
- wait for non-blocking call to complete RCF_RPC_CALL_WAIT
- wait for remote procedure to complete before returning (blocking call)
Parameters:
rpcs |
RPC server handle |
s |
listening socket descriptor |
addr |
pointer to a sockaddr structure |
addrlen |
contain size of structure pointed by addr. On return contain the actual size of the returned in addr address |
flags |
RPC_SOCK_NONBLOCK and/or RPC_SOCK_CLOEXEC |
Returns:
Socket for new connection or -1
int rpc_getsockopt_gen(rcf_rpc_server* rpcs, int s, rpc_socklevel level, rpc_sockopt optname, void* optval, void* raw_optval, socklen_t* raw_optlen, socklen_t raw_roptlen)
This generic routine gets options associated with a socket. This operation takes place on RPC server side.
For more information about supported option level, see te_rpc_sys_socket.h
.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
level |
protocol level at which the option resides. Following values can be specified:
|
optname |
option name |
optval |
pointer to a buffer containing the value associated with the selected option. |
raw_optlen |
initially points to the length of supplied buffer. On return contain the actual size of the buffer. |
raw_roptlen |
maximal length of the buffer or zero |
Returns:
0 on success or -1 on failure
static int rpc_getsockopt(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, void* optval)
Query options associated with a socket. This operation takes place on RPC server side.
The function should be used for fixed-size options when valid option level is required. RPC socket option name is unambiguously mapped to socket option level (see rpc_sockopt2level()).
For more information about supported option level, see te_rpc_sys_socket.h
.
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor |
optname |
Option name |
optval |
Location for option value value (size of location depends on option name and assumed to be sufficient) |
Returns:
0 on success or -1 on failure
See also:
int rpc_setsockopt_gen(rcf_rpc_server* rpcs, int s, rpc_socklevel level, rpc_sockopt optname, const void* optval, const void* raw_optval, socklen_t raw_optlen, socklen_t raw_roptlen)
Set option on socket opened on RPC server.
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor |
level |
Protocol level at which the option resides |
optname |
Option name |
optval |
Pointer to option value to be set or NULL (length is defined by option name) |
raw_optval |
Pointer to option value as sequence of bytes (if optval is not NULL, raw_optval goes after binary representation of optval) |
raw_optlen |
Size of the raw_optval specified in call |
raw_roptlen |
Real size of the raw_optval |
Returns:
0 on success or -1 on failure
See also:
rpc_setsockopt(), rpc_setsockopt_raw()
static int rpc_setsockopt_raw(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, const void* raw_optval, socklen_t raw_optlen)
Set option on socket opened on RPC server using raw option value representation.
See rpc_setsockopt_gen() for parameters description. level is derived from optname using rpc_sockopt2level() function.
Returns:
0 on success or -1 on failure
See also:
static int rpc_setsockopt(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, const void* optval)
Set option on socket opened on RPC server using convered value only.
See rpc_setsockopt_gen() for parameters description. level is derived from optname using rpc_sockopt2level() function. raw_optval and raw_optlen are passed as NULL
and 0
correspondingly.
Returns:
0 on success or -1 on failure
See also:
static int rpc_setsockopt_int(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, int optval)
Wrapper function to set int socket option.
See rpc_setsockopt_gen() for parameters description. level is derived from optname using rpc_sockopt2level() function. raw_optval and raw_optlen are passed as NULL
and 0
correspondingly.
Returns:
Status code
See also:
int rpc_setsockopt_check_int(rcf_rpc_server* rpcs, int s, rpc_sockopt optname, int optval)
Wrapper function to set int socket option with reading and checking new value.
See rpc_setsockopt_gen() for parameters description. level is derived from optname using rpc_sockopt2level() function. raw_optval and raw_optlen are passed as NULL
and 0
correspondingly.
Returns:
Status code
See also:
int rpc_getsockname_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen, socklen_t rnamelen)
Query the current name of the specified socket on RPC server side, store this address in the sockaddr structure ponited by name, and store the length of this address to the object pointed by namelen.
See getsockname manual page for more information
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor whose name is requested |
name |
pointer to a sockaddr structure that should contain the requested name |
namelen |
pointer to the size of the sockaddr structure |
rnamelen |
real size of the sockaddr structure |
Returns:
0 on success, otherwise -1 is returned on failure
static int rpc_getsockname(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen)
Query the name associated with a specified socket.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
name |
pointer to a struct sockaddr which on return contain the name of the socket. |
namelen |
initially indicate the size of the parameter name. On return it contains the actual size of the socket name |
Returns:
0 on success or -1 when failed.
int rpc_getpeername_gen(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen, socklen_t rnamelen)
Query the peer name of a specified socket on RPC server side, store this address in the sockaddr structure ponited by name, and store the length of this address to the object pointed by namelen.
See getpeername manual page for more information
Parameters:
rpcs |
RPC server handle |
s |
Socket descriptor whose peer name is requested |
name |
pointer to a sockaddr structure that should contain the requested peer name |
namelen |
pointer to the size of the sockaddr structure |
rnamelen |
real size of the sockaddr structure |
Returns:
0 on success, otherwise -1 is returned on failure
static int rpc_getpeername(rcf_rpc_server* rpcs, int s, struct sockaddr* name, socklen_t* namelen)
Query the peer name of a specified socket.
Parameters:
rpcs |
RPC server handle |
s |
socket descriptor |
name |
pointer to a buffer which on return contains the name of the peer socket. |
namelen |
Initially indicate the size of the parameter name. On return it contains the actual size of the socket name |
Returns:
0 on success otherwise returns -1 on failure
int rpc_recvmmsg_alt(rcf_rpc_server* rpcs, int fd, struct rpc_mmsghdr* mmsg, unsigned int vlen, rpc_send_recv_flags flags, struct tarpc_timespec* timeout)
Receive data from connected or non-connected socket This operation takes place on RPC server side.
Parameters:
rpcs |
RPC server handle |
fd |
file descriptor |
mmsg |
array of rpc_mmsghdr structures that holds the received messages |
vlen |
length of mmsg array |
flags |
bitwise OR of zero or more of the flags; see rpc_recv for more information |
timeout |
Timeout for receiving |
Returns:
Number of received packets, otherwise -1 when an error occurred.
int rpc_sendmmsg_alt(rcf_rpc_server* rpcs, int fd, struct rpc_mmsghdr* mmsg, unsigned int vlen, rpc_send_recv_flags flags)
Send data from connected or non-connected socket with help of sendmmsg() function. This operation takes place on RPC server side.
msg_len field of each message will be set to number of actually sent bytes
Parameters:
rpcs |
RPC server handle |
fd |
file descriptor |
mmsg |
array of rpc_mmsghdr structures that holds the messages to be sent |
vlen |
length of mmsg array |
flags |
bitwise OR of zero or more of the flags; see rpc_send for more information |
Returns:
Number of sent packets, otherwise -1 when an error occurred.
void tapi_rpc_provoke_arp_resolution(rcf_rpc_server* rpcs, const struct sockaddr* addr)
Send ICMPv4 or ICMPv6 ECHO request packet to addr
to provoke ARP resolution (for IPv4) or neigbour discovery (for IPv6) from both sides. ICMP version depends on the addr
family.
The function jumps to cleanup in case of failure.
Parameters:
rpcs |
RPC server handle. |
addr |
Destination address. |
Macros
#define RPC_CMSG_FIRSTHDR(_rpc_msg)
Get the first cmsghdr from control data stored in rpc_msghdr.
Parameters:
_rpc_msg |
Pointer to rpc_msghdr structure. |
#define RPC_CMSG_NXTHDR(_rpc_msg, _cmsg)
Get the next cmsghdr from control data stored in rpc_msghdr.
Parameters:
_rpc_msg |
Pointer to rpc_msghdr structure. |
_cmsg |
Pointer to the current cmsghdr structure. |