in reply to Could not create socket: Bad file number
To narrow down on the issue, I would run the program under strace to figure out which system call is actually failing...
On my machine (where your (slightly adapted) code does work), the last lines I get are
... socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 3 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa99308) = -1 EINVAL (Inval +id argument) _llseek(3, 0, 0xbfa99350, SEEK_CUR) = -1 ESPIPE (Illegal seek) ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xbfa99308) = -1 EINVAL (Inval +id argument) _llseek(3, 0, 0xbfa99350, SEEK_CUR) = -1 ESPIPE (Illegal seek) fcntl64(3, F_SETFD, FD_CLOEXEC) = 0 setsockopt(3, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0 bind(3, {sa_family=AF_INET, sin_port=htons(7070), sin_addr=inet_addr(" +0.0.0.0")}, 16) = 0 listen(3, 1) = 0 accept(3,
It could be one of fcntl, setsockopt, bind or listen failing (all may potentially set EBADF). Then, depending on which one it is, look in the respective man page. If you're lucky, you might find something resembling an explanation...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Could not create socket: Bad file number
by perlofwisdom (Pilgrim) on Aug 30, 2007 at 23:27 UTC | |
by almut (Canon) on Aug 30, 2007 at 23:44 UTC |