Re: Checking for closed/broken connections

Rajko Albrecht <[email protected]>
Newsgroups gmane.mail.libetpan.user
Message-ID <[email protected]>
Appended a patch for the mailsockets:

It replaces the calls to write/read with send/recv. So it is possible to set 
the MSG_NOSIGNAL flag to tcp/ip communication. That means, no SIGPIPE appears 
when something goes wrong with the socket.

When connection is broken so it will just return -1.

Bye

Alwin
mailstream_socket.patch (text/x-diff, 960 B)
Index: tools/mailstream_socket.c
===================================================================
RCS file: /cvsroot/libetpan/libetpan/tools/mailstream_socket.c,v
retrieving revision 1.13
diff -u -d -r1.13 mailstream_socket.c
--- tools/mailstream_socket.c	2 Mar 2004 23:54:17 -0000	1.13
+++ tools/mailstream_socket.c	11 Mar 2004 12:30:02 -0000
@@ -44,6 +44,7 @@
 */
 #include <sys/time.h>
 #include <sys/types.h>
+#include <sys/socket.h>
 #include <unistd.h>
 #include <sys/select.h>
 
@@ -176,8 +177,8 @@
     if (!FD_ISSET(socket_data->fd, &fds_read))
       return 0;
   }
-  
-  return read(socket_data->fd, buf, count);
+ 
+  return recv(socket_data->fd,buf,count,MSG_NOSIGNAL);
 }
 
 static ssize_t mailstream_low_socket_write(mailstream_low * s,
@@ -207,8 +208,7 @@
     if (!FD_ISSET(socket_data->fd, &fds_write))
       return 0;
   }
-  
-  return write(socket_data->fd, buf, count);
+  return send(socket_data->fd,buf,count,MSG_NOSIGNAL);
 }
signature.asc (application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQBAUGJDPn3zffsdiJYRAgJaAJ9Z9v82Ur62YKf4fsNCU90mA9hkCgCeI90s
IBxGKkSMdC5E/a05Xk8wyHM=
=zv/i
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.