mirror of
https://github.com/apache/nuttx.git
synced 2026-08-02 04:38:59 +00:00
This commit removes unnecessary file duplication and memory allocation when passing file descriptors through Unix domain sockets, leveraging the new filep reference counting framework. Background: With the new filep framework, file structures (filep) can be safely shared across processes using reference counting. When passing file descriptors through SCM_RIGHTS control messages on local sockets, the previous implementation unnecessarily duplicated the entire file structure. Changes: 1. In local_sendctl() (sender side): - Removed allocation of filep2 structure (kmm_zalloc) - Removed file_dup2() call that copied the file structure - Now directly stores the original filep with its reference count - Eliminates memory allocation overhead and potential failure points 2. In local_recvctl() (receiver side): - Changed from file_close() + kmm_free() to file_put() - file_put() properly decrements reference count and handles cleanup - Consistent with the new filep reference counting model 3. In local_freectl() (cleanup on error): - Changed from file_close() + kmm_free() to file_put() - Ensures proper reference count management during error paths Technical Details: The new filep framework ensures that: - Multiple file descriptors across different processes can reference the same underlying filep structure safely - Reference counting (via file_get/file_put) manages lifetime correctly - The underlying file object is only released when all references are gone This change is safe because file_dup() in the receiver already calls file_get() internally to increment the reference count for the new fd, so the filep remains valid after the sender calls file_put(). Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com> |
||
|---|---|---|
| .. | ||
| CMakeLists.txt | ||
| Kconfig | ||
| local.h | ||
| local_accept.c | ||
| local_bind.c | ||
| local_conn.c | ||
| local_connect.c | ||
| local_fifo.c | ||
| local_listen.c | ||
| local_netpoll.c | ||
| local_recvmsg.c | ||
| local_recvutils.c | ||
| local_release.c | ||
| local_sendmsg.c | ||
| local_sendpacket.c | ||
| local_sockif.c | ||
| Make.defs | ||