| 98 | } |
| 99 | |
| 100 | void Transceiver::init_socket(const std::string& identifier, bool bind) |
| 101 | { |
| 102 | LogFunc << VAR(bind); |
| 103 | |
| 104 | static auto kTempDir = temp_directory(); |
| 105 | |
| 106 | std::string path = std::format("{}/maafw-agent-{}.sock", kTempDir, identifier); |
| 107 | ipc_addr_ = std::format("ipc://{}", path); |
| 108 | ipc_path_ = MaaNS::path(path); |
| 109 | is_tcp_ = false; |
| 110 | |
| 111 | LogInfo << VAR(ipc_addr_) << VAR(identifier); |
| 112 | |
| 113 | zmq_sock_ = zmq::socket_t(zmq_ctx_, zmq::socket_type::pair); |
| 114 | |
| 115 | zmq_pollitem_send_ = zmq::pollitem_t(zmq_sock_.handle(), 0, ZMQ_POLLOUT, 0); |
| 116 | zmq_pollitem_recv_ = zmq::pollitem_t(zmq_sock_.handle(), 0, ZMQ_POLLIN, 0); |
| 117 | |
| 118 | is_bound_ = bind; |
| 119 | |
| 120 | if (is_bound_) { |
| 121 | zmq_sock_.bind(ipc_addr_); |
| 122 | } |
| 123 | else { |
| 124 | zmq_sock_.connect(ipc_addr_); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | static uint16_t parse_port_from_endpoint(const std::string& endpoint) |
| 129 | { |
nothing calls this directly
no test coverage detected