Socket编程:listen()函数英文翻译

作者:C语言达人
链接:https://zhuanlan.zhihu.com/p/24951131
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

本篇翻译的listen()函数,我参考的国外网站是:

listen

朋友们可以自由转载我对英文的中文翻译,但是对于“作者注:”的描述,转载时请注明出处和作者,否则视为侵权。

下面是翻译的正文,由于水平有限,有些翻译的不好,有些未能翻译出,恳请读者指出与见谅。

NAME

listen - listenfor socket connections and limit the queue of incoming connections

监听客户端发来的socket连接,而且限制接入的连接的队列。

SYNOPSIS

#include <sys/socket.h>

int listen(int socket,int backlog);

listen()函数原型。

DESCRIPTION

The listen() function marks aconnection-mode socket, specified by the socket argument, as acceptingconnections, and limits the number of outstanding connections in the socket'slisten queue to the value specified by the backlog argument.

这个listen()函数标记着一个处于连接模式的socket,也就是listen()函数的socket参数。listen()函数接收外来的连接,然后限制socket监听队列里的未完成的连接数量,限制的这个连接数量由参数backlog 指定。

作者注:

我觉得backlog 这个参数决定了listen()函数能处理多少个连接,超出这个连接数的话,listen()就不管了吧。

If listen() is called with a backlog argument valuethat is less than 0, the function sets the length of the socket's listen queueto 0.

如果传给listen()函数的backlog参数的值小于0,那么此函数会将socket的监听队列长度设置为0.

作者注:

给listen()函数传backlog参数时,肯定不会传给负数吧,这个可以人为控制的。

The implementationmay include incomplete connections in the queue subject to the queue limit. Theimplementation may also increase the specified queue limit internally if itincludes such incomplete connections in the queue subject to this limit.

由于容纳外来连接数量队列的限制,函数实现中也许包含连接队列中还有未完成的连接。后半句不知如何翻译。

Implementationsmay limit the length of the socket's listen queue. If backlog exceeds theimplementation-dependent maximum queue length, the length of the socket'slisten queue will be set to the maximum supported value.

函数实现也许会限制socket的监听队列长度。如果参数backlog超过了最大的队列长度,那么socket的监听队列的长度会被设置为最大的支持的值。

作者注:

服务器端能处理的客户端请求数量是有限的。服务器在处理一个客户端请求时,此时再来一个客户的请求,那么服务器就顾不上了,只能把新来的请求放在一个队列里。队列的长度是有限制的,超过这个限制的客户请求,可能就被丢弃吧。

The socket in usemay require the process to have appropriate privileges to use the listen() function.

被使用的socket也许会要求进程有合适的权限来使用listen()函数。

RETURN VALUE

Upon successfulcompletions, listen() returns 0. Otherwise, -1 is returned and errno is set to indicatethe error.

一旦listen()函数成功执行,函数会返回0,否则返回-1,而且会有错误信息来解释是什么错误。

ERRORS

The listen() function will failif:

函数listen()会由于以下原因失败:

[EBADF]

The socket argument is not avalid file descriptor.

参数socket不是一个有效的文件描述符。

[EDESTADDRREQ]

The socket is not bound to a localaddress, and the protocol does not support listening on an unbound socket.

socket没有被绑定到一个本地地址,协议也不支持在一个未绑定的socket上监听。

[EINVAL]

The socket is alreadyconnected.

socket已经处于连接中。

[ENOTSOCK]

The socket argument does notrefer to a socket.

参数socket没有引用到一个socket。

作者注:

参数socket是一个文件描述符,但是这个文件描述符没有引用到任何一个socket文件,形象的说,就是这个文件描述符指向了一个空空的东西。

[EOPNOTSUPP]

The socket protocol does not support listen().

socket协议不支持listen()函数。

The listen() function may failif:

函数listen()会由于以下原因可能会失败:

[EACCES]

The calling process does not have theappropriate privileges.

调用listen()函数的进程没有合适的权限。

[EINVAL]

The socket has been shutdown.

参数socket对应的套接字已经被关闭了。

[ENOBUFS]

Insufficient resources are available inthe system to complete the call.

系统中没有足够的资源来完成调用。

转载于:https://www.cnblogs.com/itblog/p/7236560.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值