File: mtt_client_process.c

package info (click to toggle)
rpma 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,040 kB
  • sloc: ansic: 27,313; sh: 1,805; perl: 1,148; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (2)
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
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2022, Intel Corporation */

/*
 * mtt_client_process.c -- process spawning threads with clients for server-side MT tests
 */

#include <librpma.h>

#include "mtt.h"
#include "mtt_connect.h"

const char data[] = "Hello server!";

struct client_prestate {
	char *addr;
	unsigned port;
};

/*
 * thread -- run a single client
 */
static void
thread(unsigned id, void *prestate, void *state,
		struct mtt_result *result)
{
	struct client_prestate *pr = (struct client_prestate *)prestate;

	struct rpma_peer *peer = NULL;
	struct rpma_conn *conn = NULL;

	if (mtt_client_peer_new(result, pr->addr, &peer))
		return;

	struct rpma_conn_private_data pdata;
	pdata.ptr = (void *)data;
	pdata.len = sizeof(data);

	if (mtt_client_connect(result, pr->addr, pr->port, peer, &conn, &pdata)) {
		mtt_client_peer_delete(result, &peer);
		return;
	}

	mtt_client_disconnect(result, &conn);
	mtt_client_peer_delete(result, &peer);
}

int
client_main(char *addr, unsigned port, unsigned threads_num)
{
	struct client_prestate client_prestate = {addr, port};

	struct mtt_test test = {
			&client_prestate,
			NULL,
			NULL,
			NULL,
			thread,
			NULL,
			NULL,
			NULL,
			NULL,
			NULL
	};

	return mtt_run(&test, threads_num);
}