diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-09-16 20:29:00 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-09-16 20:29:00 +0000 |
commit | 28ac0618357cd777265cff69fc7ec196b7ec51de (patch) | |
tree | 0074ae9aa5276d7a0272b8dcdd98819531e213a6 /nuttx/net/net_sockets.c | |
parent | 9baa429e57191d588bf3534228c896dfe9e9e155 (diff) | |
download | px4-nuttx-28ac0618357cd777265cff69fc7ec196b7ec51de.tar.gz px4-nuttx-28ac0618357cd777265cff69fc7ec196b7ec51de.tar.bz2 px4-nuttx-28ac0618357cd777265cff69fc7ec196b7ec51de.zip |
Sockets were not being closed when a task exits
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2070 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/net_sockets.c')
-rw-r--r-- | nuttx/net/net_sockets.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/nuttx/net/net_sockets.c b/nuttx/net/net_sockets.c index 3db69519d..60141808a 100644 --- a/nuttx/net/net_sockets.c +++ b/nuttx/net/net_sockets.c @@ -161,6 +161,8 @@ int net_addreflist(FAR struct socketlist *list) int net_releaselist(FAR struct socketlist *list) { int crefs; + int ndx; + if (list) { /* Decrement the reference count on the list. @@ -182,12 +184,29 @@ int net_releaselist(FAR struct socketlist *list) */ if (crefs <= 0) - { + { + /* Close each open socket in the list + * REVISIT: net_closesocket() will attempt to use semaphores. + * If we actually are in the IDLE thread, then could this cause + * problems? Probably not, it the task has exited and crefs is + * zero, then there probably could not be a contender for the + * semaphore. + */ + + for (ndx = 0; ndx < CONFIG_NSOCKET_DESCRIPTORS; ndx++) + { + FAR struct socket *psock = &list->sl_sockets[ndx]; + if (psock->s_crefs > 0) + { + (void)net_closesocket(psock); + } + } + /* Destroy the semaphore and release the filelist */ (void)sem_destroy(&list->sl_sem); sched_free(list); - } + } } return OK; } @@ -226,14 +245,11 @@ int sockfd_allocate(int minsd) return ERROR; } -void sockfd_release(int sockfd) +void sock_release(FAR struct socket *psock) { - FAR struct socket *psock; - - /* Get the socket structure for this sockfd */ - - psock = sockfd_socket(sockfd); +#if CONFIG_DEBUG if (psock) +#endif { /* Take the list semaphore so that there will be no accesses * to this socket structure. @@ -262,6 +278,20 @@ void sockfd_release(int sockfd) } } +void sockfd_release(int sockfd) +{ + /* Get the socket structure for this sockfd */ + + FAR struct socket *psock = sockfd_socket(sockfd); + + /* Get the socket structure for this sockfd */ + + if (psock) + { + sock_release(psock); + } +} + FAR struct socket *sockfd_socket(int sockfd) { FAR struct socketlist *list; |