fix: should check the value range of passed fd argument.
change: loop argument check redundant code has been refactored.