socket( AF_INET, SOCK_STREAM, IPPROTO_TCP )这个返回值表示什么意义
2个回答
展开全部
RETURN VALUE
On success, a file descriptor for the new socket is returned. On
error, -1 is returned, and errno is set appropriately.
ERRORS
EACCES Permission to create a socket of the specified type and/or pro-
tocol is denied.
EAFNOSUPPORT
The implementation does not support the specified address fam-
ily.
EINVAL Unknown protocol, or protocol family not available.
EINVAL Invalid flags in type.
EMFILE Process file table overflow.
ENFILE The system limit on the total number of open files has been
reached.
ENOBUFS or ENOMEM
Insufficient memory is available. The socket cannot be created
until sufficient resources are freed.
EPROTONOSUPPORT
The protocol type or the specified protocol is not supported
within this domain.
Other errors may be generated by the underlying protocol modules.
例子:
clientfd = socket(AF_INET, SOCK_STREAM, 0);
if (clientfd < 0) {
LOG_RECORD(LOG_ERR, "Create socket error.");
return -1;
}
ret = connect(clientfd, (struct sockaddr *)&host_addr, sizeof(host_addr));
On success, a file descriptor for the new socket is returned. On
error, -1 is returned, and errno is set appropriately.
ERRORS
EACCES Permission to create a socket of the specified type and/or pro-
tocol is denied.
EAFNOSUPPORT
The implementation does not support the specified address fam-
ily.
EINVAL Unknown protocol, or protocol family not available.
EINVAL Invalid flags in type.
EMFILE Process file table overflow.
ENFILE The system limit on the total number of open files has been
reached.
ENOBUFS or ENOMEM
Insufficient memory is available. The socket cannot be created
until sufficient resources are freed.
EPROTONOSUPPORT
The protocol type or the specified protocol is not supported
within this domain.
Other errors may be generated by the underlying protocol modules.
例子:
clientfd = socket(AF_INET, SOCK_STREAM, 0);
if (clientfd < 0) {
LOG_RECORD(LOG_ERR, "Create socket error.");
return -1;
}
ret = connect(clientfd, (struct sockaddr *)&host_addr, sizeof(host_addr));
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询