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=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,55d7a8ac203f8ae5,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!oleane.net!oleane!nerim.net!usenet-fr.net!enst.fr!melchior!cuivre.fr.eu.org!melchior.frmug.org!not-for-mail From: =?iso-8859-1?q?Bj=F6rn_Lundin?= Newsgroups: comp.lang.ada Subject: gnat win sockets WSAGetLastError tasking Date: Tue, 4 Jan 2005 22:30:06 +0100 Organization: Cuivre, Argent, Or Message-ID: NNTP-Posting-Host: lovelace.ada-france.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: melchior.cuivre.fr.eu.org 1104874237 54084 212.85.156.195 (4 Jan 2005 21:30:37 GMT) X-Complaints-To: usenet@melchior.cuivre.fr.eu.org NNTP-Posting-Date: Tue, 4 Jan 2005 21:30:37 +0000 (UTC) To: comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.7.2 Content-Disposition: inline X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Xref: g2news1.google.com comp.lang.ada:7443 Date: 2005-01-04T22:30:06+01:00 Hello all! I'm writing a console socket application, with several tasks, and I run into som strange behaviour when tasks are involved. Below is output from a test program (also below). The first output is when the tasking part was comment= ed=20 out, the second output is from when tasking is part of the program. compile= d=20 with gnat 3.15p on a w2k box. (just gnatmake socket_connect.adb) What I wonder is why I can get the correct errorcode by calling=20 WSAGetLasterror (which is what Gnat.Sockets.Thin.Socket_Errno does, just=20 pragma import) when having no tasks, but not when having tasks. It gets even more strange (to me at least) when i realize that the associat= ed=20 error string to the exception has the correct error code in both cases. By looking in the sources I see, that gnat is using=20 Gnat.Sockets.Thin.Socket_Errno to create that error-string.=20 Testing with Object Ada 7.2.2 (well basically the same) will get the=20 correct errorcode no matter of tasking or not regards Bj=F6rn Lundin Without tasking =2D------------------------------------------- Startup sockets Get a socket Try to connect! GNAT.SOCKETS.SOCKET_ERROR: [10061] Connection refused 10061 - Connection refused Resolve_Exception - CONNECTION_REFUSED With tasking =2D------------------------------------------- Task running, Execute! Startup sockets Get a socket Try to connect! GNAT.SOCKETS.SOCKET_ERROR: [10061] Connection refused 0 - Unknown system error Resolve_Exception - CONNECTION_REFUSED =2D------------------------------------------------------------------------= =2D- with Text_Io; with Gnat.Sockets; with Gnat.Sockets.Thin; with Ada.Exceptions; procedure Socket_Connect is Socket : Gnat.Sockets.Socket_Type; Address : Gnat.Sockets.Sock_Addr_Type; Error : Integer :=3D 0; -------------------------------------------------- task type Run_Once is entry Execute; end Run_Once; -------------------------------------------------- task body Run_Once is begin select accept Execute do text_io.put_line("Task running, Execute!"); end Execute; or terminate; end select; end Run_Once; -------------------------------------------------- begin declare TmpTask : Run_Once; begin TmpTask.Execute; end; text_io.put_line("Startup sockets"); Gnat.Sockets.Initialize; text_io.put_line("Get a socket"); Gnat.Sockets.Create_Socket (Socket); text_io.put_line("Try to connect!"); Address.Addr :=3D Gnat.Sockets.Inet_Addr("127.0.0.1");=20 Address.Port :=3D 8000; Gnat.Sockets.Connect_Socket (Socket, Address); text_io.put_line("Connected!"); text_io.put_line("Close socket!"); Gnat.Sockets.Close_Socket (Socket); text_io.put_line("Shutdown sockets!"); Gnat.Sockets.Finalize; text_io.put_line("Done!"); exception when E: others =3D> Text_IO.Put_Line(Ada.Exceptions.Exception_Name (E) & ": " &=20 Ada.Exceptions.Exception_Message (E)); =20 Error :=3D Gnat.Sockets.Thin.Socket_Errno; Text_IO.Put_Line(Integer'Image(Error) & " - " &=20 Gnat.Sockets.Thin.Socket_Error_Message (Error)); =20 Text_IO.Put_Line("Resolve_Exception" & " - " &=20 Gnat.Sockets.Error_Type'Image(Gnat.Sockets.Resolve_Exception(E))); Gnat.Sockets.Finalize; end socket_connect; =2D------------------------------------------------------------------------= =2D-