This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathclient.c
134 lines (110 loc) · 3.01 KB
/
client.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright (c) 2020 Fujitsu */
/*
* client.c -- a client of the send-with-imm example
*
* Please see README.md for a detailed description of this example.
*/
#include <librpma.h>
#include <limits.h>
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include "common-conn.h"
#define USAGE_STR "usage: %s <server_address> <port> <word> <imm>\n"
int
main(int argc, char *argv[])
{
/* validate parameters */
if (argc < 5) {
fprintf(stderr, USAGE_STR, argv[0]);
return -1;
}
/* configure logging thresholds to see more details */
rpma_log_set_threshold(RPMA_LOG_THRESHOLD, RPMA_LOG_LEVEL_INFO);
rpma_log_set_threshold(RPMA_LOG_THRESHOLD_AUX, RPMA_LOG_LEVEL_INFO);
/* read common parameters */
char *addr = argv[1];
char *port = argv[2];
char *word = argv[3];
uint64_t imm = strtoul(argv[4], NULL, 10);
if (imm == ULONG_MAX && errno == ERANGE) {
fprintf(stderr, "strtoul() overflowed\n");
return -1;
}
if (imm > UINT32_MAX) {
fprintf(stderr,
"the provided immediate data is too big(%lu > %u)\n",
imm, UINT32_MAX);
return -1;
}
/* RPMA resources - general */
struct rpma_peer *peer = NULL;
struct rpma_mr_local *send_mr = NULL;
struct rpma_conn *conn = NULL;
struct rpma_completion cmpl;
int ret;
/* prepare memory */
char *send = malloc_aligned(KILOBYTE);
if (!send)
return -1;
/*
* lookup an ibv_context via the address and create a new peer using it
*/
ret = client_peer_via_address(addr, &peer);
if (ret)
goto err_mr_free;
/* register the memory */
ret = rpma_mr_reg(peer, send, KILOBYTE, RPMA_MR_USAGE_SEND, &send_mr);
if (ret)
goto err_peer_delete;
/*
* establish a new connection to a server and send an immediate
* data for valication on the sever side
*/
struct rpma_conn_private_data pdata;
pdata.ptr = (uint32_t *)&imm;
pdata.len = sizeof(uint32_t);
ret = client_connect(peer, addr, port, &pdata, &conn);
if (ret)
goto err_mr_dereg;
/* send a message with immediate data to the server */
fprintf(stdout, "send value %s with immediate data %u\n",
word, (uint32_t)imm);
strcpy(send, word);
ret = rpma_send_with_imm(conn, send_mr, 0, KILOBYTE,
RPMA_F_COMPLETION_ALWAYS, (uint32_t)imm, NULL);
if (ret)
goto err_conn_disconnect;
/* prepare completions, get one and validate it */
ret = rpma_conn_completion_wait(conn);
if (ret)
goto err_conn_disconnect;
ret = rpma_conn_completion_get(conn, &cmpl);
if (ret)
goto err_conn_disconnect;
if (cmpl.op_status != IBV_WC_SUCCESS) {
fprintf(stderr,
"an unexpected completion: %s\n",
ibv_wc_status_str(cmpl.op_status));
ret = -1;
}
if (cmpl.op != RPMA_OP_SEND) {
fprintf(stderr,
"an unexpected type of operation (%d != %d)\n",
cmpl.op, RPMA_OP_SEND);
ret = -1;
}
err_conn_disconnect:
common_disconnect_and_wait_for_conn_close(&conn);
err_mr_dereg:
/* deregister the memory regions */
rpma_mr_dereg(&send_mr);
err_peer_delete:
/* delete the peer object */
rpma_peer_delete(&peer);
err_mr_free:
/* free the memory */
free(send);
return ret;
}