SIGPIPE问题

news/2024/5/17 15:14:02 标签: signal, 服务器, socket, tcp
转自 http://blog.chinaunix.net/space.php?uid=14966892&do=blog&id=2780358 

服务端关闭已连接客户端,客户端接着发数据产生问题,
   1. 当服务器close一个连接时,若client端接着发数据。根据TCP协议的规定,会收到一个RST响应,client再往这个服务器发送数据时,系统会发出一个SIGPIPE信号给进程,告诉进程这个连接已经断开了,不要再写了。
    根据信号的默认处理规则SIGPIPE信号的默认执行动作是terminate(终止、退出),所以client会退出。若不想客户端退出可以把SIGPIPE设为SIG_IGN
    如:    signal(SIGPIPE,SIG_IGN);
这时SIGPIPE交给了系统处理。
 
   2. 客户端write一个已经被服务器端关闭的sock后,返回的错误信息Broken pipe.
     1)broken pipe的字面意思是“管道破裂”。broken pipe的原因是该管道的读端被关闭。
     2)broken pipe经常发生socket关闭之后(或者其他的描述符关闭之后)的write操作中
   3)发生broken pipe错误时,进程收到SIGPIPE信号,默认动作是进程终止。
     4)broken pipe最直接的意思是:写入端出现的时候,另一端却休息或退出了,
       因此造成没有及时取走管道中的数据,从而系统异常退出;
 
 
 
  服务器采用了fork的话,要收集垃圾进程,防止僵尸进程的产生,可以这样处理:
          signal(SIGCHLD,SIG_IGN); 交给系统init去回收。
   这里子进程就不会产生僵尸进程了。

http://www.niftyadmin.cn/n/518977.html

相关文章

webrtc-m79-VideoSink的设置

1 首先来看一下 VideoTrackInterface 接口的定义 class RTC_EXPORT VideoTrackInterface: public MediaStreamTrackInterface,public rtc::VideoSourceInterface<VideoFrame> {public:// Video track content hint, used to override the source is_screencast// proper…

strftime说明

转自http://www.cnblogs.com/caolisong/archive/2007/04/11/709732.html 我们可以使用strftime&#xff08;&#xff09;函数将时间格式化为我们想要的格式。它的原型如下&#xff1a; size_t strftime(char *strDest,size_t maxsize,const char *format,const struct tm *tim…

webrtc-m79-rtc::VideoSourceInterface<webrtc::VideoFrame>类图

1 rtc::VideoSourceInterface<webrtc::VideoFrame>类图

*** glibc detected *** mainwindow: malloc(): smallbin double linked list corrupted: 0x01a73ab8 ***

1.先看看在glibc malloc的实现机制 /* This struct declaration is misleading (but accurate and necessary). It declares a "view" into memory allowing access to necessary fields at known offsets from a given base. See explanation below. */ st…

webrtc-m79-VideoSinkInterface类图

1 定义 namespace rtc {template <typename VideoFrameT> class VideoSinkInterface {public:virtual ~VideoSinkInterface() default;virtual void OnFrame(const VideoFrameT& frame) 0;// Should be called by the source when it discards the frame due to r…

webrtc-m79-VideoRtpReceiver::SetStreams的设置逻辑

1 相关代码 RTCError PeerConnection::ApplyRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) { >if (IsUnifiedPlan()) {std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>now_receiving_transceivers;std::vector<r…