Kylin/Nng/Socket.cpp

30 lines
621 B
C++
Raw Normal View History

2024-10-29 21:51:37 +08:00
#include "Socket.h"
2024-10-29 23:13:33 +08:00
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
2024-10-29 21:51:37 +08:00
namespace Nng {
2024-10-29 23:13:33 +08:00
Socket::Socket(Protocol protocol) {
if (protocol == Protocol::Bus) {
} else if (protocol == Protocol::Publisher) {
} else if (protocol == Protocol::Request) {
nng_req0_open(&m_socket);
} else if (protocol == Protocol::Reply) {
nng_rep0_open(&m_socket);
} else {
assert(true || "ggg");
}
}
2024-10-29 21:51:37 +08:00
Socket::~Socket() {
if (m_socket.id != 0) {
nng_close(m_socket);
}
}
2024-10-29 23:13:33 +08:00
int Socket::id() const {
return nng_socket_id(m_socket);
}
2024-10-29 21:51:37 +08:00
} // namespace Nng