sal_socket()
和sal_accept()
都调用了socket_new()
,不是生成和占用两个块了吗?
int sal_socket(int domain, int type, int protocol)
{
int retval;
int socket, proto_socket;
struct sal_socket *sock;
struct sal_proto_family *pf;
/* allocate a new socket and registered socket options */
socket = socket_new(); //??????????????????????????????????????
if (socket < 0)
{
return -1;
}
......
}
int sal_accept(int socket, struct sockaddr *addr, socklen_t *addrlen)
{
int new_socket;
struct sal_socket *sock;
struct sal_proto_family *pf;
/* get the socket object by socket descriptor */
SAL_SOCKET_OBJ_GET(sock, socket);
/* check the network interface socket operations */
SAL_NETDEV_SOCKETOPS_VALID(sock->netdev, pf, accept);
new_socket = pf->skt_ops->accept((int) sock->user_data, addr, addrlen);
if (new_socket != -1)
{
int retval;
int new_sal_socket;
struct sal_socket *new_sock;
/* allocate a new socket structure and registered socket options */
new_sal_socket = socket_new(); //???????????????????????????
if (new_sal_socket < 0)
{
pf->skt_ops->closesocket(new_socket);
return -1;
}
......
}
这个就是 accept 函数的意义:
The accept() system call is used with connection-based socket types (SOCK_STREAM, SOCK_SEQPACKET).It extracts the first connection request on the queue of pending connections for the listening socket, sockfd, creates a new connected socket, and returns a new file descriptor referring to that socket.The newly created socket is not in the listening state.The original socket sockfd is unaffected by this call.
accept()系统调用用于基于连接的套接字类型(SOCK_STREAM, SOCK_SEQPACKET)。它提取侦听套接字sockfd挂起连接队列上的第一个连接请求,创建一个新的已连接套接字,并返回一个引用该套接字。新创建的套接字不处于监听状态。原始套接字sockfd不受此调用的影响。