nmbd.c open_sockets() have wonder initialization.
Kenichi Okuyama
okuyama at trl.ibm.co.jp
Thu Nov 9 02:34:49 GMT 2000
Dear Michael,
>>>>> "MJT" == Michael Ju Tokarev <mjt at tls.msk.ru> writes:
>>
>> Dear all,
>>
MJT> []
>> + if ( ClientNMB == -1 ) {
MJT> []
>> + if ( ClientDGRAM == -1 ) {
MJT> []
MJT> I was always curious in such places -- why to check with -1?
1) because I didn't want to change meaning of function too much.
Original code also checked validness using comparison with -1.
2) Now, file descriptor with invalid value is -1.
So, we know that any number < 0 is invalid file descriptor.
BUT! who knows. Someone might wish to add new value less than
0 for some other meaning.
3) And even among all above, I agree with you.
Yes, your suggestion is right. comparing like:
MJT> if ( fd < 0 ) {
is more robust code.
Usually it's not that fast, for -1 is usually equivalent to
(~0), so if you have smart compiler,
if ( fd == -1 ) {
will be translated to
if ( (~fd) == 0 ) {
which now a day CPU can treat very fast. So, speed is not so
important here.
If POSIX or anything coming in future have "compatibility"
in their mind, file descriptor with negative number will be
anything of invalid, though it might not be simply invalid file
descriptor. So your code is more robust.
For typing ...well I've already typed it , so never mind about
that.
# using shorter name for variable is lot more effective for
# typing, you know(^o^)
best regards,
----
Kenichi Okuyama at Tokyo Research Lab. IBM-Japan, Co.
More information about the samba-technical
mailing list