Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--acconfig.h1
-rw-r--r--configure.in15
-rw-r--r--mono/io-layer/ChangeLog5
-rw-r--r--mono/io-layer/daemon-messages.c44
-rw-r--r--mono/io-layer/sockets.c35
6 files changed, 95 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 000358c1324..36cda3bdf3c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2002-06-10 Jaroslaw Kowalski <jarek@atm.com.pl>
+
+ * configure.in: added checks for MSG_NOSIGNAL
+
2002-05-30 Daniel Morgan <danmorg@sc.rr.com>
* doc/ado-net: update the ado-net web page on go-mono.com
diff --git a/acconfig.h b/acconfig.h
index 1ba6021b489..8f559030546 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -1,5 +1,6 @@
#undef HAVE_INET_PTON
#undef HAVE_INET_ATON
+#undef HAVE_MSG_NOSIGNAL
#undef HAVE_SOL_IP
#undef HAVE_SOL_TCP
#undef HAVE_IP_PKTINFO
diff --git a/configure.in b/configure.in
index 00ce947ada1..a82c6749548 100644
--- a/configure.in
+++ b/configure.in
@@ -183,6 +183,21 @@ if test x$platform_win32 = xno; then
dnl *****************************
AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket")
+ dnl *******************************
+ dnl *** Checks for MSG_NOSIGNAL ***
+ dnl *******************************
+ AC_MSG_CHECKING(for MSG_NOSIGNAL)
+ AC_TRY_COMPILE([#include <sys/socket.h>], [
+ int f = MSG_NOSIGNAL;
+ ], [
+ # Yes, we have it...
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_MSG_NOSIGNAL)
+ ], [
+ # We'll have to use signals
+ AC_MSG_RESULT(no)
+ ])
+
dnl *****************************
dnl *** Checks for SOL_IP ***
dnl *****************************
diff --git a/mono/io-layer/ChangeLog b/mono/io-layer/ChangeLog
index 71c89635535..6215e3a8420 100644
--- a/mono/io-layer/ChangeLog
+++ b/mono/io-layer/ChangeLog
@@ -1,3 +1,8 @@
+2002-06-10 Jaroslaw Kowalski <jarek@atm.com.pl>
+
+ * sockets.c, daemon-messages.c: Prevent SIGPIPE from being raised
+ when writing to a closed socket.
+
2002-06-08 Jeffrey Stedfast <fejj@ximian.com>
* mono-mutex.c (mono_once): New convenience function for my
diff --git a/mono/io-layer/daemon-messages.c b/mono/io-layer/daemon-messages.c
index 20da788364c..ab5690d4772 100644
--- a/mono/io-layer/daemon-messages.c
+++ b/mono/io-layer/daemon-messages.c
@@ -13,16 +13,13 @@
#include <errno.h>
#include <string.h>
+#ifndef HAVE_MSG_NOSIGNAL
+#include <signal.h>
+#endif
+
#include <mono/io-layer/wapi.h>
#include <mono/io-layer/daemon-messages.h>
-/*
- * Since this is not portable, it's probably better to just ignore sigpipe.
- */
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-
/* Send request on fd, wait for response (called by applications, not
* the daemon)
*/
@@ -31,14 +28,22 @@ void _wapi_daemon_request_response (int fd, WapiHandleRequest *req,
{
static pthread_mutex_t req_mutex=PTHREAD_MUTEX_INITIALIZER;
int ret;
-
+#ifndef HAVE_MSG_NOSIGNAL
+ void (*old_sigpipe)(int);
+#endif
+
/* Serialise requests to the daemon from the same process. We
* rely on request turnaround time being minimal anyway, so
* performance shouldnt suffer from the mutex.
*/
pthread_mutex_lock (&req_mutex);
+#ifdef HAVE_MSG_NOSIGNAL
ret=send (fd, req, sizeof(WapiHandleRequest), MSG_NOSIGNAL);
+#else
+ old_sigpipe = signal (SIGPIPE, SIG_IGN);
+ ret=send (fd, req, sizeof(WapiHandleRequest), 0);
+#endif
if(ret!=sizeof(WapiHandleRequest)) {
if(errno==EPIPE) {
g_warning (G_GNUC_PRETTY_FUNCTION ": The handle daemon vanished!");
@@ -50,7 +55,12 @@ void _wapi_daemon_request_response (int fd, WapiHandleRequest *req,
}
}
+#ifdef HAVE_MSG_NOSIGNAL
ret=recv (fd, resp, sizeof(WapiHandleResponse), MSG_NOSIGNAL);
+#else
+ ret=recv (fd, resp, sizeof(WapiHandleResponse), 0);
+ signal (SIGPIPE, old_sigpipe);
+#endif
if(ret==-1) {
if(errno==EPIPE) {
g_warning (G_GNUC_PRETTY_FUNCTION ": The handle daemon vanished!");
@@ -69,8 +79,17 @@ void _wapi_daemon_request_response (int fd, WapiHandleRequest *req,
void _wapi_daemon_request (int fd, WapiHandleRequest *req)
{
int ret;
+#ifndef HAVE_MSG_NOSIGNAL
+ void (*old_sigpipe)(int);
+#endif
+#ifdef HAVE_MSG_NOSIGNAL
ret=recv (fd, req, sizeof(WapiHandleRequest), MSG_NOSIGNAL);
+#else
+ old_sigpipe = signal (SIGPIPE, SIG_IGN);
+ ret=recv (fd, req, sizeof(WapiHandleRequest), 0);
+ signal (SIGPIPE, old_sigpipe);
+#endif
if(ret==-1) {
#ifdef DEBUG
g_warning (G_GNUC_PRETTY_FUNCTION ": Recv error: %s",
@@ -84,8 +103,17 @@ void _wapi_daemon_request (int fd, WapiHandleRequest *req)
void _wapi_daemon_response (int fd, WapiHandleResponse *resp)
{
int ret;
+#ifndef HAVE_MSG_NOSIGNAL
+ void (*old_sigpipe)(int);
+#endif
+#ifdef HAVE_MSG_NOSIGNAL
ret=send (fd, resp, sizeof(WapiHandleResponse), MSG_NOSIGNAL);
+#else
+ old_sigpipe = signal (SIGPIPE, SIG_IGN);
+ ret=send (fd, resp, sizeof(WapiHandleResponse), 0);
+ signal (SIGPIPE, old_sigpipe);
+#endif
if(ret==-1) {
#ifdef DEBUG
g_warning (G_GNUC_PRETTY_FUNCTION ": Send error: %s",
diff --git a/mono/io-layer/sockets.c b/mono/io-layer/sockets.c
index fc5e7f708bb..81ef793cb15 100644
--- a/mono/io-layer/sockets.c
+++ b/mono/io-layer/sockets.c
@@ -23,6 +23,10 @@
#endif
#include <unistd.h>
+#ifndef HAVE_MSG_NOSIGNAL
+#include <signal.h>
+#endif
+
#include <mono/io-layer/wapi.h>
#include <mono/io-layer/wapi-private.h>
#include <mono/io-layer/socket-private.h>
@@ -657,6 +661,9 @@ int _wapi_recv(guint32 handle, void *buf, size_t len, int recv_flags)
int _wapi_recvfrom(guint32 handle, void *buf, size_t len, int recv_flags,
struct sockaddr *from, socklen_t *fromlen)
{
+#ifndef HAVE_MSG_NOSIGNAL
+ void (*old_sigpipe)(int); // old SIGPIPE handler
+#endif
struct _WapiHandlePrivate_socket *socket_private_handle;
gboolean ok;
int ret;
@@ -675,8 +682,16 @@ int _wapi_recvfrom(guint32 handle, void *buf, size_t len, int recv_flags,
return(SOCKET_ERROR);
}
+#ifdef HAVE_MSG_NOSIGNAL
+ ret=recvfrom(socket_private_handle->fd, buf, len, recv_flags | MSG_NOSIGNAL, from,
+ fromlen);
+#else
+ old_sigpipe = signal(SIGPIPE, SIG_IGN);
ret=recvfrom(socket_private_handle->fd, buf, len, recv_flags, from,
fromlen);
+ signal(SIGPIPE, old_sigpipe);
+#endif
+
if(ret==-1) {
#ifdef DEBUG
g_message(G_GNUC_PRETTY_FUNCTION ": recv error: %s",
@@ -719,6 +734,9 @@ int _wapi_recvfrom(guint32 handle, void *buf, size_t len, int recv_flags,
int _wapi_send(guint32 handle, const void *msg, size_t len, int send_flags)
{
+#ifndef HAVE_MSG_NOSIGNAL
+ void (*old_sigpipe)(int); // old SIGPIPE handler
+#endif
struct _WapiHandlePrivate_socket *socket_private_handle;
gboolean ok;
int ret;
@@ -736,8 +754,14 @@ int _wapi_send(guint32 handle, const void *msg, size_t len, int send_flags)
WSASetLastError(WSAENOTSOCK);
return(SOCKET_ERROR);
}
-
+
+#ifdef HAVE_MSG_NOSIGNAL
+ ret=send(socket_private_handle->fd, msg, len, send_flags | MSG_NOSIGNAL);
+#else
+ old_sigpipe = signal(SIGPIPE, SIG_IGN);
ret=send(socket_private_handle->fd, msg, len, send_flags);
+ signal(SIGPIPE, old_sigpipe);
+#endif
if(ret==-1) {
#ifdef DEBUG
g_message(G_GNUC_PRETTY_FUNCTION ": send error: %s",
@@ -787,6 +811,9 @@ int _wapi_send(guint32 handle, const void *msg, size_t len, int send_flags)
int _wapi_sendto(guint32 handle, const void *msg, size_t len, int send_flags,
const struct sockaddr *to, socklen_t tolen)
{
+#ifndef HAVE_MSG_NOSIGNAL
+ void (*old_sigpipe)(int); // old SIGPIPE handler
+#endif
struct _WapiHandlePrivate_socket *socket_private_handle;
gboolean ok;
int ret;
@@ -805,7 +832,13 @@ int _wapi_sendto(guint32 handle, const void *msg, size_t len, int send_flags,
return(SOCKET_ERROR);
}
+#ifdef HAVE_MSG_NOSIGNAL
+ ret=sendto(socket_private_handle->fd, msg, len, send_flags | MSG_NOSIGNAL, to, tolen);
+#else
+ old_sigpipe = signal(SIGPIPE, SIG_IGN);
ret=sendto(socket_private_handle->fd, msg, len, send_flags, to, tolen);
+ signal(SIGPIPE, old_sigpipe);
+#endif
if(ret==-1) {
#ifdef DEBUG
g_message(G_GNUC_PRETTY_FUNCTION ": send error: %s",