comp.lang.ada
 help / color / mirror / Atom feed
From: "Björn Lundin" <bnl@tiscali.se>
To: comp.lang.ada@ada-france.org
Subject: Gnat 3.4.2 tasking errorcodes windows
Date: Mon, 17 Jan 2005 20:44:54 +0100
Date: 2005-01-17T20:44:54+01:00	[thread overview]
Message-ID: <mailman.65.1105991123.527.comp.lang.ada@ada-france.org> (raw)

Hello all!

A couple of weeks I sent the mail below, but got no answers. Well, 
I then tried to use gnat 3.4.2 from minGW, instead of 3.15.p, but I got he 
same results still. Besides, it it only me that misses libaddr2line, used to 
print stacktraces? It was included in 3.15p, but now I cant find it :(

Below is the last mail, and the sample code. Any pointers to what is happening 
are very appreciated. 

/Björn


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 out, the second output is from when tasking is part of the program. compile
d 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 
WSAGetLasterror (which is what Gnat.Sockets.Thin.Socket Errno does, just 
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 error string to the exception has the correct error code in both cases.
By looking in the sources I see, that gnat is using 
Gnat.Sockets.Thin.Socket Errno to create that error-string. 

Testing with Object Ada 7.2.2 (well basically the same) will get the 
correct errorcode no matter of tasking or not


regards
Bjön Lundin






Without tasking
--------------------------------------------
Startup sockets
Get a socket
Try to connect!
GNAT.SOCKETS.SOCKET ERROR: [10061] Connection refused
 10061 - Connection refused
Resolve Exception - CONNECTION REFUSED



With tasking
--------------------------------------------
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


-------------------------------------------------------------------------
--
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 := 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 := Gnat.Sockets.Inet Addr("127.0.0.1"); 
  Address.Port := 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 =>
   Text IO.Put Line(Ada.Exceptions.Exception Name (E) & ": " & 
                    Ada.Exceptions.Exception Message (E));
   
   Error := Gnat.Sockets.Thin.Socket Errno;
   Text IO.Put Line(Integer'Image(Error) & " - " & 
            Gnat.Sockets.Thin.Socket Error Message (Error));
 
   Text IO.Put Line("Resolve Exception" & " - " & 
     Gnat.Sockets.Error Type'Image(Gnat.Sockets.Resolve Exception(E)));

   Gnat.Sockets.Finalize;

end socket connect;
-------------------------------------------------------------------------
--



             reply	other threads:[~2005-01-17 19:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-17 19:44 Björn Lundin [this message]
2005-01-17 22:04 ` Gnat 3.4.2 tasking errorcodes windows Randy Brukardt
2005-01-17 23:17   ` tmoran
2005-01-18 18:52   ` Björn Lundin
     [not found]   ` <200501181952.49091.bnl@tiscali.se>
2005-01-18 21:26     ` Stephen Leake
2005-01-18  0:33 ` Jeff C
2005-01-18 18:55   ` Björn Lundin
2005-01-18 14:44 ` Craig Carey
2005-01-18 16:34   ` Nicolas
2005-01-18 18:54     ` Björn Lundin
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox