-
Notifications
You must be signed in to change notification settings - Fork 1
/
sockets.h
executable file
·51 lines (44 loc) · 1.24 KB
/
sockets.h
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
#ifndef __scable_sockets__
#define __scable_sockets__
#include "rte.h"
#include "socket.h"
class Sockets {
private:
std::vector<Socket> sockets;
Sockets() { }
public:
static Sockets *create() {
auto it = new Sockets();
int lc;
RTE_LCORE_FOREACH(lc) {
auto socketId = rte_lcore_to_socket_id(lc);
auto socket = std::find_if(it->sockets.begin(),
it->sockets.end(),
[socketId](const Socket& obj) {
return obj.getId() == socketId;
});
if (socket == it->sockets.end()) {
socket = it->sockets.emplace(it->sockets.end(), Socket(socketId));
}
socket->addLcore(lc);
}
for(auto socket : it->sockets) {
LOG(INFO) << "Socket:" << socket.getId()
<< " Lcore:[" << join(socket.getLcores(), ":") << "]";
}
return it;
}
int size() const {
return sockets.size();
}
Socket *findFree() {
for (auto it = sockets.begin(); it != sockets.end(); ++it) {
if (!it->isFree()) {
return &(*it);
}
}
LOG(ERROR) << "no free Socket found!";
return 0;
}
};
#endif