#include "config.h"
#endif /* HAVE_CONFIG_H */
+#ifndef _XOPEN_SOURCE
+# define _XOPEN_SOURCE 600
+#endif
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__
+#endif
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
* io mode for the socket
* @param timeout (r) number of seconds to try reading
*
- * @returns number of bytes actually read or -1 on fatal error
+ * @returns number of bytes actually read or -1 on timeout or error
*/
ssize_t readt(int socket, void *data, const size_t length, int setnonblocking, int timeout)
{
fd_set rfds;
int ret;
+ FD_ZERO(&rfds);
+
if (setnonblocking) {
if (setnonblock(socket, 1) != 0)
return -1;
case EINTR:
continue;
case EAGAIN:
- FD_ZERO(&rfds);
FD_SET(socket, &rfds);
tv.tv_usec = 0;
tv.tv_sec = timeout;
while ((ret = select(socket + 1, &rfds, NULL, NULL, &tv)) < 1) {
switch (ret) {
case 0:
- LOG(log_warning, logtype_afpd, "select timeout %d s", timeout);
+ LOG(log_debug, logtype_afpd, "select timeout %d s", timeout);
+ errno = EAGAIN;
goto exit;
default: /* -1 */
tv.tv_usec = end.tv_usec - now.tv_usec;
tv.tv_sec = end.tv_sec - now.tv_sec;
}
- FD_ZERO(&rfds);
FD_SET(socket, &rfds);
continue;
}
}
}
+/* Length of the space taken up by a padded control message of length len */
+#ifndef CMSG_SPACE
+#define CMSG_SPACE(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len))
+#endif
+
/*
* Receive a fd on a suitable socket
* @args fd (r) PF_UNIX socket to receive on