简体   繁体   English

recv()上的分段错误

[英]Segmentation fault on recv()

I am writing client/server programs on Unix in C, using send/recv. 我正在使用send / recv在C语言的Unix上编写客户端/服务器程序。 I am occasionally getting a segmentation fault from a recv call. 我偶尔会从recv调用中获得分段错误。 The behavior is not perfectly reproducible; 这种行为不是完全可重复的; sometimes it happens, and sometimes the program runs to completion. 有时它会发生,有时程序会运行完成。

Any ideas what this could mean? 任何想法可能意味着什么?

如果分段错误在recv()调用本身中,那么这意味着传递给recv()的缓冲区没有正确分配,或者不是你告诉recv()它的大小。

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. 例如,如果你malloc 20字节和recv 1000字节,你将遇到这个问题。

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


*a That's a subtle hint to post the code, by the way :-) * a这是发布代码的微妙提示,顺便说一句:-)

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. 这是一个可能导致您的应用程序关闭的SIGPIPE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM