MGlobal
asked on
Socket Descriptor return value
Hi All,
I have a question that, Socket function may return a value 0 when it creates socket successful?
socket function:
SOCKET socket( int af, int type, int protocol );
Thanks in advandce.
Regards,
MGlobal
I have a question that, Socket function may return a value 0 when it creates socket successful?
socket function:
SOCKET socket( int af, int type, int protocol );
Thanks in advandce.
Regards,
MGlobal
ASKER
Hi bass20,
I am using Windows. How about the return value? All documenst I have read, they only check error when it is -1. But by testing, I found that in Windows, it never returns 0 (if successful). But I am not sure socket() realy always returns > 0 (if successful). This is importance for me, because I have a program (written by other person), there will be a bug in that program, if socket() can return 0 in case successful.
Thanks,
MGlobal
I am using Windows. How about the return value? All documenst I have read, they only check error when it is -1. But by testing, I found that in Windows, it never returns 0 (if successful). But I am not sure socket() realy always returns > 0 (if successful). This is importance for me, because I have a program (written by other person), there will be a bug in that program, if socket() can return 0 in case successful.
Thanks,
MGlobal
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank bass20.
MGlobal
MGlobal
You can test it's result like this:
int mySock=0;
if( (mySock=socket(...))<0 ) //there's an error
perror("socket");
//if it doesn't produce an error, mySock will have the value of the recently created file descriptor
Hope I helped :)