diff options
author | Tobias Markmann <tm@ayena.de> | 2011-05-26 18:46:49 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-09-25 17:42:32 (GMT) |
commit | 4f62e5ec4b42929fe3c1a68667e63cb1b7a35509 (patch) | |
tree | 0d19fac3f578dec00ccf3e58930312951e38de89 /3rdParty/LibMiniUPnPc/src/miniupnpc/receivedata.c | |
parent | de660b763459cdd707876ec244b6866abca07fa2 (diff) | |
download | swift-contrib-4f62e5ec4b42929fe3c1a68667e63cb1b7a35509.zip swift-contrib-4f62e5ec4b42929fe3c1a68667e63cb1b7a35509.tar.bz2 |
Google Summer of Code 2011 Project: Adding support for Jingle File Transfers (XEP-0234), Jingle SOCKS5 Bytestreams Transport Method (XEP-0260), Jingle In-Band Bytestreams Transport Method (XEP-0261) and SOCKS5 Bytestreams (XEP-0065).
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to '3rdParty/LibMiniUPnPc/src/miniupnpc/receivedata.c')
-rw-r--r-- | 3rdParty/LibMiniUPnPc/src/miniupnpc/receivedata.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/3rdParty/LibMiniUPnPc/src/miniupnpc/receivedata.c b/3rdParty/LibMiniUPnPc/src/miniupnpc/receivedata.c new file mode 100644 index 0000000..a1eadfc --- /dev/null +++ b/3rdParty/LibMiniUPnPc/src/miniupnpc/receivedata.c @@ -0,0 +1,81 @@ +/* $Id: receivedata.c,v 1.1 2011/04/11 08:21:47 nanard Exp $ */ +/* Project : miniupnp + * Author : Thomas Bernard + * Copyright (c) 2011 Thomas Bernard + * This software is subject to the conditions detailed in the + * LICENCE file provided in this distribution. */ + +#include <stdio.h> +#ifdef WIN32 +#include <winsock2.h> +#include <ws2tcpip.h> +#else +#include <unistd.h> +#if defined(__amigaos__) && !defined(__amigaos4__) +#define socklen_t int +#else /* #if defined(__amigaos__) && !defined(__amigaos4__) */ +#include <sys/select.h> +#endif /* #else defined(__amigaos__) && !defined(__amigaos4__) */ +#include <sys/socket.h> +#if !defined(__amigaos__) && !defined(__amigaos4__) +#include <poll.h> +#endif +#include <errno.h> +#define MINIUPNPC_IGNORE_EINTR +#endif + +#ifdef WIN32 +#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError()); +#else +#define PRINT_SOCKET_ERROR(x) perror(x) +#endif + +#include "receivedata.h" + +int +receivedata(int socket, char * data, int length, int timeout) +{ + int n; +#if !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) + /* using poll */ + struct pollfd fds[1]; /* for the poll */ +#ifdef MINIUPNPC_IGNORE_EINTR + do { +#endif + fds[0].fd = socket; + fds[0].events = POLLIN; + n = poll(fds, 1, timeout); +#ifdef MINIUPNPC_IGNORE_EINTR + } while(n < 0 && errno == EINTR); +#endif + if(n < 0) { + PRINT_SOCKET_ERROR("poll"); + return -1; + } else if(n == 0) { + /* timeout */ + return 0; + } +#else /* !defined(WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */ + /* using select under WIN32 and amigaos */ + fd_set socketSet; + TIMEVAL timeval; + FD_ZERO(&socketSet); + FD_SET(socket, &socketSet); + timeval.tv_sec = timeout / 1000; + timeval.tv_usec = (timeout % 1000) * 1000; + n = select(FD_SETSIZE, &socketSet, NULL, NULL, &timeval); + if(n < 0) { + PRINT_SOCKET_ERROR("select"); + return -1; + } else if(n == 0) { + return 0; + } +#endif + n = recv(socket, data, length, 0); + if(n<0) { + PRINT_SOCKET_ERROR("recv"); + } + return n; +} + + |