Bad File Descriptor

The file descriptor passed to a syscall was out of range, or was not open, or is invalid for the function requested.

This is usually a programming bug, you forgot to call open(2), or socket(2), or something or they returned an error. Check to see if the file descriptor is -1, if it is, then you should check errno for why it failed. see the man pages for open(2) or socket(2) for more information.