Gnat 3.4.2 tasking errorcodes windows

From: Björn Lundin (bnl_at_tiscali.se)
Date: 01/17/05


Date: Mon, 17 Jan 2005 20:44:54 +0100
To: comp.lang.ada@ada-france.org

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;
-------------------------------------------------------------------------
--


Relevant Pages

  • Re: GNAT.Sockets: Timeval_Duration is in milliseconds?
    ... So if you are using Windows, Microsoft's decision to screw things up ... I suppose we have to report this as a bug in GNAT though it would be ... Personally I've never used timeouts -- I've used selectand waited ... Sets with only one socket seems to be overcomplication, ...
    (comp.lang.ada)
  • Re: using c with html interface
    ... and returns the result to the html page. ... the socket() function returns with an error. ... However, when i execute the program on the command line in linux, the ... Any output you want should just be output to stdout, you don't need to establish a socket connection to the peer. ...
    (comp.lang.c)
  • using c with html interface
    ... and returns the result to the html page. ... The OS used is Red Hat linux. ... the socket() function returns with an error. ... However, when i execute the program on the command line in linux, the ...
    (comp.lang.c)
  • Re: Windows XMLRPC Service
    ... May be because you didn't set correctly the socket timeout. ... never execute because ... Gabriel Genellina ...
    (comp.lang.python)
  • Re: Windows reverse Shell
    ... I wrote a little piece of shellcode that should spawn a shell using a ... socket in %ebp, which will execute cmd.exe succesfully. ...
    (Vuln-Dev)