2018-12-01 6:40-8:00 NIO 源码阅读

本文详细解析了I/O通道的概念,包括其在硬件设备、文件、网络套接字及程序组件间的应用,阐述了通道的开闭状态及其多线程安全性。特别介绍了网络通道接口,涉及套接字的绑定、地址获取及选项设置,强调了方法调用的链式特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

阅读内容:

 

interface chanel

 

A nexus for I/O operations.

I/O操作的连接。

 

A channel represents an open connection to an entity such as a hardware device, a file, a network socket, or a program component that is capable of performing one or more distinct I/O operations, for example reading or writing.

 

Chanel表示打开一个连接如硬件、文件、网络套接字或程序组件执行一个或多个不同的I/O操作,例如读取或写入。

 

A channel is either open or closed. A channel is open upon creation, and once closed it remains closed. Once a channel is closed, any attempt to invoke an I/O operation upon it will cause a {@link ClosedChannelException} to be thrown. Whether or not a channel is open may be tested by invoking its {@link #isOpen isOpen} method.

通道要么是打开的,要么是关闭的。通道在创建时是打开的,一旦关闭,它就会保持关闭的状态。一旦通道关闭,任何对其调用I/O操作的尝试都会引发{@link ClosedChannelException}。通道是否打开可以通过调用其{@link #isOpen isOpen}方法进行测试。

 

Channels are, in general, intended to be safe for multithreaded access as described in the specifications of the interfaces and classes that extend and implement this interface.

 

一般来说,通道是用于多线程访问的,就像扩展和实现该接口的接口和类的规范中描述的那样。

 

interface NetworkChanel extend chanel

 

A channel to a network socket.

 

网络套接字的Chanel。

 

A channel that implements this interface is a channel to a network socket. The {@link#bind(SocketAddress) bind} method is used to bind the socket to a local {@link SocketAddress address}, the {@link #getLocalAddress() getLocalAddress} method returns the address that the socket is bound to, and the {@link #setOption(SocketOption,Object) setOption} and {@link #getOption(SocketOption) getOption} methods are used to set and query socket options. An implementation of this interface should specify the socket options that it supports.

 

实现此接口的通道是到网络套接字的通道。{@link#bind(SocketAddress) bind}方法用于将套接字绑定到本地的{@link SocketAddress address}, {@link# getLocalAddress() getLocalAddress}方法返回套接字绑定到的地址,{@link# setOption(SocketOption,Object) setOption}和{@link# getOption(SocketOption) getOption}方法用于设置和查询套接字选项。这个接口的实现应该说明它支持的套接字选项。

 

The {@link #bind bind} and {@link #setOption setOption} methods that do not otherwise have a value to return are specified to return the network channel upon which they are invoked. This allows method invocations to be chained. Implementations of this interface should specialize the return type so that method invocations on the implementation class can be chained.

没有返回值的{@link #bind}和{@link #setOption}方法被指定为返回调用它们的网络通道。这允许方法调用被链接。该接口的实现应该专门化返回类型,以便可以链接对实现类的方法调用。

 

我的疑问:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值