socket()函数调用的有效返回值是0还是1

Ala*_*n H 16 c unix sockets

套接字函数调用C可以返回0或1作为套接字描述符的值吗?

   int socket(int domain, int type, int protocol);
Run Code Online (Sandbox Code Playgroud)

根据我的手册页:

RETURN VALUE
   -1 is returned if an error occurs; otherwise the  return  value  is  a
   descriptor referencing the socket.
Run Code Online (Sandbox Code Playgroud)

它似乎可以,或者至少手册页没有提到任何保留值.是否在其他地方写入了有效套接字描述符需要为2或更大?

我专门在linux 2.4.22内核上运行,但我很想知道任何基于unix的socket实现.

小智 17

0和1都是有效的返回值,如果应用程序已关闭其标准输入或输出文件描述符,则可能确实返回.