当我使用 accept() 创建套接字并使用 fdopen() 从中创建一个 FILE 时,我需要做什么来清理所有内容?我需要在文件上执行 fclose(),在套接字上执行 shutdown() 和 close(),还是只需要执行 shutdown() 和/或 close() 或 fclose()?如果我不执行 fclose(),我是否必须手动 free() FILE 指针?
最佳答案
来自 man fdopen:
The file descriptor is not dup’ed, and will be closed when the stream created by fdopen() is closed
所以我只使用 fclose(),它也会关闭底层文件描述符。我也不知道是否需要 shutdown()。
关于关闭/清理 "mixed"文件描述符/套接字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/108043/