Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我创建一个套接字
sockfd = socket(...);
然后我通过调用将它关联到 FILE 流
FILE* f=fdopen(sockfd,"r+");
我应该同时调用close(sockfd);andfclose(f);还是只调用close(sockfd);?如果我打电话或不打电话,文件结构会发生什么fclose(f)?
close(sockfd);
fclose(f);
fclose(f)
并且(最重要的),如果我应该同时调用它们,它们必须按什么顺序调用?首先close()还是fclose()?
close()
fclose()
fdopen()将文件描述符包装到缓冲的 ioFILE结构中,就像您使用fopen().
fdopen()
FILE
fopen()
您应该只调用fclose(),这将关闭 os 文件描述符并释放所有关联的结构和缓冲区!