Not enough queuing of datagrams on a unix domain socket

Not enough queuing of datagrams on a unix domain socket

Post by Wonjae Le » Sat, 31 May 2003 10:33:12



  When I test in Linux 2.4.18-14debug(Redhat 8.0), only 10 or 11 datagrams
can be queued on a unix domain socket(datagram)'s receive buffer. If a
sender tries to send more datagrams, it blocks(in a blocking sento) or
returns error(in a non-blocking sendto). That doesn't make sense, because
each message is 10 bytes long and receive buffer size is 128KB. Is there any
solution?

----> dg_serv.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>

#define MAXLINE 1024

int
main(int argc, char **argv)
{
 int     sockfd, clilen, rcvbufsize, len;
 struct sockaddr_un cliaddr, servaddr;
 char recvline[MAXLINE + 1];

 char UNIXDG_PATH[30]="unix_sock_dgram";

 sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0);

 unlink(UNIXDG_PATH);
 bzero(&servaddr, sizeof(servaddr));
 servaddr.sun_family = AF_LOCAL;
 strcpy(servaddr.sun_path, UNIXDG_PATH);

 bind(sockfd, (struct sockaddr*) &servaddr, sizeof(servaddr));
 rcvbufsize = 256*1024; // when i tested, 128KB is max size
 len = sizeof(rcvbufsize);
 setsockopt( sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, len);
 getsockopt( sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, &len);
 printf("recv buffer size = %d\n", rcvbufsize);

 clilen = sizeof(cliaddr);
 while (1) {
  int n;

  getchar();

  while( (n = recvfrom(sockfd, recvline, MAXLINE, MSG_DONTWAIT,
    (struct sockaddr*) &cliaddr, &clilen ))>0 ) {
   recvline[n]='\0';

   printf("Received :%s", recvline);
  }

 }

Quote:}

----> dg_cli.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>

#define MAXLINE 1024

int
main(int argc, char **argv)
{
 int     sockfd, count=0;
 struct sockaddr_un cliaddr, servaddr;

 char UNIXDG_PATH[30]="unix_sock_dgram";

 sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0);

 bzero(&cliaddr, sizeof(cliaddr));  /* bind an address for us */
 cliaddr.sun_family = AF_LOCAL;
 strcpy(cliaddr.sun_path, tmpnam(NULL));

 bind(sockfd, (struct sockaddr*) &cliaddr, sizeof(cliaddr));

 bzero(&servaddr, sizeof(servaddr)); /* fill in server's address */
 servaddr.sun_family = AF_LOCAL;
 strcpy(servaddr.sun_path, UNIXDG_PATH);

 while (1) {
  char sendline[MAXLINE];
  int retval;

  sprintf( sendline, "Message %d\n" , count);

  retval = sendto(sockfd, sendline, strlen(sendline), MSG_DONTWAIT,
    (struct sockaddr*) &servaddr, sizeof(servaddr) );

  printf("called sendto() with %s", sendline);
  printf("return value = %d, errno = %d\n",retval,errno);

  sleep(1);

  count += 1;

 }

Quote:}

 
 
 

1. Not enough queuing of datagrams on a unix domain socket

  When I test in Linux 2.4.18-14debug(Redhat 8.0), only 10 or 11 datagrams
can be queued on a unix domain socket(datagram)'s receive buffer. If a
sender tries to send more datagrams, it blocks(in a blocking sento) or
returns error(in a non-blocking sendto). That doesn't make sense, because
each message is 10 bytes long and receive buffer size is 128KB. Is there any
solution?

----> dg_serv.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>

#define MAXLINE 1024

int
main(int argc, char **argv)
{
 int     sockfd, clilen, rcvbufsize, len;
 struct sockaddr_un cliaddr, servaddr;
 char recvline[MAXLINE + 1];

 char UNIXDG_PATH[30]="unix_sock_dgram";

 sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0);

 unlink(UNIXDG_PATH);
 bzero(&servaddr, sizeof(servaddr));
 servaddr.sun_family = AF_LOCAL;
 strcpy(servaddr.sun_path, UNIXDG_PATH);

 bind(sockfd, (struct sockaddr*) &servaddr, sizeof(servaddr));
 rcvbufsize = 256*1024;
 len = sizeof(rcvbufsize);
 setsockopt( sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, len);
 getsockopt( sockfd, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, &len);
 printf("recv buffer size = %d\n", rcvbufsize);

 clilen = sizeof(cliaddr);
 while (1) {
  int n;

  getchar();

  while( (n = recvfrom(sockfd, recvline, MAXLINE, MSG_DONTWAIT,
    (struct sockaddr*) &cliaddr, &clilen ))>0 ) {
   recvline[n]='\0';

   printf("Received :%s", recvline);
  }

 }

----> dg_cli.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>

#define MAXLINE 1024

int
main(int argc, char **argv)
{
 int     sockfd, count=0;
 struct sockaddr_un cliaddr, servaddr;

 char UNIXDG_PATH[30]="unix_sock_dgram";

 sockfd = socket(AF_LOCAL, SOCK_DGRAM, 0);

 bzero(&cliaddr, sizeof(cliaddr));  /* bind an address for us */
 cliaddr.sun_family = AF_LOCAL;
 strcpy(cliaddr.sun_path, tmpnam(NULL));

 bind(sockfd, (struct sockaddr*) &cliaddr, sizeof(cliaddr));

 bzero(&servaddr, sizeof(servaddr)); /* fill in server's address */
 servaddr.sun_family = AF_LOCAL;
 strcpy(servaddr.sun_path, UNIXDG_PATH);

 while (1) {
  char sendline[MAXLINE];
  int retval;

  sprintf( sendline, "Message %d\n" , count);

  retval = sendto(sockfd, sendline, strlen(sendline), MSG_DONTWAIT,
    (struct sockaddr*) &servaddr, sizeof(servaddr) );

  printf("called sendto() with %s", sendline);
  printf("return value = %d, errno = %d\n",retval,errno);

  sleep(1);

  count += 1;

 }

2. more on LINUX and CD-ROMs

3. UNIX Domain Datagram Sockets - Receive Queue Size?

4. AIX and AVS

5. UNIX Domain Datagram Socket:Receive Queue Size?

6. PCMCIA support

7. UNIX domain datagram sockets

8. newbie needs pwd guru

9. UNIX domain Socket Datagram question

10. DATAGRAM sockets in the UNIX DOMAIN.

11. Datagram sockets in Unix Domain?

12. Are unix domain socket datagrams reliable?

13. credentials from Unix-domain datagram socket?