X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fnetwork.c;h=8ec365269dd5b003ffce0a9407b19edaf4a20c8d;hb=d47f834c1f2de41c9fba74a4b6928e7c8e0679e0;hp=5b1fa654d6b0cf65a47e69d6eea9c8e5c9144eb8;hpb=b23010f5708520611bf9addf75d839414275cfb8;p=oweals%2Fgnunet.git diff --git a/src/util/network.c b/src/util/network.c index 5b1fa654d..8ec365269 100644 --- a/src/util/network.c +++ b/src/util/network.c @@ -38,7 +38,11 @@ struct GNUNET_NETWORK_Handle { +#ifndef MINGW int fd; +#else + SOCKET fd; +#endif }; @@ -57,7 +61,7 @@ struct GNUNET_NETWORK_FDSet #ifdef WINDOWS /** - * Linked list of handles + * Linked list of handles */ struct GNUNET_CONTAINER_SList *handles; #endif @@ -222,7 +226,10 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, #ifdef DARWIN socket_set_nosigpipe (ret); #endif - socket_set_nodelay (ret); +#ifdef AF_UNIX + if (address->sa_family != AF_UNIX) +#endif + socket_set_nodelay (ret); return ret; } @@ -360,17 +367,21 @@ GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, * Returns GNUNET_NO if no data is available, or on error! * @param desc socket */ -unsigned int +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? */ +#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; @@ -398,14 +409,12 @@ GNUNET_NETWORK_socket_recvfrom (const struct GNUNET_NETWORK_Handle * desc, #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; } @@ -426,15 +435,12 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, #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; } @@ -587,7 +593,11 @@ GNUNET_NETWORK_socket_create (int domain, int type, int protocol) #ifdef DARWIN socket_set_nosigpipe (ret); #endif - if (type == SOCK_STREAM) + if ( (type == SOCK_STREAM) +#ifdef AF_UNIX + && (domain != AF_UNIX) +#endif + ) socket_set_nodelay (ret); return ret; } @@ -720,6 +730,21 @@ GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, to->nsds = nfds; } + +/** + * Set a native fd in a set + * + * @param to destination + * @param nfd native FD to set + */ +void GNUNET_NETWORK_fdset_set_native (struct GNUNET_NETWORK_FDSet *to, + int nfd) +{ + FD_SET (nfd, &to->sds); + to->nsds = GNUNET_MAX (nfd + 1, to->nsds); +} + + /** * Add a file handle to the fd set * @param fds fd set