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

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

listen

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

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

NAME

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

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

SYNOPSIS

#include <[sys/socket.h](http://link.zhihu.com/?target=http%3A//pubs.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html)>

int listen(int *socket*, int *backlog*);

listen()函数原型。

DESCRIPTION

The listen() function marks a connection-mode socket, specified by the socket argument, as accepting connections, and limits the number of outstanding connections in the socket's listen 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 value that is less than 0, the function sets the length of the socket's listen queue to 0.

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

作者注:

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

The implementation may include incomplete connections in the queue subject to the queue limit. The implementation may also increase the specified queue limit internally if it includes such incomplete connections in the queue subject to this limit.

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

Implementations may limit the length of the socket's listen queue. If backlog exceeds the implementation-dependent maximum queue length, the length of the socket's listen queue will be set to the maximum supported value.

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

作者注:

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

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

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

RETURN VALUE

Upon successful completions, listen() returns 0. Otherwise, -1 is returned and errno is set to indicate the error.

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

ERRORS

The listen() function will fail if:

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

[EBADF]

The socket argument is not a valid file descriptor.

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

[EDESTADDRREQ]

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

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

[EINVAL]

The socket is already connected.

socket已经处于连接中。

[ENOTSOCK]

The socket argument does not refer to a socket.

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

作者注:

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

[EOPNOTSUPP]

The socket protocol does not support listen().

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

The listen() function may fail if:

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

[EACCES]

The calling process does not have the appropriate privileges.

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

[EINVAL]

The socket has been shut down.

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

[ENOBUFS]

Insufficient resources are available in the system to complete the call.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C语言答疑课堂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值