MCPcopy Create free account
hub / github.com/MaaXYZ/MaaFramework / init_socket

Method init_socket

source/AgentCommon/Transceiver.cpp:100–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void 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
128static uint16_t parse_port_from_endpoint(const std::string& endpoint)
129{

Callers

nothing calls this directly

Calls 4

temp_directoryFunction · 0.85
handleMethod · 0.80
connectMethod · 0.65
bindMethod · 0.45

Tested by

no test coverage detected