Index: /pjproject/trunk/pjlib/include/pj/sock.h
===================================================================
--- /pjproject/trunk/pjlib/include/pj/sock.h	(revision 3477)
+++ /pjproject/trunk/pjlib/include/pj/sock.h	(revision 3478)
@@ -298,4 +298,7 @@
 extern const pj_uint16_t PJ_SO_REUSEADDR;
 
+/** Do not generate SIGPIPE. @see pj_SO_NOSIGPIPE */
+extern const pj_uint16_t PJ_SO_NOSIGPIPE;
+
 /** Set the protocol-defined priority for all packets to be sent on socket.
  */
@@ -334,4 +337,7 @@
     PJ_DECL(pj_uint16_t) pj_SO_REUSEADDR(void);
 
+    /** Get #PJ_SO_NOSIGPIPE constant */
+    PJ_DECL(pj_uint16_t) pj_SO_NOSIGPIPE(void);
+
     /** Get #PJ_SO_PRIORITY constant */
     PJ_DECL(pj_uint16_t) pj_SO_PRIORITY(void);
@@ -366,4 +372,7 @@
     /** Get #PJ_SO_REUSEADDR constant */
 #   define pj_SO_REUSEADDR() PJ_SO_REUSEADDR
+
+    /** Get #PJ_SO_NOSIGPIPE constant */
+#   define pj_SO_NOSIGPIPE() PJ_SO_NOSIGPIPE
 
     /** Get #PJ_SO_PRIORITY constant */
Index: /pjproject/trunk/pjlib/src/pj/sock_bsd.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_bsd.c	(revision 3477)
+++ /pjproject/trunk/pjlib/src/pj/sock_bsd.c	(revision 3478)
@@ -136,4 +136,9 @@
 const pj_uint16_t PJ_TCP_NODELAY= TCP_NODELAY;
 const pj_uint16_t PJ_SO_REUSEADDR= SO_REUSEADDR;
+#ifdef SO_NOSIGPIPE
+const pj_uint16_t PJ_SO_NOSIGPIPE = SO_NOSIGPIPE;
+#else
+const pj_uint16_t PJ_SO_NOSIGPIPE = 0xFFFF;
+#endif
 #if defined(SO_PRIORITY)
 const pj_uint16_t PJ_SO_PRIORITY = SO_PRIORITY;
Index: /pjproject/trunk/pjlib/src/pj/sock_common.c
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_common.c	(revision 3477)
+++ /pjproject/trunk/pjlib/src/pj/sock_common.c	(revision 3478)
@@ -1138,4 +1138,9 @@
 }
 
+PJ_DEF(pj_uint16_t) pj_SO_NOSIGPIPE(void)
+{
+    return PJ_SO_NOSIGPIPE;
+}
+
 PJ_DEF(pj_uint16_t) pj_SO_PRIORITY(void)
 {
Index: /pjproject/trunk/pjlib/src/pj/sock_symbian.cpp
===================================================================
--- /pjproject/trunk/pjlib/src/pj/sock_symbian.cpp	(revision 3477)
+++ /pjproject/trunk/pjlib/src/pj/sock_symbian.cpp	(revision 3478)
@@ -54,4 +54,5 @@
 const pj_uint16_t PJ_SOL_UDP	= 0xFFFF;
 const pj_uint16_t PJ_SOL_IPV6	= 0xFFFF;
+const pj_uint16_t PJ_SO_NOSIGPIPE = 0xFFFF;
 
 /* TOS */
Index: /pjproject/trunk/pjsip-apps/src/pjsua/main.c
===================================================================
--- /pjproject/trunk/pjsip-apps/src/pjsua/main.c	(revision 3477)
+++ /pjproject/trunk/pjsip-apps/src/pjsua/main.c	(revision 3478)
@@ -67,8 +67,18 @@
 }
 
+static void setup_socket_signal()
+{
+}
+
 #else
+#include <signal.h>
 
 static void setup_signal_handler(void)
 {
+}
+
+static void setup_socket_signal()
+{
+    signal(SIGPIPE, SIG_IGN);
 }
 
@@ -77,4 +87,6 @@
 int main(int argc, char *argv[])
 {
+    setup_socket_signal();
+
     do {
 	app_restart = PJ_FALSE;
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c	(revision 3477)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_tcp.c	(revision 3478)
@@ -545,4 +545,5 @@
     pj_activesock_cb tcp_callback;
     const pj_str_t ka_pkt = PJSIP_TCP_KEEP_ALIVE_DATA;
+    pj_int32_t val = 1;
     pj_status_t status;
     
@@ -632,4 +633,8 @@
     pj_ioqueue_op_key_init(&tcp->ka_op_key.key, sizeof(pj_ioqueue_op_key_t));
     pj_strdup(tcp->base.pool, &tcp->ka_pkt, &ka_pkt);
+    
+    /* Prevent SIGPIPE */
+    pj_sock_setsockopt(tcp->sock, pj_SOL_SOCKET(), pj_SO_NOSIGPIPE(),
+		       &val, sizeof(val));
 
     /* Done setting up basic transport. */
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c	(revision 3477)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls.c	(revision 3478)
@@ -528,4 +528,5 @@
     struct tls_transport *tls;
     const pj_str_t ka_pkt = PJSIP_TLS_KEEP_ALIVE_DATA;
+    pj_int32_t val = 1;
     pj_status_t status;
     
@@ -617,4 +618,8 @@
     pj_strdup(tls->base.pool, &tls->ka_pkt, &ka_pkt);
 
+    /* Prevent SIGPIPE */
+    pj_sock_setsockopt(tcp->sock, pj_SOL_SOCKET(), pj_SO_NOSIGPIPE(),
+		       &val, sizeof(val));
+    
     /* Done setting up basic transport. */
     *p_tls = tls;
Index: /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls_ossl.c
===================================================================
--- /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls_ossl.c	(revision 3477)
+++ /pjproject/trunk/pjsip/src/pjsip/sip_transport_tls_ossl.c	(revision 3478)
@@ -1230,4 +1230,5 @@
     pj_ioqueue_callback tls_callback;
     int rc;
+    pj_int32_t val = 1;
     pj_status_t status;
     
@@ -1332,4 +1333,8 @@
     tls->ka_timer.user_data = (void*) tls;
     tls->ka_timer.cb = &tls_keep_alive_timer;
+
+    /* Prevent SIGPIPE */
+    pj_sock_setsockopt(tcp->sock, pj_SOL_SOCKET(), pj_SO_NOSIGPIPE(),
+		       &val, sizeof(val));
 
 
