开发者

Segmentation fault on recv()

I am writing client/server programs on Unix in C, using send/recv. I am occasionally getting a segmentation fault from a recv call. The behavior is not perfectly reproducible; sometimes it happens, and sometimes the program runs to c开发者_如何学Pythonompletion.

Any ideas what this could mean?


If the segmentation fault is in the recv() call itself, then that implies that the buffer you passed to recv() is not properly allocated or is not the size that you told recv() it was.


Well, it usually means you're receiving more data than your buffer has allowed for.

For example, if you malloc 20 bytes and recv 1000 bytes, you'll run into this problem.

Unfortunately, without seeing the code, and without some very rapid advances in the field of psychic debugging, we'll never know for sure *a.


*a That's a subtle hint to post the code, by the way :-)


This could also mean that the socket on the other side is closed before you write to it. That is a SIGPIPE that may be causing your application to close.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜