Class
FileHandle
An object-oriented wrapper for a file descriptor.
--文件描述符的面向对象的包装者
--所以文件句柄就是对文件描述符的包装者
Declaration
class FileHandle : NSObject
Overview --概览
You use file handle objects to access data associated with files, sockets, pipes, and devices. For files, you can read, write, and seek within the file. For sockets, pipes, and devices, you can use a file handle object to monitor the device and process data asynchronously.
--您可以使用文件句柄对象来访问与文件、套接字、管道和设备相关联的数据。 对于文件,您可以在文件中读取、写入和查找。 对于套接字、管道和设备,您可以使用文件句柄对象来异步监视设备和处理数据。
Most creation methods for FileHandle
cause the file handle object to take ownership of the associated file descriptor. This means that the file handle object both creates the file descriptor and is responsible for closing it later, usually when the file handle object itself is deallocated. If you want to use a file handle object with a file descriptor that you created, use the init(fileDescriptor:)
method or use the init(fileDescriptor:closeOnDealloc:)
method and pass false
for the flag
parameter.
--FileHandle的大多数创建方法都会导致文件句柄对象取得相关文件描述符的所有权。 这意味着文件句柄对象既创建文件描述符,又负责稍后关闭它,通常是在文件句柄对象本身被释放时。 如果要将文件句柄对象与您创建的文件描述符一起使用,请使用init(fileDescriptor:)方法或使用init(fileDescriptor:closeOnDealloc:)方法并为flag参数传递false。
Run Loop Considerations --运行循环时的考虑事项
When using a file handle object to communicate asynchronously with a socket, you must initiate the corresponding operations from a thread with an active run loop. Although the read, accept, and wait operations themselves are performed asynchronously on background threads, the file handle uses a run loop source to monitor the operations and notify your code appropriately. Therefore, you must call those methods from your application’s main thread or from any thread where you have configured a run loop and are using it to process events.
--使用文件句柄对象与套接字异步通信时,必须从具有活动Run循环的线程启动相应的操作。 尽管读取、接受和等待操作本身在后台线程上异步执行,但文件句柄使用Run循环源来监视操作并适当地通知您的代码。 因此,您必须从 应用程序的主线程 或 已配置Run循环的(并使用它来处理事件的)线程中 调用这些方法。
For more information about configuring and using run loops, see Threading Programming Guide.
--有关配置和使用运行循环的更多信息,请参见