comp.lang.ada
 help / color / mirror / Atom feed
* Gnat 3.4.2 tasking errorcodes windows
@ 2005-01-17 19:44 Björn Lundin
  2005-01-17 22:04 ` Randy Brukardt
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Björn Lundin @ 2005-01-17 19:44 UTC (permalink / raw)
  To: comp.lang.ada

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



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-17 19:44 Gnat 3.4.2 tasking errorcodes windows Björn Lundin
@ 2005-01-17 22:04 ` Randy Brukardt
  2005-01-17 23:17   ` tmoran
                     ` (2 more replies)
  2005-01-18  0:33 ` Jeff C
  2005-01-18 14:44 ` Craig Carey
  2 siblings, 3 replies; 10+ messages in thread
From: Randy Brukardt @ 2005-01-17 22:04 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]

"Bj�rn Lundin" <bnl@tiscali.se> wrote in message
news:mailman.65.1105991123.527.comp.lang.ada@ada-france.org...
...
> 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.

I wouldn't expect that to work. WSAGetLastError isn't necessarily
thread-safe: I believe that there is only one global copy per process. If
you have multiple threads all doing sockets calls, the values will get
clobbered by the next sockets call. We handled that in the Claw sockets
bindings by grabbing the WSAGetLastError value immediately, and then raising
an appropriate exception (but even that isn't guaranteed to work in every
case). Waiting certainly won't work.

I would guess that the reason that Gnat.Sockets.Thin directly accesses via
Import is that it assumes no tasking issues. In any case, why access this
directly? You're just asking for trouble, by making yourself rediscover
things that the binding writers already did.

                      Randy.









^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-17 22:04 ` Randy Brukardt
@ 2005-01-17 23:17   ` tmoran
  2005-01-18 18:52   ` Björn Lundin
       [not found]   ` <200501181952.49091.bnl@tiscali.se>
  2 siblings, 0 replies; 10+ messages in thread
From: tmoran @ 2005-01-17 23:17 UTC (permalink / raw)


>I wouldn't expect that to work. WSAGetLastError isn't necessarily
>thread-safe: I believe that there is only one global copy per process.
  Are you sure of that?  The docs I have, and relied on, say
"Note that errors are thread-specific".  If that's not true, then
it's pure luck if a multi-thread socket app manages to work.
Good luck is not something I normally base a design on.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-17 19:44 Gnat 3.4.2 tasking errorcodes windows Björn Lundin
  2005-01-17 22:04 ` Randy Brukardt
@ 2005-01-18  0:33 ` Jeff C
  2005-01-18 18:55   ` Björn Lundin
  2005-01-18 14:44 ` Craig Carey
  2 siblings, 1 reply; 10+ messages in thread
From: Jeff C @ 2005-01-18  0:33 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 802 bytes --]


"Bj�rn Lundin" <bnl@tiscali.se> wrote in message 
news:mailman.65.1105991123.527.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 :(





Looks to me like this function returns a thread specific value so it should 
be ok.
Clearly it is not ok for some reason. I'd guess something about the 
exception propagation within
the threaded run-time support is clearing that error value. I see no reason 
why it should

I recommend you submit a bugzilla bug at the gcc site. At the very least 
this should be documented.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-17 19:44 Gnat 3.4.2 tasking errorcodes windows Björn Lundin
  2005-01-17 22:04 ` Randy Brukardt
  2005-01-18  0:33 ` Jeff C
@ 2005-01-18 14:44 ` Craig Carey
  2005-01-18 16:34   ` Nicolas
  2 siblings, 1 reply; 10+ messages in thread
From: Craig Carey @ 2005-01-18 14:44 UTC (permalink / raw)



On Mon, 17 Jan 2005 20:44:54 +0100, Bj�rn Lundin <bnl@tiscali.se> wrote:
...
>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 :(
...

A "libaddr2line.a" file for Windows is here:

http://public.planetmirror.com/pub/sf/m/mi/mingw/libaddr2line.tar.gz

12.2 KB. Contains: "libaddr2line.a" (13,086 bytes).

The same file was once at Sourceforge and it is not there now:

  http://sourceforge.net/projects/mingw/

--.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-18 14:44 ` Craig Carey
@ 2005-01-18 16:34   ` Nicolas
  2005-01-18 18:54     ` Björn Lundin
  0 siblings, 1 reply; 10+ messages in thread
From: Nicolas @ 2005-01-18 16:34 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]

If this is the file which was on sourceforge with an older version of 
binutils, it doesn't work with current binutils-2.15.91-20040904-1
Link will be fine, but output of stacktrace will be corrupted.
You have to build libaddr2line.a with corresponding binutils version (check 
binutils makefile)


"Craig Carey" <research@ijs.co.nz> a �crit dans le message de news: 
166qu0pdfgm61fvc563sun9857uui0r40e@4ax.com...
>
> On Mon, 17 Jan 2005 20:44:54 +0100, Bj�rn Lundin <bnl@tiscali.se> wrote:
> ...
>>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 :(
> ...
>
> A "libaddr2line.a" file for Windows is here:
>
> http://public.planetmirror.com/pub/sf/m/mi/mingw/libaddr2line.tar.gz
>
> 12.2 KB. Contains: "libaddr2line.a" (13,086 bytes).
>
> The same file was once at Sourceforge and it is not there now:
>
>  http://sourceforge.net/projects/mingw/
>
> --. 





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-17 22:04 ` Randy Brukardt
  2005-01-17 23:17   ` tmoran
@ 2005-01-18 18:52   ` Björn Lundin
       [not found]   ` <200501181952.49091.bnl@tiscali.se>
  2 siblings, 0 replies; 10+ messages in thread
From: Björn Lundin @ 2005-01-18 18:52 UTC (permalink / raw)
  To: comp.lang.ada

måndag 17 januari 2005 23:04 skrev Randy Brukardt:
> "Björn Lundin" <bnl@tiscali.se> wrote in message
> news:mailman.65.1105991123.527.comp.lang.ada@ada-france.org...
> ...
>
> > 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.
>
> I wouldn't expect that to work. WSAGetLastError isn't necessarily
> thread-safe: I believe that there is only one global copy per process. 

Hmm, not according to:
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/wsagetlasterror_2.asp>

In short from the webpage:
Return Values
The return value indicates the error code for this thread's last Windows 
Sockets operation that failed.
Remarks
The WSAGetLastError function returns returns the last error that occurred for 
the calling thread. 


So Microsoft thinks it's thread/task safe and it is if I use Object Ada. Now, 
I'm (my company) is moving from Object Ada to Gnat, but this one is a 
showstopper :( (We already did the transition on Aix, and I like gnat more 
than OA)

Nicolas explained to me that what I want will not work with 3.15 or with 
3.4.2 :( but the explanation of libaddress2line was good news. 


> I would guess that the reason that Gnat.Sockets.Thin directly accesses via
> Import is that it assumes no tasking issues. In any case, why access this
> directly? You're just asking for trouble, by making yourself rediscover
> things that the binding writers already did.
I dont' use gnat.sockets directly, I use a 10 year old homemade interface, 
that works with other compilers and operating systems, and won't break legacy 
code in production on several sites. 
The sample I sent was to illustrate my problem with known 'standardcode'

/Björn
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-18 16:34   ` Nicolas
@ 2005-01-18 18:54     ` Björn Lundin
  0 siblings, 0 replies; 10+ messages in thread
From: Björn Lundin @ 2005-01-18 18:54 UTC (permalink / raw)
  To: comp.lang.ada

tisdag 18 januari 2005 17:34 skrev Nicolas:
> If this is the file which was on sourceforge with an older version of
> binutils, it doesn't work with current binutils-2.15.91-20040904-1
> Link will be fine, but output of stacktrace will be corrupted.
> You have to build libaddr2line.a with corresponding binutils version (check
> binutils makefile)
>
Thank you
/Björn



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
  2005-01-18  0:33 ` Jeff C
@ 2005-01-18 18:55   ` Björn Lundin
  0 siblings, 0 replies; 10+ messages in thread
From: Björn Lundin @ 2005-01-18 18:55 UTC (permalink / raw)
  To: comp.lang.ada

tisdag 18 januari 2005 01:33 skrev Jeff C:
>
> I recommend you submit a bugzilla bug at the gcc site. At the very least
> this should be documented.
i will
/Björn



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Gnat 3.4.2 tasking errorcodes windows
       [not found]   ` <200501181952.49091.bnl@tiscali.se>
@ 2005-01-18 21:26     ` Stephen Leake
  0 siblings, 0 replies; 10+ messages in thread
From: Stephen Leake @ 2005-01-18 21:26 UTC (permalink / raw)
  To: comp.lang.ada

Björn Lundin <bnl@tiscali.se> writes:

> I'm (my company) is moving from Object Ada to Gnat, but this one is a 
> showstopper :( 

So call AdaCore (www.adacore.com) (formerly www.gnat.com) and ask for
evaluation support; they'll tell you how to fix the problem the right
way for their runtime. 

Then sign up for a support contract; it will be well worth it. They
provide the _best_ support I have ever had on any product.

> (We already did the transition on Aix, and I like gnat more than OA)

AdaCore will like hearing that!

-- 
-- Stephe




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-01-18 21:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-17 19:44 Gnat 3.4.2 tasking errorcodes windows Björn Lundin
2005-01-17 22:04 ` 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

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