Merge pull request #2382 from Lawlieta/develop

[net][sal_socket] improve closesocke/shutdown error handling
This commit is contained in:
Bernard Xiong 2019-03-07 14:48:21 +08:00 committed by GitHub
commit 19563a21a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 44 additions and 20 deletions

View File

@ -78,29 +78,39 @@ RTM_EXPORT(bind);
int shutdown(int s, int how) int shutdown(int s, int how)
{ {
int socket; int error = 0;
int socket = -1;
struct dfs_fd *d; struct dfs_fd *d;
socket = dfs_net_getsocket(s);
if (socket < 0)
{
rt_set_errno(-ENOTSOCK);
return -1;
}
d = fd_get(s); d = fd_get(s);
if (d == NULL) if (d == NULL)
{ {
rt_set_errno(-EBADF); rt_set_errno(-EBADF);
return -1; return -1;
} }
socket = dfs_net_getsocket(s);
if (sal_shutdown(socket, how) == 0) if (sal_shutdown(socket, how) == 0)
{ {
error = 0;
}
else
{
rt_set_errno(-ENOTSOCK);
error = -1;
}
/* socket has been closed, delete it from file system fd */ /* socket has been closed, delete it from file system fd */
fd_put(d); fd_put(d);
fd_put(d); fd_put(d);
return 0; return error;
}
return -1;
} }
RTM_EXPORT(shutdown); RTM_EXPORT(shutdown);
@ -240,25 +250,39 @@ RTM_EXPORT(socket);
int closesocket(int s) int closesocket(int s)
{ {
int socket = dfs_net_getsocket(s); int error = 0;
int socket = -1;
struct dfs_fd *d; struct dfs_fd *d;
d = fd_get(s); socket = dfs_net_getsocket(s);
if(!d) if (socket < 0)
{ {
rt_set_errno(-ENOTSOCK);
return -1;
}
d = fd_get(s);
if (d == RT_NULL)
{
rt_set_errno(-EBADF);
return -1; return -1;
} }
if (sal_closesocket(socket) == 0) if (sal_closesocket(socket) == 0)
{ {
error = 0;
}
else
{
rt_set_errno(-ENOTSOCK);
error = -1;
}
/* socket has been closed, delete it from file system fd */ /* socket has been closed, delete it from file system fd */
fd_put(d); fd_put(d);
fd_put(d); fd_put(d);
return 0; return error;
}
return -1;
} }
RTM_EXPORT(closesocket); RTM_EXPORT(closesocket);