| 170 | } |
| 171 | |
| 172 | void FetchRequest::handle_connecting() { |
| 173 | fd_set write_fds; |
| 174 | FD_ZERO(&write_fds); |
| 175 | FD_SET(mSocketFd, &write_fds); |
| 176 | |
| 177 | struct timeval timeout; |
| 178 | timeout.tv_sec = 0; |
| 179 | timeout.tv_usec = 0; // Non-blocking check |
| 180 | |
| 181 | int result = select(mSocketFd + 1, nullptr, &write_fds, nullptr, &timeout); |
| 182 | |
| 183 | if (result > 0) { |
| 184 | // Check for connection errors |
| 185 | int sock_err = 0; |
| 186 | socklen_t len = sizeof(sock_err); |
| 187 | getsockopt(mSocketFd, SOL_SOCKET, SO_ERROR, (char*)&sock_err, &len); |
| 188 | |
| 189 | if (sock_err != 0) { |
| 190 | complete_error("Connection failed"); |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | // Connected! Build HTTP request |
| 195 | mRequestBuffer = "GET " + mPath + " HTTP/1.1\r\n"; |
| 196 | mRequestBuffer += "Host: " + mHostname + "\r\n"; |
| 197 | mRequestBuffer += "Connection: close\r\n\r\n"; |
| 198 | |
| 199 | mBytesSent = 0; |
| 200 | mState = SENDING; |
| 201 | mStateStartTime = fl::millis(); |
| 202 | } else if (result < 0) { |
| 203 | complete_error("select() failed during connection"); |
| 204 | } else { |
| 205 | // Timeout check (5 seconds) |
| 206 | if (fl::millis() - mStateStartTime > 5000) { |
| 207 | complete_error("Connection timeout"); |
| 208 | } |
| 209 | // else: Not ready yet, try again on next update() |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | void FetchRequest::handle_sending() { |
| 214 | ssize_t sent = send(mSocketFd, |
nothing calls this directly
no test coverage detected