Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef __CLIENT_H__
19#define __CLIENT_H__
20
21#include <thread>
22#include <unordered_map>
23#include <vector>
24#include <netinet/in.h>
25
26#include "logger.h"
27#include "types.h"
28
29namespace mesh {
30 // @class Client
31 // @brief Client in client-server architecture.
32 class Client {
33 mesh::NodeIdent self;
34 std::unordered_map<std::string, mesh::NodeIdent> peers;
35 int ai_family{AF_INET};
36
37 // map of sending sockets
38 std::unordered_map<std::string, int> send_sockets;
39
40 // Independent threads for each client
41 std::vector<std::thread> threads;
42
43 std::shared_ptr<p2p::Logger::p2p_log> p2p_log{nullptr};
44
45 void set_sock_addr_(const char *address_str, int port, struct sockaddr_in *saddr);
46 int connect_to_server_(const std::string &ip, int port);
47
48 public:
50 const std::unordered_map<std::string, mesh::NodeIdent> &servers);
51
57 int start();
58
67 int send_buf(const std::string &dst, void *buf, size_t len);
68
73 int shutdown();
74 };
75
76} // namespace mesh
77
78#endif
Definition client.h:32
int shutdown()
close connections to all servers on all the workers.
Client(const mesh::NodeIdent &self, const std::unordered_map< std::string, mesh::NodeIdent > &servers)
int start()
Connects to all the servers on all the workers and saves the Socket ids in send_socks_ map.
int send_buf(const std::string &dst, void *buf, size_t len)
sends data to the destination.
Definition client.h:29
Definition types.h:27