Re: read hang on datagram socket



On Thu, 26 Jan 2006, Kurt Miller wrote:

> I'm working on 1.5 jdk certification on 5.4 and 6.0. One of the jck
> tests hangs on 5.4 but works ok on 6.0. I've reduced the problem
> down to the following C program that hangs on 5.4 but works fine
> (finishes) on 6.0 and 4.11.
>
> I could use some assistance with finding a work-around to the
> problem or an explanation as to why the program hangs on 5.4.

It exit'd in the last connect() in Solaris 9. I modified it
to work -- see below.

>
> Thank you,
> -Kurt
>
> #include <stdio.h>
> #include <unistd.h>
> #include <netdb.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <sys/param.h>
> #include <netinet/in.h>

[ ... ]

> int
> main() {
> int sock1, sock2;
> int optval = 1;
> struct sockaddr addr;
> struct sockaddr sock1Addr, sock2Addr;
> int sock1AddrLen, sock2AddrLen;
> short port1, port2;
> char sendBuf, readBuf;
> int hostAddress;
>
> if ((hostAddress = getHostAddress()) == 0)
> exit(1);
>
> buildAddr4((struct sockaddr_in *)&addr, 0, 0);
>
> if ((sock1 = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
> exit(1);
> if (setsockopt(sock1, SOL_SOCKET, SO_BROADCAST, (char*) &optval, sizeof(optval)) != 0)
> exit(1);
> if (bind(sock1, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)
> exit(1);

+ sock1AddrLen = sizeof(sock1Addr);

> if (getsockname(sock1, &sock1Addr, &sock1AddrLen) != 0)
> exit(1);
> setAddress((struct sockaddr_in *)&sock1Addr, hostAddress);
>
> if ((sock2 = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
> exit(1);
> if (bind(sock2, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != 0)
> exit(1);

+ sock2AddrLen = sizeof(sock2Addr);

> if (getsockname(sock2, &sock2Addr, &sock2AddrLen) != 0)
> exit(1);
> setAddress((struct sockaddr_in *)&sock2Addr, hostAddress);
> if (connect(sock2, &sock1Addr, sock1AddrLen) != 0)
> exit(1);
>
> sendBuf = 22;
> if (sendto(sock1, &sendBuf, 1, 0, &sock2Addr, sock2AddrLen) != 1)
> exit(1);
>
> if (read(sock2, &readBuf, 1) != 1)
> exit(1);
>
> printf("no hang\n");
> }

--
DE

_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Using C functions in a TSR program
    ... hangs... ... But I'll be searching for the problem... ... monitoring DOS's crtical error flag as well as InDos. ... also the entry for Int 21h/AX=5d06h. ...
    (comp.os.msdos.programmer)
  • Kernel hangs on PCI config register access ???
    ... eject". ... static int pci_conf1_read (int seg, int bus, int devfn, int reg, int ... Using pci=bios still hangs; pci=conf2 doesn't work. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • usb 2.4: Little Rework for usbserial
    ... This patch fixes various hangs and oopses which happen if serial devices ... * has a lifetime from probe to disconnect. ... int sent = 0; ...
    (Linux-Kernel)
  • read hang on datagram socket
    ... problem or an explanation as to why the program hangs on 5.4. ... buildAddr4(struct sockaddr_in *addr4, int address, short port) { ... struct sockaddr sock1Addr, sock2Addr; ... char sendBuf, readBuf; ...
    (freebsd-hackers)
  • [PATCH 5/5] netpoll: fix up trapped logic
    ... This patch contains the updates necessary to fix the hangs in netconsole. ... int netpoll_parse_options ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)