1 /* $Id: receivedata.c,v 1.3 2012/03/05 19:42:47 nanard Exp $ */
3 * Website : http://miniupnp.free.fr/
4 * Author : Thomas Bernard
5 * Copyright (c) 2011-2012 Thomas Bernard
6 * This software is subject to the conditions detailed in the
7 * LICENCE file provided in this distribution. */
15 #if defined(__amigaos__) && !defined(__amigaos4__)
17 #else /* #if defined(__amigaos__) && !defined(__amigaos4__) */
18 #include <sys/select.h>
19 #endif /* #else defined(__amigaos__) && !defined(__amigaos4__) */
20 #include <sys/socket.h>
21 #if !defined(__amigaos__) && !defined(__amigaos4__)
25 #define MINIUPNPC_IGNORE_EINTR
29 #define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
31 #define PRINT_SOCKET_ERROR(x) perror(x)
34 #include "receivedata.h"
37 receivedata(int socket
, char * data
, int length
, int timeout
)
40 #if !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__)
42 struct pollfd fds
[1]; /* for the poll */
43 #ifdef MINIUPNPC_IGNORE_EINTR
47 fds
[0].events
= POLLIN
;
48 n
= poll(fds
, 1, timeout
);
49 #ifdef MINIUPNPC_IGNORE_EINTR
50 } while(n
< 0 && errno
== EINTR
);
53 PRINT_SOCKET_ERROR("poll");
59 #else /* !defined(_WIN32) && !defined(__amigaos__) && !defined(__amigaos4__) */
60 /* using select under _WIN32 and amigaos */
64 FD_SET(socket
, &socketSet
);
65 timeval
.tv_sec
= timeout
/ 1000;
66 timeval
.tv_usec
= (timeout
% 1000) * 1000;
67 n
= select(FD_SETSIZE
, &socketSet
, NULL
, NULL
, &timeval
);
69 PRINT_SOCKET_ERROR("select");
75 n
= recv(socket
, data
, length
, 0);
77 PRINT_SOCKET_ERROR("recv");