Bad file descriptor with BSD socket?

Your program prints "Bad file descriptor" when errno is EBADF. From man page of send: EBADF = An invalid descriptor was specified I'm quite sure that the socket is closed before the send() call. That can happen, because program can go to "ready for writing" branch after "connection closed," branch Try the following: else if(numRead == 0) { printf("\nClosing socket"); close(comm_fd); break; } Instead of: else if(numRead == 0) { printf("\nClosing socket"); close(comm_fd); done = true; }.

Your program prints "Bad file descriptor" when errno is EBADF. From man page of send: EBADF = An invalid descriptor was specified. I'm quite sure that the socket is closed before the send() call.

That can happen, because program can go to "ready for writing" branch after "connection closed," branch. Try the following: else if(numRead == 0) { printf("\nClosing socket"); close(comm_fd); break; } Instead of: else if(numRead == 0) { printf("\nClosing socket"); close(comm_fd); done = true; }.

I have that in the code, ctrl f 'if connection closed' – Sterling Aug 19 at 13:43 Yes, but your code needs "break". I updated my answer, so it is easier to see the proposed change. – User1 Aug 19 at 14:00 That didn't change anything.

Why would it? To be more clear, the error is occurring at the start of my program. I have messages that are sent every 0.2 seconds and after it sends the first message, it gives me the error.

– Sterling Aug 19 at 14:21 As you can see the code can call send() after close(). If it didn't fix the problem, then there is an another problem too. – User1 Aug 19 at 14:27 I'm not positive about why this worked, but if I initialize numSent and numRead to 0 I don't get the error anymore.

I guess it was just getting to the if statement before they were initialized to anything? – Sterling Aug 19 at 14:53.

You answered your own question. Without explicitly initializing numSent and numRead, you get garbage, which may happen to be a negative number for numSent, which would cause it to error if there was no digit in the out array.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions