#include <mono/io-layer/socket-private.h>
#include <mono/io-layer/handles-private.h>
#include <mono/io-layer/socket-wrappers.h>
+#include <mono/io-layer/io-trace.h>
#include <mono/utils/mono-poll.h>
+#include <mono/utils/mono-once.h>
+#include <mono/utils/mono-logger-internals.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#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);
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.
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);
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);
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);
}
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);
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);
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);
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__);
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);
&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);
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);
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__);
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__);
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__);
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);
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);
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);
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
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);
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);
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__);
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__);
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);
}
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);
* 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);
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);
}
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);
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);
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);
/* TODO: Might not send the entire file for non-blocking sockets */
res = sendfile (file, socket, 0, &statbuf.st_size, NULL, 0);
#endif
- } while (res != -1 && (errno == EINTR || errno == EAGAIN) && !_wapi_thread_cur_apc_pending ());
+ } while (res != -1 && errno == EINTR && !_wapi_thread_cur_apc_pending ());
if (res == -1) {
errnum = errno;
errnum = errno_to_WSA (errnum, __func__);
}
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__);
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);
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);