This repository was archived by the owner on Jan 11, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVMATransmitter.cpp
More file actions
69 lines (55 loc) · 1.58 KB
/
VMATransmitter.cpp
File metadata and controls
69 lines (55 loc) · 1.58 KB
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
#include <string>
#include <memory>
#include <thread>
#include <queue>
#include <iostream>
#include <system_error>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <mellanox/vma_extra.h>
#include <capnp/serialize.h>
#include "utils.h"
#include "VMATransmitter.h"
#include "message.capnp.h"
using namespace std;
namespace transport {
VMATransmitter::VMATransmitter(const size_t i, const std::string &address, const size_t port, TransmitterPool &pool)
: Transmitter(i, address, port, pool) {
cout << "Connecting VMA Transmitter to " << serverIP << ", port " << serverPort << endl;
int rc;
servAddr.sin_family = AF_INET;
servAddr.sin_addr.s_addr = inet_addr(serverIP.c_str());
servAddr.sin_port = htons(serverPort);
cout << "Thread " << index << ": Connecting to " << endPoint.str() << "..." << endl;
sock = socket(AF_INET, SOCK_STREAM, 0);
assert(sock);
rc = connect(sock, (struct sockaddr *) &servAddr, sizeof(servAddr));
assert(rc == 0);
//vma_api = vma_get_api();
//assert(vma_api == nullptr);
cout << "VMA API available" << endl;
}
void
VMATransmitter::operator()() {
try {
// send the messages
cout << "Thread " << index << ": Sending messages..." << endl;
int flags = MSG_VMA_ZCOPY_FORCE;
int rc;
while(true) {
MessageItem rawMsg;
parentPool.msgQueue.wait_dequeue(rawMsg);
if (rawMsg.first != nullptr && rawMsg.second != 0) {
rc = send(sock, rawMsg.first, rawMsg.second, flags);
assert(rc != -1);
} else {
break;
}
}
cout << "Finished." << endl;
} catch (const std::system_error &e) {
std::cerr << e.what() << std::endl;
return;
}
}
}