struct GNUNET_NETWORK_Handle
{
+#ifndef MINGW
int fd;
+#else
+ SOCKET fd;
+#endif
};
#ifdef WINDOWS
/**
- * Linked list of handles
+ * Linked list of handles
*/
struct GNUNET_CONTAINER_SList *handles;
#endif
* Returns GNUNET_NO if no data is available, or on error!
* @param desc socket
*/
-unsigned int
-GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle * desc)
+ssize_t
+GNUNET_NETWORK_socket_recvfrom_amount (const struct GNUNET_NETWORK_Handle
+ *desc)
{
int error;
- unsigned int pending;
+ int pending;
/* How much is there to be read? */
- error = ioctl(desc->fd, FIONREAD, &pending);
- GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, "udp", _
- ("pending is %u bytes, error is %d\n"), pending, error);
-
+#ifndef WINDOWS
+ error = ioctl (desc->fd, FIONREAD, &pending);
if (error == 0)
+#else
+ error = ioctlsocket (desc->fd, FIONREAD, &pending);
+ if (error != SOCKET_ERROR)
+#endif
return pending;
else
return GNUNET_NO;
ssize_t
GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc,
void *buffer, size_t length,
- struct sockaddr *src_addr, socklen_t *addrlen)
+ struct sockaddr * src_addr,
+ socklen_t * addrlen)
{
int ret;
int flags;
#ifdef MSG_DONTWAIT
flags |= MSG_DONTWAIT;
-#endif /* */
+#endif
ret = recvfrom (desc->fd, buffer, length, flags, src_addr, addrlen);
-
#ifdef MINGW
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
return ret;
}
#ifdef MSG_DONTWAIT
flags |= MSG_DONTWAIT;
-
-#endif /* */
+#endif
ret = recv (desc->fd, buffer, length, flags);
-
#ifdef MINGW
if (SOCKET_ERROR == ret)
SetErrnoFromWinsockError (WSAGetLastError ());
-
-#endif /* */
+#endif
return ret;
}
#ifdef MINGW
HANDLE hw;
GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE));
- GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &hw, sizeof (HANDLE));
+ GNUNET_CONTAINER_slist_add (fds->handles,
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &hw, sizeof (HANDLE));
#else
int fd;
return GNUNET_YES;
#ifdef MINGW
{
- struct GNUNET_CONTAINER_SList_Iterator *it;
+ struct GNUNET_CONTAINER_SList_Iterator *it;
- for(it = GNUNET_CONTAINER_slist_begin (fds1->handles); GNUNET_CONTAINER_slist_end (it) != GNUNET_YES; GNUNET_CONTAINER_slist_next (it))
- {
- HANDLE *h;
-
- h = GNUNET_CONTAINER_slist_get (it, NULL);
- if (GNUNET_CONTAINER_slist_contains (fds2->handles, h, sizeof (HANDLE)))
- {
- GNUNET_CONTAINER_slist_iter_destroy (it);
- return GNUNET_YES;
- }
- }
- GNUNET_CONTAINER_slist_iter_destroy (it);
+ for (it = GNUNET_CONTAINER_slist_begin (fds1->handles);
+ GNUNET_CONTAINER_slist_end (it) != GNUNET_YES;
+ GNUNET_CONTAINER_slist_next (it))
+ {
+ HANDLE *h;
+
+ h = GNUNET_CONTAINER_slist_get (it, NULL);
+ if (GNUNET_CONTAINER_slist_contains
+ (fds2->handles, h, sizeof (HANDLE)))
+ {
+ GNUNET_CONTAINER_slist_iter_destroy (it);
+ return GNUNET_YES;
+ }
+ }
+ GNUNET_CONTAINER_slist_iter_destroy (it);
}
#endif
return GNUNET_NO;
DWORD limit;
fd_set sock_read, sock_write, sock_except;
fd_set aread, awrite, aexcept;
- struct GNUNET_CONTAINER_SList *handles_read, *handles_write, *handles_except;
+ struct GNUNET_CONTAINER_SList *handles_read, *handles_write,
+ *handles_except;
int i;
struct timeval tvslice;
{
GNUNET_CONTAINER_slist_add (handles_read,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &h,
- sizeof (HANDLE));
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &h, sizeof (HANDLE));
retcode++;
}
}
{
GNUNET_CONTAINER_slist_add (handles_except,
- GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &h,
- sizeof (HANDLE));
+ GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
+ &h, sizeof (HANDLE));
retcode++;
}
}