--- libaitio/src/sock.c 2013/08/26 23:30:27 1.2.2.1 +++ libaitio/src/sock.c 2013/08/26 23:37:27 1.2.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sock.c,v 1.2.2.1 2013/08/26 23:30:27 misho Exp $ +* $Id: sock.c,v 1.2.2.2 2013/08/26 23:37:27 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -216,8 +216,9 @@ ioAcceptSocket(sock_t * __restrict s, sock_cb_t f, voi struct pollfd pfd[1]; socklen_t salen; sockaddr_t sa; - int c; + int c, rlen; sock_cli_t *cli; + u_char buf[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; if (!s || s->sock_role == IO_SOCK_ROLE_CLIENT || !f) return -1; @@ -231,9 +232,18 @@ ioAcceptSocket(sock_t * __restrict s, sock_cb_t f, voi } else salen = sizeof sa.ss; - if ((c = accept(s->sock_fd, &sa.sa, &salen))) { - LOGERR; - return -1; + if (s->sock_type == SOCK_STREAM) { + if ((c = accept(s->sock_fd, &sa.sa, &salen)) == -1) { + LOGERR; + return -1; + } + } else { + if ((rlen = recvfrom(s->sock_fd, buf, sizeof buf, MSG_PEEK, + &sa.sa, &salen)) == -1) { + LOGERR; + return -1; + } else + c = s->sock_fd; } cli = e_malloc(sizeof(sock_cli_t));