MCPcopy Create free account
hub / github.com/FastLED/FastLED / handle_dns_lookup

Method handle_dns_lookup

src/fl/net/http/fetch_request.cpp.hpp:119–170  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119void FetchRequest::handle_dns_lookup() {
120 // Pump async system before DNS to keep server responsive
121 fl::task::run(1000);
122
123 FL_WARN("[FETCH] Resolving hostname: " << mHostname);
124
125 // DNS lookup (blocking 10-100ms, but acceptable)
126 // Note: localhost is typically instant due to OS caching
127 mDnsResult = gethostbyname(mHostname.c_str());
128
129 // Pump async system after DNS to resume server pumping
130 fl::task::run(1000);
131
132 if (!mDnsResult) {
133 complete_error("DNS lookup failed");
134 return;
135 }
136
137 // Create socket
138 mSocketFd = socket(AF_INET, SOCK_STREAM, 0);
139 if (mSocketFd < 0) {
140 complete_error("Failed to create socket");
141 return;
142 }
143
144 // Set non-blocking mode
145#ifdef FL_IS_WIN
146 u_long mode = 1; // 1 = non-blocking
147 ioctlsocket(mSocketFd, FIONBIO, &mode);
148#else
149 int flags = fcntl(mSocketFd, F_GETFL, 0);
150 fcntl(mSocketFd, F_SETFL, flags | O_NONBLOCK);
151#endif
152
153 // Initiate non-blocking connect
154 sockaddr_in server_addr{};
155 server_addr.sin_family = AF_INET;
156 server_addr.sin_port = htons(static_cast<u16>(mPort));
157 // Use memcpy to extract address pointer — h_addr_list[0] may be misaligned
158 // on some platforms (macOS arm64 UBSan flags this)
159 char *addr_ptr = nullptr;
160 fl::memcpy(&addr_ptr, mDnsResult->h_addr_list, sizeof(addr_ptr));
161 fl::memcpy(&server_addr.sin_addr, addr_ptr, mDnsResult->h_length);
162
163 FL_WARN("[FETCH] Waiting for connection to " << mHostname << ":" << mPort);
164
165 connect(mSocketFd, (sockaddr*)&server_addr, sizeof(server_addr));
166 // connect() returns immediately with EINPROGRESS/WSAEWOULDBLOCK (expected)
167
168 mState = CONNECTING;
169 mStateStartTime = fl::millis();
170}
171
172void FetchRequest::handle_connecting() {
173 fd_set write_fds;

Callers

nothing calls this directly

Calls 7

runFunction · 0.50
socketClass · 0.50
fcntlFunction · 0.50
memcpyFunction · 0.50
connectFunction · 0.50
millisFunction · 0.50
c_strMethod · 0.45

Tested by

no test coverage detected