U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » SIGPIPE problem
Re: SIGPIPE problem [message #57120 is a reply to message #57108] Thu, 27 May 2021 09:14 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
zsolt wrote on Wed, 26 May 2021 05:19
I'm writing an HTTP App server currently and I'm using some libraries, such as libpq.
My problem is, that some of the libraries are switching SIGPIPE signal handler on and off, and I have no control over that.
So when a client disconnects while my server is sending the HTTP response, sometimes it gets a SIGPIPE and my app stops at that point in debugger.
I'm running tons of unit tests so this is not very convenient, as some tests are doing this.

I fixed this by changing the flags argument of send() from 0 to MSG_NOSIGNAL in TcpSocket::RawSend() method.

Do you have any better idea?

 int TcpSocket::RawSend(const void *buf, int amount)
 {
+#ifdef PLATFORM_POSIX
+	int res = send(socket, (const char *)buf, amount, MSG_NOSIGNAL);
+#else
 	int res = send(socket, (const char *)buf, amount, 0);
+#endif
 	if(res < 0 && WouldBlock())
 		res = 0;
 	else
 	if(res == 0 || res < 0)
 		SetSockError("send");
 	return res;
 }


Sounds good, applied, thank you.

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Small optimization
Next Topic: MSVS15x64: Compile Error C3256 C3259 C3250 in Fn.h findarg
Goto Forum:
  


Current Time: Sat Sep 05 15:04:45 GMT+2 2026

Total time taken to generate the page: 0.00811 seconds