#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
-#endif /* */
+#endif
+
+
struct GNUNET_NETWORK_Handle
{
int fd;
};
+
+
struct GNUNET_NETWORK_FDSet
{
- /* socket descriptors */
+ /**
+ * Maximum number of any socket socket descriptor in the set
+ */
int nsds;
+
+ /**
+ * Bitset with the descriptors.
+ */
fd_set sds;
#ifdef WINDOWS
- /* handles */
+ /**
+ * Linked list of handles
+ */
struct GNUNET_CONTAINER_SList *handles;
+#endif
-#endif /* */
};
#ifndef FD_COPY
#define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set)))
-#endif /* */
+#endif
+
/**
* Set if a socket should use blocking or non-blocking IO.
}
return GNUNET_OK;
-#else /* */
+#else
/* not MINGW */
int flags = fcntl (fd->fd, F_GETFL);
if (flags == -1)
return GNUNET_SYSERR;
}
return GNUNET_OK;
-
-#endif /* */
+#endif
}
return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0)
? GNUNET_OK : GNUNET_SYSERR;
}
+#endif
-#endif /* */
-
#ifdef DARWIN
/**
* The MSG_NOSIGNAL equivalent on Mac OS X
setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof (value)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
}
+#endif
-#endif /* */
-
/**
* Disable delays when sending data via the socket.
* (GNUnet makes sure that messages are as big as
ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
ret->fd = accept (desc->fd, address, address_len);
if (ret->fd == INVALID_SOCKET)
-
{
-
#ifdef MINGW
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
GNUNET_free (ret);
return NULL;
}
-
#ifndef MINGW
if (ret->fd >= FD_SETSIZE)
-
{
GNUNET_break (0 == close (ret->fd));
GNUNET_free (ret);
errno = EMFILE;
return NULL;
}
-
-#endif /* */
+#endif
if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
{
if (GNUNET_OK != socket_set_inheritable (ret))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"socket_set_inheritable");
-
-#endif /* */
+#endif
#ifdef DARWIN
socket_set_nosigpipe (ret);
-
-#endif /* */
+#endif
socket_set_nodelay (ret);
return ret;
}
socklen_t address_len)
{
int ret;
- ret = bind (desc->fd, address, address_len);
+ ret = bind (desc->fd, address, address_len);
#ifdef MINGW
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
#ifdef MINGW
ret = closesocket (desc->fd);
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#else /* */
+#else
ret = close (desc->fd);
-
-#endif /* */
+#endif
eno = errno;
GNUNET_free (desc);
errno = eno;
if (errno == EWOULDBLOCK)
errno = EINPROGRESS;
}
-
-#endif /* */
+#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
else if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-#endif /* */
+#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-#endif /* */
+#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
#ifdef MSG_DONTWAIT
flags |= MSG_DONTWAIT;
-
-#endif /* */
+#endif
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
-
-#endif /* */
+#endif
ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len);
-
#ifdef MINGW
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
return ret;
}
socklen_t option_len)
{
int ret;
- ret = setsockopt (fd->fd, level, option_name, option_value, option_len);
+ ret = setsockopt (fd->fd, level, option_name, option_value, option_len);
#ifdef MINGW
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
ret->fd = socket (domain, type, protocol);
if (INVALID_SOCKET == ret->fd)
-
{
-
#ifdef MINGW
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
GNUNET_free (ret);
return NULL;
}
#ifndef MINGW
if (ret->fd >= FD_SETSIZE)
-
{
GNUNET_break (0 == close (ret->fd));
GNUNET_free (ret);
return NULL;
}
-#endif /* */
+#endif
if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
-
{
-
/* we might want to treat this one as fatal... */
GNUNET_break (0);
GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
if (GNUNET_OK != socket_set_inheritable (ret))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"socket_set_inheritable");
-
-#endif /* */
+#endif
#ifdef DARWIN
socket_set_nosigpipe (ret);
-
-#endif /* */
+#endif
if (type == SOCK_STREAM)
socket_set_nodelay (ret);
return ret;
GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, int how)
{
int ret;
- ret = shutdown (desc->fd, how);
+ ret = shutdown (desc->fd, how);
#ifdef MINGW
if (ret != 0)
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
}
{
FD_ZERO (&fds->sds);
fds->nsds = 0;
-
#ifdef MINGW
GNUNET_CONTAINER_slist_clear (fds->handles);
-
-#endif /* */
+#endif
}
/**
/**
* Copy one fd set to another
+ *
* @param to destination
* @param from source
*/
#ifdef MINGW
GNUNET_CONTAINER_slist_clear (to->handles);
GNUNET_CONTAINER_slist_append (to->handles, from->handles);
-#endif /* */
+#endif
}
/**
* Copy a native fd set
+ *
* @param to destination
* @param from native source set
* @param nfds the biggest socket number in from + 1
GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE));
GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &hw, sizeof (HANDLE));
-#else /* */
+#else
int fd;
GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int));
FD_SET (fd, &fds->sds);
if (fd + 1 > fds->nsds)
fds->nsds = fd + 1;
-#endif /* */
+#endif
}
#ifdef MINGW
return GNUNET_CONTAINER_slist_contains (fds->handles, &h->h,
sizeof (HANDLE));
-
-#else /* */
+#else
return FD_ISSET (h->fd, &fds->sds);
-
-#endif /* */
+#endif
}
{
struct GNUNET_NETWORK_FDSet *fds;
fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet));
-
#ifdef MINGW
fds->handles = GNUNET_CONTAINER_slist_create ();
-
-#endif /* */
+#endif
GNUNET_NETWORK_fdset_zero (fds);
return fds;
}
void
GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
{
-
#ifdef MINGW
GNUNET_CONTAINER_slist_destroy (fds->handles);
-
-#endif /* */
+#endif
GNUNET_free (fds);
}
(timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
? NULL : &tv);
-#else /* */
+#else
DWORD limit;
fd_set sock_read, sock_write, sock_except;
fd_set aread, awrite, aexcept;
limit = GetTickCount () + ms_total;
do
-
{
retcode = 0;
if (nfds > 0)
#if DEBUG_NETWORK
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select");
-#endif /* */
+#endif
goto select_loop_end;
}
}
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"PeekNamedPipe");
-#endif /* */
+#endif
goto select_loop_end;
}
else if (dwBytes)
GNUNET_CONTAINER_slist_destroy (handles_except);
return retcode;
-
-#endif /* */
+#endif
}