Merge pull request #1759 from Lawlieta/chenyong
[net][sal] Fix accept create new socket failed issue.
This commit is contained in:
commit
3632693141
|
@ -47,8 +47,7 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
rt_set_errno(-ENOMEM);
|
rt_set_errno(-ENOMEM);
|
||||||
sal_closesocket(socket);
|
sal_closesocket(new_socket);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +73,8 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rt_set_errno(-ENOMEM);
|
||||||
|
sal_closesocket(new_socket);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -411,20 +411,23 @@ int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
|
||||||
if (new_socket != -1)
|
if (new_socket != -1)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
int new_socket;
|
int new_sal_socket;
|
||||||
struct sal_socket *new_sock;
|
struct sal_socket *new_sock;
|
||||||
|
|
||||||
/* allocate a new socket structure and registered socket options */
|
/* allocate a new socket structure and registered socket options */
|
||||||
new_socket = socket_new();
|
new_sal_socket = socket_new();
|
||||||
if (new_socket < 0)
|
if (new_sal_socket < 0)
|
||||||
{
|
{
|
||||||
|
sock->ops->closesocket(new_socket);
|
||||||
return -1;
|
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);
|
retval = socket_init(sock->domain, sock->type, sock->protocol, &new_sock);
|
||||||
if (retval < 0)
|
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);
|
LOG_E("New socket registered failed, return error %d.", retval);
|
||||||
return -1;
|
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 */
|
/* socket struct user_data used to store the acquired new socket */
|
||||||
new_sock->user_data = (void *) new_socket;
|
new_sock->user_data = (void *) new_socket;
|
||||||
|
|
||||||
return new_sock->socket;
|
return new_sal_socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in New Issue