X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fio-layer%2Fsockets.c;h=aaa53ffe16d157b16554960ba51f2ab35c430ab8;hb=3d2ddac37f5d79e00e4eea92645901c1ad2ff31e;hp=c5279448570c77be44ca5c6f15b97ede95151c8e;hpb=e9767791179ef1ab75d97afd8f2ffc0a8db793d2;p=mono.git diff --git a/mono/io-layer/sockets.c b/mono/io-layer/sockets.c index c5279448570..aaa53ffe16d 100644 --- a/mono/io-layer/sockets.c +++ b/mono/io-layer/sockets.c @@ -41,7 +41,10 @@ #include #include #include +#include #include +#include +#include #include #include @@ -53,12 +56,6 @@ #include #endif -#if 0 -#define DEBUG(...) g_message(__VA_ARGS__) -#else -#define DEBUG(...) -#endif - static guint32 in_cleanup = 0; static void socket_close (gpointer handle, gpointer data); @@ -84,7 +81,7 @@ static void socket_close (gpointer handle, gpointer data) int ret; struct _WapiHandle_socket *socket_handle = (struct _WapiHandle_socket *)data; - DEBUG ("%s: closing socket handle %p", __func__, handle); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: closing socket handle %p", __func__, handle); /* Shutdown the socket for reading, to interrupt any potential * receives that may be blocking for data. See bug 75705. @@ -98,7 +95,7 @@ static void socket_close (gpointer handle, gpointer data) if (ret == -1) { gint errnum = errno; - DEBUG ("%s: close error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: close error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); if (!in_cleanup) WSASetLastError (errnum); @@ -117,7 +114,7 @@ cleanup_close (gpointer handle, gpointer data) void _wapi_cleanup_networking(void) { - DEBUG ("%s: cleaning up", __func__); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: cleaning up", __func__); in_cleanup = 1; _wapi_handle_foreach (WAPI_HANDLE_SOCKET, cleanup_close, NULL); @@ -182,7 +179,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen) if (new_fd == -1) { gint errnum = errno; - DEBUG ("%s: accept error: %s", __func__, strerror(errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: accept error: %s", __func__, strerror(errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -191,7 +188,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen) } if (new_fd >= _wapi_fd_reserve) { - DEBUG ("%s: File descriptor is too big", __func__); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big", __func__); WSASetLastError (WSASYSCALLFAILURE); @@ -213,7 +210,7 @@ guint32 _wapi_accept(guint32 fd, struct sockaddr *addr, socklen_t *addrlen) return(INVALID_SOCKET); } - DEBUG ("%s: returning newly accepted socket handle %p with", + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning newly accepted socket handle %p with", __func__, new_handle); return(new_fd); @@ -232,7 +229,7 @@ int _wapi_bind(guint32 fd, struct sockaddr *my_addr, socklen_t addrlen) ret = bind (fd, my_addr, addrlen); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: bind error: %s", __func__, strerror(errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: bind error: %s", __func__, strerror(errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -262,7 +259,7 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr, errnum = errno; if (errno != EINTR) { - DEBUG ("%s: connect error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: connect error: %s", __func__, strerror (errnum)); errnum = errno_to_WSA (errnum, __func__); @@ -300,7 +297,7 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr, if (errno != EINTR) { errnum = errno_to_WSA (errno, __func__); - DEBUG ("%s: connect poll error: %s", + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: connect poll error: %s", __func__, strerror (errno)); WSASetLastError (errnum); @@ -313,7 +310,7 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr, &len) == -1) { errnum = errno_to_WSA (errno, __func__); - DEBUG ("%s: connect getsockopt error: %s", + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: connect getsockopt error: %s", __func__, strerror (errno)); WSASetLastError (errnum); @@ -332,7 +329,7 @@ int _wapi_connect(guint32 fd, const struct sockaddr *serv_addr, socket_handle->saved_error = errnum; } - DEBUG ("%s: connect getsockopt returned error: %s", + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: connect getsockopt returned error: %s", __func__, strerror (so_error)); WSASetLastError (errnum); @@ -356,7 +353,7 @@ int _wapi_getpeername(guint32 fd, struct sockaddr *name, socklen_t *namelen) ret = getpeername (fd, name, namelen); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: getpeername error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: getpeername error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); @@ -381,7 +378,7 @@ int _wapi_getsockname(guint32 fd, struct sockaddr *name, socklen_t *namelen) ret = getsockname (fd, name, namelen); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: getsockname error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: getsockname error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); @@ -418,7 +415,7 @@ int _wapi_getsockopt(guint32 fd, int level, int optname, void *optval, ret = getsockopt (fd, level, optname, tmp_val, optlen); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: getsockopt error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: getsockopt error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); @@ -470,7 +467,7 @@ int _wapi_listen(guint32 fd, int backlog) ret = listen (fd, backlog); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: listen error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: listen error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -533,7 +530,7 @@ int _wapi_recvfrom(guint32 fd, void *buf, size_t len, int recv_flags, if (ret == -1) { gint errnum = errno; - DEBUG ("%s: recv error: %s", __func__, strerror(errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: recv error: %s", __func__, strerror(errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -573,7 +570,7 @@ _wapi_recvmsg(guint32 fd, struct msghdr *msg, int recv_flags) if (ret == -1) { gint errnum = errno; - DEBUG ("%s: recvmsg error: %s", __func__, strerror(errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: recvmsg error: %s", __func__, strerror(errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -600,7 +597,7 @@ int _wapi_send(guint32 fd, const void *msg, size_t len, int send_flags) if (ret == -1) { gint errnum = errno; - DEBUG ("%s: send error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: send error: %s", __func__, strerror (errno)); #ifdef O_NONBLOCK /* At least linux returns EAGAIN/EWOULDBLOCK when the timeout has been set on @@ -637,7 +634,7 @@ int _wapi_sendto(guint32 fd, const void *msg, size_t len, int send_flags, if (ret == -1) { gint errnum = errno; - DEBUG ("%s: send error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: send error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -665,7 +662,7 @@ _wapi_sendmsg(guint32 fd, const struct msghdr *msg, int send_flags) if (ret == -1) { gint errnum = errno; - DEBUG ("%s: sendmsg error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: sendmsg error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -718,7 +715,7 @@ int _wapi_setsockopt(guint32 fd, int level, int optname, ret = setsockopt (fd, level, optname, tmp_val, optlen); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: setsockopt error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: setsockopt error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); @@ -772,7 +769,7 @@ int _wapi_shutdown(guint32 fd, int how) ret = shutdown (fd, how); if (ret == -1) { gint errnum = errno; - DEBUG ("%s: shutdown error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: shutdown error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); @@ -807,7 +804,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused, if (fd == -1) { gint errnum = errno; - DEBUG ("%s: socket error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: socket error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -815,7 +812,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused, } if (fd >= _wapi_fd_reserve) { - DEBUG ("%s: File descriptor is too big (%d >= %d)", + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: File descriptor is too big (%d >= %d)", __func__, fd, _wapi_fd_reserve); WSASetLastError (WSASYSCALLFAILURE); @@ -840,14 +837,14 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused, * https://bugzilla.novell.com/show_bug.cgi?id=MONO53992 */ { - int ret, true = 1; + int ret, true_ = 1; - ret = setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &true, - sizeof (true)); + ret = setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &true_, + sizeof (true_)); if (ret == -1) { int errnum = errno; - DEBUG ("%s: Error setting SO_REUSEADDR", __func__); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Error setting SO_REUSEADDR", __func__); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -869,7 +866,7 @@ guint32 _wapi_socket(int domain, int type, int protocol, void *unused, return(INVALID_SOCKET); } - DEBUG ("%s: returning socket handle %p", __func__, handle); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: returning socket handle %p", __func__, handle); return(fd); } @@ -895,7 +892,7 @@ static gboolean socket_disconnect (guint32 fd) if (newsock == -1) { gint errnum = errno; - DEBUG ("%s: socket error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: socket error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -915,7 +912,7 @@ static gboolean socket_disconnect (guint32 fd) if (ret == -1) { gint errnum = errno; - DEBUG ("%s: dup2 error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: dup2 error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -931,7 +928,7 @@ static gboolean socket_disconnect (guint32 fd) static gboolean wapi_disconnectex (guint32 fd, WapiOverlapped *overlapped, guint32 flags, guint32 reserved) { - DEBUG ("%s: called on socket %d!", __func__, fd); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: called on socket %d!", __func__, fd); if (reserved != 0) { WSASetLastError (WSAEINVAL); @@ -1164,13 +1161,13 @@ WSAIoctl (guint32 fd, gint32 command, } if (i_len > 0) { - buffer = g_memdup (input, i_len); + buffer = (char *)g_memdup (input, i_len); } ret = ioctl (fd, command, buffer); if (ret == -1) { gint errnum = errno; - DEBUG("%s: WSAIoctl error: %s", __func__, + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: WSAIoctl error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); @@ -1263,7 +1260,7 @@ int ioctlsocket(guint32 fd, unsigned long command, gpointer arg) if (ret == -1) { gint errnum = errno; - DEBUG ("%s: ioctl error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: ioctl error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum); @@ -1300,7 +1297,7 @@ int _wapi_select(int nfds G_GNUC_UNUSED, fd_set *readfds, fd_set *writefds, if (ret == -1) { gint errnum = errno; - DEBUG ("%s: select error: %s", __func__, strerror (errno)); + MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: select error: %s", __func__, strerror (errno)); errnum = errno_to_WSA (errnum, __func__); WSASetLastError (errnum);