+/**
+ * How much data is available to be read on this descriptor?
+ *
+ * Returns GNUNET_NO if no data is available, or on error!
+ * @param desc socket
+ */
+ssize_t
+GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle
+ *desc)
+{
+ int error;
+
+ /* How much is there to be read? */
+#ifndef WINDOWS
+ int pending;
+ error = ioctl (desc->fd, FIONREAD, &pending);
+ if (error == 0)
+#else
+ u_long pending;
+ error = ioctlsocket (desc->fd, FIONREAD, &pending);
+ if (error != SOCKET_ERROR)
+#endif
+ return pending;
+ else
+ return GNUNET_NO;
+}
+
+/**
+ * Read data from a connected socket (always non-blocking).
+ * @param desc socket
+ * @param buffer buffer
+ * @param length length of buffer
+ * @param src_addr either the source to recv from, or all zeroes
+ * to be filled in by recvfrom
+ * @param addrlen length of the addr
+ */
+ssize_t
+GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
+ void *buffer, size_t length,
+ struct sockaddr * src_addr,
+ socklen_t * addrlen)
+{
+ int ret;
+ int flags;
+ flags = 0;
+
+#ifdef MSG_DONTWAIT
+ flags |= MSG_DONTWAIT;
+
+#endif
+ ret = recvfrom (desc->fd, buffer, length, flags, src_addr, addrlen);
+#ifdef MINGW
+ if (SOCKET_ERROR == ret)
+ SetErrnoFromWinsockError (WSAGetLastError ());
+#endif
+ return ret;
+}
+
+