From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f0972757f30880f7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-13 03:25:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: john@nospam.demon.co.uk (John McCabe) Newsgroups: comp.lang.ada Subject: Re: Sockets - newbie at a brick wall Date: Fri, 13 Dec 2002 11:25:59 GMT Message-ID: <3df9bee6.1810403@news.demon.co.uk> References: <3df85d10.3167644@news.demon.co.uk> <3df895c0.17679291@news.demon.co.uk> NNTP-Posting-Host: pipehawk.demon.co.uk X-Trace: news.demon.co.uk 1039778717 10472 158.152.226.81 (13 Dec 2002 11:25:17 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Fri, 13 Dec 2002 11:25:17 +0000 (UTC) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:31777 Date: 2002-12-13T11:25:59+00:00 List-Id: On Fri, 13 Dec 2002 01:23:06 +0900, Toshitaka Kumano wrote: >Sorry for somewhat off topic from GNAT.Sockets, > >John McCabe wrote: >> >1) Your use of Socket_Datagram with a Connect() call. Perhaps you >> >should try Socket_Stream sockets. >> >> Datagrams are 'connectionless' sockets so you wouldn't use the >> Connect() call at all. > >This statement seems restrictve. > >You can do "connect()" for Datagram socket and get some merits(*). Now that I've had a look at Unix Network Programming by W Richard Stevens, I see you are entirely correct. There's an interesting table in there on page 225 of the Second Edition. It says: It says that if you use sendto() that specifies a destination on a connected datagram socket, the error EISCONN (i.e. socket is already connected) will be raised. This is exactly what was happening with Ben's original example. Looking at the source of g-socket.adb, you can see that the write operation for a datagram socket contains the following... =========== procedure Write (Stream : in out Datagram_Socket_Stream_Type; Item : Ada.Streams.Stream_Element_Array) is : : begin loop Send_Socket (Stream.Socket, Item (First .. Max), Index, Stream.To); : : blah, blah. Here it is using the Send_Socket operation that requires a destination parameter (in this case Stream.To). That version of Send_Socket() calls C_Sendto, which is a pragma import of the C library's sendto() function. So the behaviour you got (Ben) is what is programmed into GNAT.Sockets. I wouldn't necessarily call this a bug, but it is certainly an oversight for GNAT.Sockets not to adjust what call is made on a datagram socket depending on whether it is connected or not. There are various ways of fixing this, but it all depends on how you determine whether a socket is connected or not. In the simplest scenario you would change part of Send_Socket from: Res := C_Sendto (C.int (Socket), Item (Item'First)'Address, Item'Length, 0, Sin'Unchecked_Access, Len); to: if Is_Connected (Socket) then (C.int (Socket), Item (Item'First)'Address, Item'Length, 0, Null, 0); else (C.int (Socket), Item (Item'First)'Address, Item'Length, 0, Sin'Unchecked_Access, Len); end if; If you're a supported user, I would certainly send in a bug report. Hope this helps. Best Regards John McCabe To reply by email replace 'nospam' with 'assen'