xiaoxiang781216 opened a new issue #2833:
URL: https://github.com/apache/incubator-nuttx/issues/2833


   fs layer has many places to check socket handler explicitly:
   ```
   int nx_close(int fd)
   {
     /* Did we get a valid file descriptor? */
   
     if (fd >= CONFIG_NFILE_DESCRIPTORS)
       {
         /* Close a socket descriptor */
   
   #ifdef CONFIG_NET
         if (fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
           {
             return net_close(fd);
           }
         else
   #endif
           {
             return -EBADF;
           }
       }
   
     /* Close the driver or mountpoint.  NOTES: (1) there is no
      * exclusion mechanism here, the driver or mountpoint must be
      * able to handle concurrent operations internally, (2) The driver
      * may have been opened numerous times (for different file
      * descriptors) and must also handle being closed numerous times.
      * (3) for the case of the mountpoint, we depend on the close
      * methods bing identical in signature and position in the operations
      * vtable.
      */
   
     return files_close(fd);
   }
   ```
   It's better to use the same approach we have done for the named semphare, 
mqueue or eventfd:
   https://github.com/apache/incubator-nuttx/tree/master/fs/mqueue
   https://github.com/apache/incubator-nuttx/tree/master/fs/semaphore
   https://github.com/apache/incubator-nuttx/blob/master/fs/vfs/fs_eventfd.c
   so we can:
   1. unify socket access api
   2. avoid the code duplication
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to