@@ -255,55 +255,54 @@ void Server::setupSharedMemory()
255255void Server::setupFDPassingServer ()
256256{
257257 DBG (120 , " Setup FD Passing Server." );
258-
258+
259259 const char * socket_path = " /tmp/falcon-fd-passing.sock" ;
260260 _FDPassingServerFD = Syscall::createFDPassingServer (socket_path);
261-
261+
262262 if (_FDPassingServerFD < 0 ) {
263263 ERR (" Failed to create FD passing server socket" );
264264 exit (EXIT_FAILURE);
265265 }
266-
266+
267267 DBG (120 , " FD Passing Server socket created at:" << socket_path);
268-
268+
269269 // Start thread to handle FD passing requests
270270 _FDPassingThread = std::thread (&Server::handleFDPassingRequests, this );
271271}
272272
273273void Server::handleFDPassingRequests ()
274274{
275275 DBG (120 , " FD Passing handler thread started" );
276-
277- // Set socket to non-blocking
276+
277+ // set socket non-blocking
278278 int flags = fcntl (_FDPassingServerFD, F_GETFL, 0 );
279279 fcntl (_FDPassingServerFD, F_SETFL, flags | O_NONBLOCK);
280-
280+
281281 std::vector<int > client_fds;
282-
282+
283283 while (RunServer) {
284- // Accept new connections
284+
285285 struct sockaddr_un client_addr;
286286 socklen_t client_len = sizeof (client_addr);
287-
287+
288288 int new_client_fd = accept (_FDPassingServerFD, (struct sockaddr *)&client_addr, &client_len);
289-
289+
290290 if (new_client_fd >= 0 ) {
291291 DBG (120 , " FD passing new client connected, fd:" << new_client_fd);
292292 client_fds.push_back (new_client_fd);
293293 }
294-
295- // Process existing connections
294+
296295 auto it = client_fds.begin ();
297296 while (it != client_fds.end ()) {
298297 int client_fd = *it;
299298 uint16_t requested_fd;
300-
299+
301300 ssize_t n = read (client_fd, &requested_fd, sizeof (requested_fd));
302-
301+
303302 if (n == sizeof (requested_fd)) {
304303 DBG (120 , " FD passing request for FD:" << requested_fd);
305-
306- // Send the requested FD to the client
304+
305+ // send the requested FD to the client
307306 if (Syscall::sendFD (client_fd, requested_fd) < 0 ) {
308307 ERR (" Failed to send FD:" << requested_fd);
309308 close (client_fd);
@@ -313,7 +312,7 @@ void Server::handleFDPassingRequests()
313312 ++it;
314313 }
315314 } else if (n == 0 ) {
316- // Connection closed
315+ // connection closed
317316 DBG (120 , " FD passing client disconnected, fd:" << client_fd);
318317 close (client_fd);
319318 it = client_fds.erase (it);
@@ -325,21 +324,16 @@ void Server::handleFDPassingRequests()
325324 } else {
326325 ++it;
327326 }
328- } else {
329- // Partial read - shouldn't happen with small fixed-size data
330- ERR (" Partial read of FD request" );
331- close (client_fd);
332- it = client_fds.erase (it);
333327 }
334328 }
335-
336- std::this_thread::sleep_for (std:: chrono::milliseconds ( 10 ));
329+
330+ std::this_thread::sleep_for (chrono::microseconds (IDLE_SLEEP_MICROSECONDS ));
337331 }
338-
339- // Clean up
332+
333+ // clean up
340334 for (int fd : client_fds) {
341335 close (fd);
342336 }
343-
337+
344338 DBG (120 , " FD Passing handler thread exiting" );
345339}
0 commit comments