提交 39f3f93e 编写于 作者: Lawlieta's avatar Lawlieta

[net][sal] Fix accept create new socket failed issue.

上级 52761fb9
......@@ -47,8 +47,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
if (fd < 0)
{
rt_set_errno(-ENOMEM);
sal_closesocket(socket);
sal_closesocket(new_socket);
return -1;
}
......@@ -74,6 +73,8 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
return fd;
}
rt_set_errno(-ENOMEM);
sal_closesocket(new_socket);
return -1;
}
......
......@@ -411,20 +411,23 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
if (new_socket != -1)
{
int retval;
int new_socket;
int new_sal_socket;
struct sal_socket *new_sock;
/* allocate a new socket structure and registered socket options */
new_socket = socket_new();
if (new_socket < 0)
new_sal_socket = socket_new();
if (new_sal_socket < 0)
{
sock->ops->closesocket(new_socket);
return -1;
}
new_sock = sal_get_socket(new_socket);
new_sock = sal_get_socket(new_sal_socket);
retval = socket_init(sock->domain, sock->type, sock->protocol, &new_sock);
if (retval < 0)
{
sock->ops->closesocket(new_socket);
rt_memset(new_sock, 0x00, sizeof(struct sal_socket));
LOG_E("New socket registered failed, return error %d.", retval);
return -1;
}
......@@ -432,7 +435,7 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
/* socket struct user_data used to store the acquired new socket */
new_sock->user_data = (void *) new_socket;
return new_sock->socket;
return new_sal_socket;
}
return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册