Unix socket bad file descriptor




















On Mac though, both the shutdown and if I comment it out the close functions give me "Bad file descriptor" errors. Up until I call this code, the sockets work fine. But as soon as I call shutdown or close, I get the error. Any ideas what could be going on? This is often because of a double-close bug in some completely unrelated section of the program.

Such a bug can be contagious. If your program closes the same descriptor twice, and it gets re-assigned in the interim, the second close will close some unrelated object's descriptor out from under them. And then when that object closes its descriptor, it can actually be closing yet another object's descriptor And so on, until the last one in line gets a "bad file descriptor" error.

The only way I know to debug this is to monitor the creation and destruction of all file descriptors using a tool like strace on Linux or dtrace on Mac. Well, maybe not the only way. If you are concerned about leaking descriptors, use a tool like valgrind to analyze your program. I had the same issue: on windows everything was ok, and on linux, an exception got thrown depending on the socket state IIRC.

See the close and shutdown overloads in the asio documentation. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.

Learn more. Bad file descriptor closing Boost socket Ask Question. Asked 10 years, 3 months ago. Active 10 years, 3 months ago. Viewed 7k times. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Asked 7 years, 11 months ago. Active 7 years, 11 months ago. Viewed 11k times. I'm trying to write a game that will let multiple clients connect and play - below is the relevant code it's very messy - cleaning up later : Edit: I realized it's a lot of scrolling Improve this question. MrDuk MrDuk If it shows accept: Bad file descriptor , How can "crash" be at close client.

It surely means problem at accept. You're right, sorry - I'm super new to this, and haven't yet figured out how to debug effectively under gdb -- however, accept: should have given it away I suppose.. Add a comment. Active Oldest Votes. Improve this answer. Community Bot 1 1 1 silver badge. When you come across a new error, you try to detect where that error appeared from. Eventually, you start researching how to rectify the mistake. There are even high chances of you exploring more and achieving various easier ways to apply the code better.

At last, you will end up observing that your skills in the concept and knowledge about the same had grown vast. Errors ought to occur in any possible programming language. In Python, errors generally occur when a particular code segment is not in compliance with the advised usage.

Various errors are commonly faced by programmers, which include indentation, syntax, etc. Rectifying these errors is no big deal when you review your code thoroughly. Have a complete understanding of the concepts and know enough about the right syntax to be used in the code. They are generally non-negative values. They assist in performing various functions related to files.

Descriptors, in general, are a unique way that Python follows to manage attributes. Have you encountered the following error message when you run your Python code when defining file directories or similar ones? In the above code, the del file will delete the reference of the file object specified.

Now, as per the code written, the close function was not called.



0コメント

  • 1000 / 1000