Mercurial > hg > CbC > CbC_llvm
comparison lldb/source/Host/common/Socket.cpp @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | 1d019706d866 |
children | 2e18cbf3894f |
comparison
equal
deleted
inserted
replaced
172:9fbae9c8bf63 | 173:0572611fdcc8 |
---|---|
145 socket_up.reset(); | 145 socket_up.reset(); |
146 | 146 |
147 return socket_up; | 147 return socket_up; |
148 } | 148 } |
149 | 149 |
150 Status Socket::TcpConnect(llvm::StringRef host_and_port, | 150 llvm::Expected<std::unique_ptr<Socket>> |
151 bool child_processes_inherit, Socket *&socket) { | 151 Socket::TcpConnect(llvm::StringRef host_and_port, |
152 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_COMMUNICATION)); | 152 bool child_processes_inherit) { |
153 LLDB_LOGF(log, "Socket::%s (host/port = %s)", __FUNCTION__, | 153 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); |
154 host_and_port.str().c_str()); | 154 LLDB_LOG(log, "host_and_port = {0}", host_and_port); |
155 | 155 |
156 Status error; | 156 Status error; |
157 std::unique_ptr<Socket> connect_socket( | 157 std::unique_ptr<Socket> connect_socket( |
158 Create(ProtocolTcp, child_processes_inherit, error)); | 158 Create(ProtocolTcp, child_processes_inherit, error)); |
159 if (error.Fail()) | 159 if (error.Fail()) |
160 return error; | 160 return error.ToError(); |
161 | 161 |
162 error = connect_socket->Connect(host_and_port); | 162 error = connect_socket->Connect(host_and_port); |
163 if (error.Success()) | 163 if (error.Success()) |
164 socket = connect_socket.release(); | 164 return std::move(connect_socket); |
165 | 165 |
166 return error; | 166 return error.ToError(); |
167 } | 167 } |
168 | 168 |
169 Status Socket::TcpListen(llvm::StringRef host_and_port, | 169 llvm::Expected<std::unique_ptr<TCPSocket>> |
170 bool child_processes_inherit, Socket *&socket, | 170 Socket::TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit, |
171 Predicate<uint16_t> *predicate, int backlog) { | 171 Predicate<uint16_t> *predicate, int backlog) { |
172 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); | 172 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); |
173 LLDB_LOGF(log, "Socket::%s (%s)", __FUNCTION__, host_and_port.str().c_str()); | 173 LLDB_LOG(log, "host_and_port = {0}", host_and_port); |
174 | 174 |
175 Status error; | 175 Status error; |
176 std::string host_str; | 176 std::string host_str; |
177 std::string port_str; | 177 std::string port_str; |
178 int32_t port = INT32_MIN; | 178 int32_t port = INT32_MIN; |
179 if (!DecodeHostAndPort(host_and_port, host_str, port_str, port, &error)) | 179 if (!DecodeHostAndPort(host_and_port, host_str, port_str, port, &error)) |
180 return error; | 180 return error.ToError(); |
181 | 181 |
182 std::unique_ptr<TCPSocket> listen_socket( | 182 std::unique_ptr<TCPSocket> listen_socket( |
183 new TCPSocket(true, child_processes_inherit)); | 183 new TCPSocket(true, child_processes_inherit)); |
184 if (error.Fail()) | |
185 return error; | |
186 | 184 |
187 error = listen_socket->Listen(host_and_port, backlog); | 185 error = listen_socket->Listen(host_and_port, backlog); |
188 if (error.Success()) { | 186 if (error.Fail()) |
189 // We were asked to listen on port zero which means we must now read the | 187 return error.ToError(); |
190 // actual port that was given to us as port zero is a special code for | 188 |
191 // "find an open port for me". | 189 // We were asked to listen on port zero which means we must now read the |
192 if (port == 0) | 190 // actual port that was given to us as port zero is a special code for |
193 port = listen_socket->GetLocalPortNumber(); | 191 // "find an open port for me". |
194 | 192 if (port == 0) |
195 // Set the port predicate since when doing a listen://<host>:<port> it | 193 port = listen_socket->GetLocalPortNumber(); |
196 // often needs to accept the incoming connection which is a blocking system | 194 |
197 // call. Allowing access to the bound port using a predicate allows us to | 195 // Set the port predicate since when doing a listen://<host>:<port> it |
198 // wait for the port predicate to be set to a non-zero value from another | 196 // often needs to accept the incoming connection which is a blocking system |
199 // thread in an efficient manor. | 197 // call. Allowing access to the bound port using a predicate allows us to |
200 if (predicate) | 198 // wait for the port predicate to be set to a non-zero value from another |
201 predicate->SetValue(port, eBroadcastAlways); | 199 // thread in an efficient manor. |
202 socket = listen_socket.release(); | 200 if (predicate) |
203 } | 201 predicate->SetValue(port, eBroadcastAlways); |
204 | 202 return std::move(listen_socket); |
205 return error; | 203 } |
206 } | 204 |
207 | 205 llvm::Expected<std::unique_ptr<UDPSocket>> |
208 Status Socket::UdpConnect(llvm::StringRef host_and_port, | 206 Socket::UdpConnect(llvm::StringRef host_and_port, |
209 bool child_processes_inherit, Socket *&socket) { | 207 bool child_processes_inherit) { |
210 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); | 208 return UDPSocket::Connect(host_and_port, child_processes_inherit); |
211 LLDB_LOGF(log, "Socket::%s (host/port = %s)", __FUNCTION__, | |
212 host_and_port.str().c_str()); | |
213 | |
214 return UDPSocket::Connect(host_and_port, child_processes_inherit, socket); | |
215 } | 209 } |
216 | 210 |
217 Status Socket::UnixDomainConnect(llvm::StringRef name, | 211 Status Socket::UnixDomainConnect(llvm::StringRef name, |
218 bool child_processes_inherit, | 212 bool child_processes_inherit, |
219 Socket *&socket) { | 213 Socket *&socket) { |