Messages in this thread | | | Date | Sun, 6 Aug 2000 12:42:17 +0200 (CEST) | From | Koblinger Egmont <> | Subject | select is buggy on dgram-socketpair |
| |
Sending data to a datagram socket created by socketpair() can block because of two reasons: the number of total bytes in the buffer (not yet read by the peer) is greater than approx 65536, or the number of messages in the buffer has reached 10.
In the second case a select() before the send() incorrectly returns that the socket is writeable now.
I've tested this with the following kernels, all of them are buggy: 2.2.16, 2.2.17pre15, 2.3.38, 2.4.0-test5.
For the lazy people, see this example code, tell it the size of the messages to send as a command line argument. If this is a large number (6337 or above) then everythins is correct, however, if this is a small number (6336 or below) then select() gives incorrect result.
Best regards Egmont Koblinger
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <sys/time.h> #include <sys/types.h> #include <sys/socket.h>
int i, len, fd[2]; fd_set wfds; char buf[65536]; struct timeval tv;
int main (int argc, char *argv[]) { len = atoi(argv[1]); if (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd) < 0) { perror("socketpair"); exit(1); } while (1) { FD_ZERO(&wfds); FD_SET(fd[0], &wfds); tv.tv_sec = tv.tv_usec = 0; i = select(fd[0]+1, NULL, &wfds, NULL, &tv); if (i < 0) { perror("select"); exit(1); } if (!FD_ISSET(fd[0], &wfds)) { printf("select() says the socket is not writeable now. " "This is correct. Exiting.\n"); exit(0); } printf("select() says the socket is writeable now. Sending data... "); fflush(stdout); i = send(fd[0], buf, len, 0); if (i < 0) { perror("send"); exit(1); } if (i != len) { fprintf(stderr, "send failed\n"); exit(1); } printf("Data sent.\n"); } }
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |