comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: In memory Stream
  @ 2024-02-17 18:09  5%     ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2024-02-17 18:09 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> Note, that if you implement stream Read/Write as individual Windows
> messages it will become extremely slow. GNAT optimizes streaming of
> some built-in objects, e.g. String. But as a general case you should
> expect that streaming of any non-scalar object would cause multiple
> calls to Read/Write and thus multiple individual Windows messages.

Our motivation for the memory stream was the equivalent of this for
UDP messages; GNAT.Sockets behaves (behaved?) exactly like this, so we
buffered the result of 'Output & wrote the constructed buffer to the
socket; on the other side, we read the UDP message, stuffed its contents
into a memory stream, then let the client 'Input.

I can't remember at this distance in time, but I think I would have
liked to construct a memory stream on the received UDP packet rather
than copying the content; the compiler wouldn't let me. Perhaps worth
another try.

^ permalink raw reply	[relevance 5%]

* gnat -xdr flag confusion.
@ 2023-07-04 10:56  4% magardner2010
  0 siblings, 0 replies; 200+ results
From: magardner2010 @ 2023-07-04 10:56 UTC (permalink / raw)


I'm still working on the p2p one-to-many data streaming protocol thing 
(at https://github.com/smeagolthellama/szakdolgozat-notes/tree/main/ada) 
and I'm trying to get it to communicate with a C thing via the xdr 
protocol. I'm trying to transfer a Child_Set, where
```
     type Child_Number is range 0 .. 2;
     subtype Child_Index is Child_Number range 1 .. Child_Number'Last;

     type Child_Set is array (Child_Index) of GNAT.Sockets.Sock_Addr_Type;
```
With the help of chatGPT, I wrote the following xdr spec file:
```
const CHILD_NUMBER = 2;

typedef unsigned int uint32;
typedef unsigned char uint8;

enum family_type {
   FAMILY_INET = 0,
   FAMILY_INET6 = 1,
   FAMILY_UNIX = 2,
   FAMILY_UNSPEC = 3
};

union inet_addr_type switch (family_type family) {
   case FAMILY_INET:
     opaque sin_v4[4];
   case FAMILY_INET6:
     opaque sin_v6[16];
   default:
     void;
};

struct address_and_port{
   inet_addr_type addr;
   unsigned int port;
};

union sock_addr_type switch (family_type family) {
   case FAMILY_UNIX:
     string name<>;
   case FAMILY_INET:
     address_and_port anp4;
   case FAMILY_INET6:
     address_and_port anp6;
   case FAMILY_UNSPEC:
     void;
};

struct child_set {
   sock_addr_type child_set_array[CHILD_NUMBER];
};
```
and using rpcgen, generated a C thing to encode/decode the messages the 
ada program is sending.

However, if the ada code encodes the object with 'write, then it creates 
something about 4 bytes too short, and if I use 'output, it is parsed as 
starting with family_type 256, which is not a member of the enum. Given 
that the gnat documentation for the -xdr flag is literally two lines, I 
don't really know where to look for more information on what I'm doing 
wrong. My current hypotheses include the C code having the family type 
recorded too many times (but I don't know how to check or fix that in 
the .x file) or the ada code not encoding the data according to the xdr 
standard correctly (but I am using the flag, and neither 'write or 
'output fixes it).

^ permalink raw reply	[relevance 4%]

* Re: GNAT or Language Problems?
  2023-05-30 16:36  7% GNAT or Language Problems? Jeffrey R.Carter
@ 2023-06-17  7:28  0% ` Randy Brukardt
  0 siblings, 0 replies; 200+ results
From: Randy Brukardt @ 2023-06-17  7:28 UTC (permalink / raw)


Regarding your second problem, refer to AI22-0041-1.

Essentially, there are problems if predicates are involved. We changed the 
rule to require static compatibility (as a Binding Interpretation). I don't 
have the energy to look up what "static compatibility" requires in this case 
(enjoy figuring out 4.9.1). In some cases, it requires static matching, in 
others, it has weaker requirements.

It's possible that GNAT did something too strong when fixing this problem, 
as well.

I don't have the time or energy tonight to look into your other problem. 
(I'm waiting for a backup to finish, or I would have already gone home --  
since I only got back from Lisbon last night, I'm not equipped for my usual 
late night work...)

              Randy.

"Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not> wrote in message 
news:u558m9$1ub3o$1@dont-email.me...
> Here are a couple of things that recent versions of GNAT reject, and I 
> suspect that these are GNAT errors, but would appreciate input from 
> language lawyers to be sure. If they're not GNAT errors, then they seem 
> like things that make Ada less easy to use than I'd like.
>
> The first is gcc bug 108157 
> (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108157). GNAT.Sockets has
>
> package GNAT.Sockets is
>    ...
>    type Selector_Type is limited private;
>    ...
>    procedure Connect_Socket
>      (Socket   : Socket_Type;
>       Server   : Sock_Addr_Type;
>       Timeout  : Selector_Duration;
>       Selector : access Selector_Type := null;
>       Status   : out Selector_Status);
>    --  Connect Socket to the given Server address using Connect_Socket, 
> waiting
>    --  no longer than the given timeout duration. Status is set to 
> indicate
>    --  whether the operation completed successfully, timed out, or was 
> aborted.
>    --  If Selector is not null, the designated selector is used to wait 
> for the
>    --  socket to become available, else a private selector object is 
> created
>    --  by this procedure and destroyed before it returns. If Timeout is 
> 0.0,
>    --  no attempt is made to detect whether the connection has succeeded; 
> it
>    --  is up to the user to determine this using Check_Selector later on.
>    ...
> private
>    ...
>    type Selector_Type (Is_Null : Boolean := False) is limited record
>       case Is_Null is
>          when True =>
>             null;
>
>          when False =>
>             R_Sig_Socket : Socket_Type := No_Socket;
>             W_Sig_Socket : Socket_Type := No_Socket;
>             --  Signalling sockets used to abort a select operation
>       end case;
>    end record;
>    ...
> end GNAT.Sockets;
>
> Kazakov's GNAT.Sockets.Server had (since modified to work with recent 
> versions of GNAT)
>
> package GNAT.Sockets.Server is
>    ...
>    type Connections_Server is tagged limited private;
>    ...
> private
>    ...
>    procedure Do_Connect
>      (Listener : in out Connections_Server'Class;
>       Client   : in out Connection_Ptr);
>    ...
>    type Connections_Server is tagged limited record
>       --  limited because Selector_Type is limited
>       Selector : aliased Selector_Type;
>    end record;
>    ...
> end GNAT.Sockets.Server;
>
> and
>
> package body GNAT.Sockets.Server is
>    ...
>    procedure Do_Connect
>      (Listener : in out Connections_Server'Class;
>       Client   : in out Connection_Ptr)
>    is
>       Status : Selector_Status;
>    begin
>       Connect_Socket
>         (Socket   => Client.Socket,
>          Server   => Client.Client_Address,
>          Timeout  => 0.0,
>          Selector => Listener.Selector'Unchecked_Access,
>          Status   => Status);
>    end Do_Connect;
>    ...
> end GNAT.Sockets.Server;
>
> Beginning with GNAT 12, the parameter association
>
>    Selector => Listener.Selector'Unchecked_Access,
>
> gives the error
>
>    object subtype must statically match designated subtype
>
> The FSF GNAT maintainers have decided not to change this, citing
>
>         --  Ada 2005 (AI-363): Require static matching when designated
>         --  type has discriminants and a constrained partial view, since
>         --  in general objects of such types are mutable, so we can't
>         --  allow the access value to designate a constrained object
>         --  (because access values must be assumed to designate mutable
>         --  objects when designated type does not impose a constraint).
>
> I think that those who use anonymous access types get what they deserve, 
> but had the parameter been mode "in out", there would be no problem. I 
> think that access parameters should work the same as "in out" parameters 
> as much as possible.
>
> So, GNAT or Ada problem, or is this a reasonable restriction?
>
> The other instance is in PragmARC.B_Strings 
> (https://github.com/jrcarter/PragmARC):
>
> package PragmARC.B_Strings is
>    type B_String (Max_Length : Positive := 1024) is tagged limited 
> private;
>    -- Default initial value is Null_B_String
>
>    Null_B_String : constant B_String; -- A string of zero characters
>    ...
> private -- PragmARC.B_Strings
>    type B_String (Max_Length : Positive := 1024) is tagged limited record
>       Len   : Natural := 0;
>       Value : String (1 .. Max_Length) := (1 .. Max_Length => ' ');
>    end record;
>
>    Null_B_String : constant B_String := (Max_Length => 1, others => <>);
> end PragmARC.B_Strings;
>
> Beginning with GNAT 13, an error on the full declaration of the constant 
> says that its subtype does not statically match that of the deferred 
> declaration.
> A workaround is to explicitly declare the discriminant value on both 
> declarations. Probably making the full declaration be (others => <>) would 
> also work.
>
> I don't see this in ARM 7.4; only constants of an anonymous access type 
> have to statically match. So this is probably a compiler error, but I 
> thought I would see what the experts think.
>
> -- 
> Jeff Carter
> "Ada is a management tool. It selects for software
> engineers and encourages the hackers to quit."
> Robert C. Leif
> 204 


^ permalink raw reply	[relevance 0%]

* GNAT or Language Problems?
@ 2023-05-30 16:36  7% Jeffrey R.Carter
  2023-06-17  7:28  0% ` Randy Brukardt
  0 siblings, 1 reply; 200+ results
From: Jeffrey R.Carter @ 2023-05-30 16:36 UTC (permalink / raw)


Here are a couple of things that recent versions of GNAT reject, and I suspect 
that these are GNAT errors, but would appreciate input from language lawyers to 
be sure. If they're not GNAT errors, then they seem like things that make Ada 
less easy to use than I'd like.

The first is gcc bug 108157 
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108157). GNAT.Sockets has

package GNAT.Sockets is
    ...
    type Selector_Type is limited private;
    ...
    procedure Connect_Socket
      (Socket   : Socket_Type;
       Server   : Sock_Addr_Type;
       Timeout  : Selector_Duration;
       Selector : access Selector_Type := null;
       Status   : out Selector_Status);
    --  Connect Socket to the given Server address using Connect_Socket, waiting
    --  no longer than the given timeout duration. Status is set to indicate
    --  whether the operation completed successfully, timed out, or was aborted.
    --  If Selector is not null, the designated selector is used to wait for the
    --  socket to become available, else a private selector object is created
    --  by this procedure and destroyed before it returns. If Timeout is 0.0,
    --  no attempt is made to detect whether the connection has succeeded; it
    --  is up to the user to determine this using Check_Selector later on.
    ...
private
    ...
    type Selector_Type (Is_Null : Boolean := False) is limited record
       case Is_Null is
          when True =>
             null;

          when False =>
             R_Sig_Socket : Socket_Type := No_Socket;
             W_Sig_Socket : Socket_Type := No_Socket;
             --  Signalling sockets used to abort a select operation
       end case;
    end record;
    ...
end GNAT.Sockets;

Kazakov's GNAT.Sockets.Server had (since modified to work with recent versions 
of GNAT)

package GNAT.Sockets.Server is
    ...
    type Connections_Server is tagged limited private;
    ...
private
    ...
    procedure Do_Connect
      (Listener : in out Connections_Server'Class;
       Client   : in out Connection_Ptr);
    ...
    type Connections_Server is tagged limited record
       --  limited because Selector_Type is limited
       Selector : aliased Selector_Type;
    end record;
    ...
end GNAT.Sockets.Server;

and

package body GNAT.Sockets.Server is
    ...
    procedure Do_Connect
      (Listener : in out Connections_Server'Class;
       Client   : in out Connection_Ptr)
    is
       Status : Selector_Status;
    begin
       Connect_Socket
         (Socket   => Client.Socket,
          Server   => Client.Client_Address,
          Timeout  => 0.0,
          Selector => Listener.Selector'Unchecked_Access,
          Status   => Status);
    end Do_Connect;
    ...
end GNAT.Sockets.Server;

Beginning with GNAT 12, the parameter association

    Selector => Listener.Selector'Unchecked_Access,

gives the error

    object subtype must statically match designated subtype

The FSF GNAT maintainers have decided not to change this, citing

         --  Ada 2005 (AI-363): Require static matching when designated
         --  type has discriminants and a constrained partial view, since
         --  in general objects of such types are mutable, so we can't
         --  allow the access value to designate a constrained object
         --  (because access values must be assumed to designate mutable
         --  objects when designated type does not impose a constraint).

I think that those who use anonymous access types get what they deserve, but had 
  the parameter been mode "in out", there would be no problem. I think that 
access parameters should work the same as "in out" parameters as much as possible.

So, GNAT or Ada problem, or is this a reasonable restriction?

The other instance is in PragmARC.B_Strings (https://github.com/jrcarter/PragmARC):

package PragmARC.B_Strings is
    type B_String (Max_Length : Positive := 1024) is tagged limited private;
    -- Default initial value is Null_B_String

    Null_B_String : constant B_String; -- A string of zero characters
    ...
private -- PragmARC.B_Strings
    type B_String (Max_Length : Positive := 1024) is tagged limited record
       Len   : Natural := 0;
       Value : String (1 .. Max_Length) := (1 .. Max_Length => ' ');
    end record;

    Null_B_String : constant B_String := (Max_Length => 1, others => <>);
end PragmARC.B_Strings;

Beginning with GNAT 13, an error on the full declaration of the constant says 
that its subtype does not statically match that of the deferred declaration.
A workaround is to explicitly declare the discriminant value on both 
declarations. Probably making the full declaration be (others => <>) would also 
work.

I don't see this in ARM 7.4; only constants of an anonymous access type have to 
statically match. So this is probably a compiler error, but I thought I would 
see what the experts think.

-- 
Jeff Carter
"Ada is a management tool. It selects for software
engineers and encourages the hackers to quit."
Robert C. Leif
204

^ permalink raw reply	[relevance 7%]

* Re: ChatGPT
  @ 2023-03-31 11:04  4%     ` magardner2010
  0 siblings, 0 replies; 200+ results
From: magardner2010 @ 2023-03-31 11:04 UTC (permalink / raw)


On 31/03/2023 09:54, Dmitry A. Kazakov wrote:
> On 2023-03-31 01:00, Jeffrey R.Carter wrote:
>> On 2023-03-30 23:49, Anatoly Chernyshev wrote:
>>>
>>> What do you think?
>>
>> No doubt there are a large number of such programs in the training 
>> data. If it had simply regurgitated one of those, at least the program 
>> would have compiled. That it couldn't even do as good as that is not 
>> impressive.
> 
> Right. Fun would be adding qualifiers to the request. E.g. "in extended 
> precision", "taking arguments from user input" etc. Parroting works up 
> to some limit.
> 

I have been trying to get chatGPT to help me with a larger Ada project 
on and off for the past few months. It not only has no idea regarding 
what functions do and do not exist in a given library, but it sometimes 
doesn't even understand how private types or tasks work. I will admit, 
those are not necessarily super common, but given how easy Ada makes it 
to use them, I can honestly say that Ada is the only language in which I 
am comfortable writing multithreaded programs that require more 
sophistication than a simple fork() call.

So, yeah. ChatGPT knows the syntax of Ada, and it is familiar with 
Ada.Text_IO's more common functions. It knows about the existence of 
GNAT.Sockets and AdaSockets, but it has no idea on how to use them.

I would be quite confident that that is pretty much it as far as ChatGPT 
and Ada goes.

^ permalink raw reply	[relevance 4%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
  @ 2023-02-19  1:27  3%                             ` A.J.
  0 siblings, 0 replies; 200+ results
From: A.J. @ 2023-02-19  1:27 UTC (permalink / raw)


Thank you for all of the responses and discussion, it pointed me in the right direction!  The "chat server"[1] (if you could call it that) does work, and my friends and I were able to telnet into it and chat.  One of my friends even tried throwing things at the server to break it, but it didn't crash!

Dmitry, maintaining a list of clients was the vital part I was missing.  I played around with using synchronized queues and tasks, but ended up defaulting to an ordered map with a UID as the key and wrapped it in a protected type.  I couldn't get Send() to send more data than Available_To_Send (after calling it, Available_To_Send ended up returning 0, and continued to do so despite wrapping Send() in a loop), but increasing the send buffer to 8kb per connection worked fine.  I would simply loop through that ordered map each time I needed to send something to all of the clients.

I really like simple components, and it would be neat if the GNAT maintainers implement epoll in the backend for linux systems, kqueue for BSD and MacOS.  Any server I write will be for linux though anyway.  I'm also interested in trying to benchmark Simple Component's connections server (both pooled and standard) against epoll to see how it fares.  Perhaps the clever tasking that the Connections Server utilizes can keep up with epoll despite what GNAT.Sockets utilizes!

Regarding coroutines vs tasks, I think at a high level it's hard to differentiate, but at a lower level, when I think of tasks vs what a coroutine would be, I think of Go, and their "goroutines."[2]  Creating a task in Ada, at least on linux, ends up creating a pthread, and you get all of the overhead that comes with threading (it's initialized in the kernel).  coroutines are managed by the go runtime (I believe in user space) and have much less overhead to create or manage, since it's not creating a specific thread.

Ada 202x supports the "parallel" block[3] though I understand no runtime has utilized it yet-- would that end up being a coroutine or is it meant for something else?

[1] https://github.com/AJ-Ianozi/protohackers/tree/main/budget_chat/src
[2] https://www.geeksforgeeks.org/golang-goroutine-vs-thread/
[3] http://www.ada-auth.org/standards/22rm/html/RM-5-6-1.html

Kind regards,
AJ.

^ permalink raw reply	[relevance 3%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
    @ 2023-02-13 20:33  5% ` Daniel Norte de Moraes
  1 sibling, 0 replies; 200+ results
From: Daniel Norte de Moraes @ 2023-02-13 20:33 UTC (permalink / raw)


Em Tue, 7 Feb 2023 12:29:39 -0800 (PST), A.J. escreveu:

> Hello everyone,

Hi! Wellcome!

> 
> In an effort to better learn network programming in Ada, I've been
> working through the Protohacker Challenges (https://protohackers.com/),
> and the current challenge (number 3) is to create a chat server.
> 
> I am using a TCP Connections Server with Simple Components, specifically
> a Connection_State_Machine, but I've run into a problem.  I'm trying to
> send a message received via "procedure Process_Packet (Client : in out
> Server_Connection)" to all connected Clients.
> 
> My (potentially incorrect) thought on how to accomplish this is to
> iterate through all of the clients currently connected, and use Send to
> send the message received to those clients.  I've been struggling with
> how to actually do this though, since I couldn't use "function
> Get_Clients_Count (Listener : Connections_Server) return Natural" from
> within Process_Packets.
> 
> Another thought I had could be to just place every message received in a
> central queue, and then once all of the packets have been received, to
> then process that queue and send the results to every connected client.
> 
> I tried overriding "procedure On_Worker_Start (Listener : in out
> Connections_Server)", thinking that I could use it to read such a queue,
> but it never seemed to be called from within my program and I'm still
> unsure how to iterate through the Connection objects anyway.
> 
> Am I approaching this the right way, or am I missing something very
> obvious?  I've read the test files that came with Simple Components,
> including the data server but couldn't see a way to get each client to
> interact with each other.  If I didn't explain this well enough, please
> let me know, I'll be happy to clarify.
> 
> Kind regards,
> AJ.

 Do you is obliged to use gnat-sockets ?

 Adare_Net has support to syncronous IO multiplex; 
 With Adare_Net you can create virtually infinite groups of network pools 
to get and send data on demand. and you can discover if peers closed 
connections and others things too. you can use syncronous i/o 
multiplexing  groups of network pools in dedicate ada tasks (or similar)  
to get truly real-time network programming and apps.

Thanks!

https://github.com/danieagle/adare-net

https://github.com/danieagle/adare-net/blob/main/adare_net/src/adare_net-
sockets-polls.ads

Each poll_type has a limit of 255 entries (more than that can be very 
slower) But you can have as many poll_types as you want.

Thanks!

Best Whishes,
GrateFull, Dani.

^ permalink raw reply	[relevance 5%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
  2023-02-13 11:07  4%           ` Emmanuel Briot
  2023-02-13 11:57  5%             ` Dmitry A. Kazakov
@ 2023-02-13 16:40  3%             ` Jeremy Grosser <jeremy@synack.me>
  1 sibling, 0 replies; 200+ results
From: Jeremy Grosser <jeremy@synack.me> @ 2023-02-13 16:40 UTC (permalink / raw)


> epoll is definitely the modern approach on linux, until of course someone finds 
> something even better. epoll is fully thread safe too, which is very nice when 
> used from Ada. 

For high performance networking, io_uring [1] is the new kid on the block, but the API involves a scary amount of pointer manipulation, so I'm not convinced that it's safe to use yet.

While epoll is thread safe, there are some subtleties. If you register a listening socket with epoll, then call epoll_wait from multiple threads, more than one thread may be woken up when the socket has a waiting incoming connection to be accepted. Only one thread will get a successful return from accept(), the others will return EAGAIN. This wastes cycles if your server handles lots of incoming connections. The recently added (kernel >=4.5) EPOLLEXCLUSIVE flag enables a mutex that ensures the event is only delivered to a single thread.

> They also have strong concerns about platform-agnostic support, and epoll is linux-specific 
> at this point (likely also BSD). There exists multiple libraries out there that provide an API 
> common to multiple platforms, and that use epoll on linux. Maybe that's what would make 
> sense, but nowadays with Alire, I would expect someone to build a crate there rather than 
> AdaCore modify GNAT.Sockets.

On BSD, the kqueue [2] API provides similar functionality to epoll. I believe kqueue is a better design, but you use what your platform supports.

libev [3] is the library I see used most commonly for cross-platform evented I/O. It will use the best available polling syscalls on whatever platform it's compiled for. Unfortunately, it's composed mostly of C preprocessor macros.

I've already written an epoll binding [5] that's in the Alire index. GNAT.Sockets provides the types and bindings for the portable syscalls.

For the Protohackers puzzles, I've written a small evented I/O server using those bindings [6]. Note that this server does not use events for the send() calls yet, which may block, though in practice it isn't an issue with the size of the payloads used in this application. I do plan to refactor this to buffer data to be sent when the Writable (EPOLLOUT) event is ready.

So far, I've found tasks and coroutines to be unnecessary for these servers, though coroutines would make it possible to implement Ada.Streams compatible Read and Write procedures, providing a cleaner interface that doesn't expose callbacks to the user.

[1] https://lwn.net/Articles/776703/
[2] https://people.freebsd.org/~jlemon/papers/kqueue.pdf
[3] https://linux.die.net/man/3/ev
[4]  https://github.com/JeremyGrosser/epoll-ada
[5] https://github.com/JeremyGrosser/protohackers/blob/master/src/mini.adb

^ permalink raw reply	[relevance 3%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
  2023-02-13 11:07  4%           ` Emmanuel Briot
@ 2023-02-13 11:57  5%             ` Dmitry A. Kazakov
    2023-02-13 16:40  3%             ` Jeremy Grosser <jeremy@synack.me>
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2023-02-13 11:57 UTC (permalink / raw)


On 2023-02-13 12:07, Emmanuel Briot wrote:
> On Monday, February 13, 2023 at 11:55:10 AM UTC+1, Dmitry A. Kazakov wrote:
>> Well, if there is Linux kernel level support why it is not used in
>> socket select as it is in epoll? I would expect them do that at some
>> point or drop epoll... (:-))
> 
> Because in practice the linux developers don't get to modify such APIs, which
> are mandated by Posix, or Unix, or some RFC.
> So the API for select and poll will *never* change.

Well, the API does not really prescribe the actual implementation of 
fd_set. If you need that many elements in the set then using a bitmask 
and not having some bookkeeping to balance load will bit you at some 
point anyway.

> epoll is definitely the modern approach on linux, until of course someone finds
> something even better.  epoll is fully thread safe too, which is very nice when
> used from Ada.
> Using select() is totally outdated at this point, and means you can never handle
> more than 1000 simultaneous clients, and that only if you do not have other
> file descriptors open (database, files,...)

Well, it is indicative how outdated Linux always was. Asynchronous I/O 
was old news long *before* Linus even started his project... (:-))

> The person who developed GNAT.Sockets has left AdaCore a while ago, so "they" (which
> I assume is what your message was referring to) are actually unlikely to update that.

Yes, that is what I expect, a face lifting of Linux implementation of 
GNAT.Sockets.

> They also have strong concerns about platform-agnostic support, and epoll is linux-specific
> at this point (likely also BSD).

GNAT.Sockets is no thin bindings, I see little problem here. AFAIK BSD 
allows increasing FD_SETSIZE, but I am not sure.

> There exists multiple libraries out there that provide an API
> common to multiple platforms, and that use epoll on linux.  Maybe that's what would make
> sense, but nowadays with Alire, I would expect someone to build a crate there rather than
> AdaCore modify GNAT.Sockets.

That is an option too. However presently I cannot use Alire because last 
time I looked it did not support automated uploading, versioning and 
target dependencies through the GPR.

>> I'd like to have special Ada "tasks" acting as co-routines on top of
>> proper tasks yielding when the socket buffer is empty or full.
> 
> This is an approach we had discussed at AdaCore before I left.  There are multiple drawbacks
> here: the limited stack size for tasks by default (2MB), the fact that entries cannot return indefinite
> types, the fact that currently those tasks are assigned to OS threads (so too many of them does
> impact resource usage),...

My idea is to have these as pseudo-tasks scheduled by the Ada run-time 
and not mapped onto any OS threads. A proper thread would pick up such a 
task and run it until it yields. The crucial point is to use the stack 
of the pseudo-task in place of the thread's stack or backing it up and 
cleaning the portion of the stack at the point of yielding, whatever.

> A colleague had found an external library that would provide several stacks and thus let people
> implement actual co-routines.  We did not do much more work on that, but it was a nice proof
> of concept, and efficient.  I think things are mostly blocked now, as the ARG has been discussing
> these topics for quite a few years now.

I have an impression that ARG's view on co-routines totally ignores the 
use case of communication stacks and other cases state machines show 
their ugly faces...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
  2023-02-13 10:55  4%         ` Dmitry A. Kazakov
@ 2023-02-13 11:07  4%           ` Emmanuel Briot
  2023-02-13 11:57  5%             ` Dmitry A. Kazakov
  2023-02-13 16:40  3%             ` Jeremy Grosser <jeremy@synack.me>
  0 siblings, 2 replies; 200+ results
From: Emmanuel Briot @ 2023-02-13 11:07 UTC (permalink / raw)


On Monday, February 13, 2023 at 11:55:10 AM UTC+1, Dmitry A. Kazakov wrote:
> Well, if there is Linux kernel level support why it is not used in 
> socket select as it is in epoll? I would expect them do that at some 
> point or drop epoll... (:-))

Because in practice the linux developers don't get to modify such APIs, which
are mandated by Posix, or Unix, or some RFC.
So the API for select and poll will *never* change.

epoll is definitely the modern approach on linux, until of course someone finds
something even better.  epoll is fully thread safe too, which is very nice when
used from Ada.
Using select() is totally outdated at this point, and means you can never handle
more than 1000 simultaneous clients, and that only if you do not have other
file descriptors open (database, files,...)

The person who developed GNAT.Sockets has left AdaCore a while ago, so "they" (which
I assume is what your message was referring to) are actually unlikely to update that.
They also have strong concerns about platform-agnostic support, and epoll is linux-specific
at this point (likely also BSD).  There exists multiple libraries out there that provide an API
common to multiple platforms, and that use epoll on linux.  Maybe that's what would make
sense, but nowadays with Alire, I would expect someone to build a crate there rather than
AdaCore modify GNAT.Sockets.


> Yes, state machine is what I want to avoid. With complex layered 
> protocols it imposes incredible difficulties requiring auxiliary stacks 
> and buffers with errors almost intractable either by testing or by 
> formal proofs.

tell me about auxiliary stacks :-)  In practice, in my experience, you can have a single
incoming buffer which is used by one state, and then another when the first state is no
longer active,... so we do not need to have too many buffers, but that definitely is not
trivial.  Currently, I have a stack of iterators reading from a socket, buffering on top of that,
then decompressing LZ4 data, then decoding our binary encoding to Ada values.


> I'd like to have special Ada "tasks" acting as co-routines on top of 
> proper tasks yielding when the socket buffer is empty or full.

This is an approach we had discussed at AdaCore before I left.  There are multiple drawbacks
here: the limited stack size for tasks by default (2MB), the fact that entries cannot return indefinite
types, the fact that currently those tasks are assigned to OS threads (so too many of them does
impact resource usage),...

A colleague had found an external library that would provide several stacks and thus let people
implement actual co-routines.  We did not do much more work on that, but it was a nice proof
of concept, and efficient.  I think things are mostly blocked now, as the ARG has been discussing
these topics for quite a few years now.

^ permalink raw reply	[relevance 4%]

* Re: Broadcast / iterate to all Connection objects via Simple Components?
  @ 2023-02-13 10:55  4%         ` Dmitry A. Kazakov
  2023-02-13 11:07  4%           ` Emmanuel Briot
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2023-02-13 10:55 UTC (permalink / raw)


On 2023-02-13 09:44, Emmanuel Briot wrote:
>> sockets (socket select).
> 
> Have you taken a look at epoll(), on linux ?

The implementation is on top of GNAT.Sockets, so no.

> It is so much more natural to use, and so much more efficient in practice.
> The example I mentioned above (a server with 25_000 concurrent connections) cannot work with select (which only
> accepts file descriptors up to 1024), and is slow with poll (since the result of the latter is the number of events, and we
> need to iterate over all registered sockets every time).

Well, if there is Linux kernel level support why it is not used in 
socket select as it is in epoll? I would expect them do that at some 
point or drop epoll... (:-))

>> P.S. This poses difficulties for users, who see all communication turned
>> upside down being driven by arbitrary socket events rather than by the
>> protocol logic. This was a reason I argued for introducing co-routines
>> with task interface in Ada.
> 
> In my own code, I basically provide an epoll-based generic framework.  One of the formal parameters is a `Job_Type`
> with one primitive operation `Execute`.
> The latter is initially called when a new connection is established, and is expected to do as much non-blocking work
> as it can (Execute is run in one of the worker tasks).  When it cannot make progress, it returns a tuple (file_descriptor, type_of_event_to_wait_for)
> to indicate when it needs to be called again in the future, for instance some data became available to read on the
> specified file_descriptor.
> The intent is that the `Job_Type` is implemented as a state machine internally.

Yes, state machine is what I want to avoid. With complex layered 
protocols it imposes incredible difficulties requiring auxiliary stacks 
and buffers with errors almost intractable either by testing or by 
formal proofs.

> Of course, a state machine is one of the two ways I know (along with a task) to implement the equivalent of
> a co-routine in Ada.  So I 100% agree with you that co-routines would be very useful in simplifying user code,
> in particular in the scenario we are discussing here !

I'd like to have special Ada "tasks" acting as co-routines on top of 
proper tasks yielding when the socket buffer is empty or full.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: Sockets, Streams, and Element_Arrays: Much confusion
  2023-01-05  7:55  5% ` Daniel Norte de Moraes
@ 2023-01-05 10:35  5%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2023-01-05 10:35 UTC (permalink / raw)


On 2023-01-05 08:55, Daniel Norte de Moraes wrote:
> Em Sat, 31 Dec 2022 14:11:55 +0200, Mark Gardner escreveu:
>> At this point, I'm half-tempted to make my own binding, but as I've
>> never done that sort of thing before, I thought I'd ask the wisdom of
>> the Usenet if there is a way to convert a Stream_Element_Array into the
>> exotic types of Unsigned_16 and String.
> 
>   You are obliged to use gnat-sockets ?
>   No? then use https://github.com/danieagle/adare-net

The OP's question was about Stream_Element_Array being used for payload. 
In that regard there is no difference between GNAT.Sockets and the 
library you suggest.

P.S. I am not sure if the library supports socket select and setting all 
necessary socket flags (e.g. NODELAY).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: Sockets, Streams, and Element_Arrays: Much confusion
  2022-12-31 12:11  6% Sockets, Streams, and Element_Arrays: Much confusion Mark Gardner
  2022-12-31 13:11  0% ` Dmitry A. Kazakov
  2022-12-31 17:39  0% ` Simon Wright
@ 2023-01-05  7:55  5% ` Daniel Norte de Moraes
  2023-01-05 10:35  5%   ` Dmitry A. Kazakov
  2 siblings, 1 reply; 200+ results
From: Daniel Norte de Moraes @ 2023-01-05  7:55 UTC (permalink / raw)


Em Sat, 31 Dec 2022 14:11:55 +0200, Mark Gardner escreveu:
> At this point, I'm half-tempted to make my own binding, but as I've
> never done that sort of thing before, I thought I'd ask the wisdom of
> the Usenet if there is a way to convert a Stream_Element_Array into the
> exotic types of Unsigned_16 and String.

 You are obliged to use gnat-sockets ?
 No? then use https://github.com/danieagle/adare-net

 And Be Happy! (Enjoy!!)

 p.s.: see the client and server in udp in example diretory.
 p.s.: nowdays Adare_Net has a manual in pdf, too

 Thanks All,
 Dani.

^ permalink raw reply	[relevance 5%]

* Re: Sockets, Streams, and Element_Arrays: Much confusion
  2022-12-31 17:39  0% ` Simon Wright
@ 2022-12-31 19:36  4%   ` Mark Gardner
  0 siblings, 0 replies; 200+ results
From: Mark Gardner @ 2022-12-31 19:36 UTC (permalink / raw)


On 31/12/2022 19:39, Simon Wright wrote:
> [...]
> 
> The approach we adopted was to create a 'memory stream', which is a
> chunk of memory that you can treat as a stream (see for example
> ColdFrame.Memory_Streams at [1]). With Ada2022, you should be able to
> use Ada.Streams.Storage.Bounded[2].
> 

Wait, so if I know what shape my data is, and use a memory_stream (like 
the one in the Big Online Book of Linux Ada Programming chapter 11 [1]), 
I'm fine using Stream, in conjunction with Get_Address? That's 
wonderful. Not at all frustrated that I just wasted approximately three 
working days looking for a solution to a problem that didn't exist.

> Message'Write the record into the memory stream;
> transmit the written contents as one datagram.

I'm guessing with Memory_Stream'Write(Socket_Stream, Buffer);?

> 
> To read, create a memory stream large enough for the message you expect;
> read a datagram into the memory stream;
> Message'Read (Stream => the_memory_stream, Item => a_message);

Does this second buffer need to be added? If the datagram arrives (UDP), 
shouldn't GNAT.Sockets.Stream() be able to handle it?
> 
> You can use gnatbind's switch -xdr to "Use the target-independent XDR
> protocol for stream oriented attributes instead of the default
> implementation which is based on direct binary representations and is
> therefore target-and endianness-dependent".

Oh fun, I didn't think of that aspect. Thanks! Would I have to pass it 
as a command line flag, or would there be some kind of pragma I could use?

Thanks for the help so far, and happy new year!

[1] http://www.pegasoft.ca/resources/boblap/11.html#11.12

^ permalink raw reply	[relevance 4%]

* Re: Sockets, Streams, and Element_Arrays: Much confusion
  2022-12-31 12:11  6% Sockets, Streams, and Element_Arrays: Much confusion Mark Gardner
  2022-12-31 13:11  0% ` Dmitry A. Kazakov
@ 2022-12-31 17:39  0% ` Simon Wright
  2022-12-31 19:36  4%   ` Mark Gardner
  2023-01-05  7:55  5% ` Daniel Norte de Moraes
  2 siblings, 1 reply; 200+ results
From: Simon Wright @ 2022-12-31 17:39 UTC (permalink / raw)


Mark Gardner <magardner2017@gmail.com> writes:

> GNAT.Sockets gives me a Stream_Element_Array, which I can't find any
> documentation on how to make use of other than "You should also be
> able to get a Stream, which you should use instead" (About ten years
> ago, on this very newsgroup, somebody said not to use streams with
> UDP, or at least not GNAT.Sockets.Stream).

The reasoning behind the recommendation not to use streams with UDP was
as follows (there's a faint possibility that it no longer applies!)

If the data type you want to send is e.g.

   type Message is record
      Id  : Integer;
      Val : Boolean;
   end record;

and you create a datagram socket and from that a stream, then use
Message'Write to the stream, GNAT will transmit each component of
Message separately in canonical order (the order they're written in the
type declaration). This results in two datagrams being sent, one of 4
bytes and one of 1 byte.

If you take the same approach at the destination, Message'Read reads one
datagram of 4 bytes, and one of 1 byte, and it all looks perfect from the
outside. If the destination is expecting a 5 byte record, of course,
things won't work so well.

The approach we adopted was to create a 'memory stream', which is a
chunk of memory that you can treat as a stream (see for example
ColdFrame.Memory_Streams at [1]). With Ada2022, you should be able to
use Ada.Streams.Storage.Bounded[2].

Message'Write the record into the memory stream;
transmit the written contents as one datagram.

To read, create a memory stream large enough for the message you expect;
read a datagram into the memory stream;
Message'Read (Stream => the_memory_stream, Item => a_message);

You can use gnatbind's switch -xdr to "Use the target-independent XDR
protocol for stream oriented attributes instead of the default
implementation which is based on direct binary representations and is
therefore target-and endianness-dependent".

[1]
https://github.com/simonjwright/coldframe/blob/master/lib/coldframe-memory_streams.ads
[2] http://www.ada-auth.org/standards/22rm/html/RM-13-13-1.html#p25

^ permalink raw reply	[relevance 0%]

* Re: Sockets, Streams, and Element_Arrays: Much confusion
  @ 2022-12-31 14:16  5%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-12-31 14:16 UTC (permalink / raw)


On 2022-12-31 14:50, Mark Gardner wrote:
> On 31/12/2022 15:11, Dmitry A. Kazakov wrote:
>> On 2022-12-31 13:11, Mark Gardner wrote:
>>
>>> ...
>>
>> Stream_Element_Array is declared in Ada.Streams as
>>
>>     type Stream_Element_Array is
>>        array(Stream_Element_Offset range <>) of
>>           aliased Stream_Element;
>>
>> For communication purpose it is an array of octets. Your datagram is 
>> represented as a Stream_Element_Array or a slice of.
> 
> According to RM 13.13.1, "Stream_Element is mod implementation-defined" 
> which to me says there is no guarantee that they will be octets, unless 
> this is specified elsewhere?

GNAT.Sockets is GNAT-specific. All GNAT compilers have Stream_Element 8 
bits. I can imagine some DSP implementation with Stream_Element of 32 
bits. But realistically add

    pragma Assert (Stream_Element'Size >= 8);

and be done with that.

> So, how would I do this directly on the elements? I mean, if it is an 
> octet-array to a string, I expect an element-to-element copy, or type 
> conversion to work, but what about integers?

Hmm, it cannot be string. It is a string encoded in some specific way 
(usually most peculiar (:-)). Then you will have to decode it into your 
machine type e.g. Wide_String or String.

An UTF-8 string you could put into String ignoring Ada's Latin-1 stuff, 
as most people would do:

    function To_String (S : Stream_Element_Array) return String is
    begin
       return Result : String (1..S'Length) do
          for I in S'Range loop
             Result (Positive (I - S'First + 1) := Character'Val (S (I));
          end loop;
       end return;
    end To_String;

> Do I need to do something like
> My_Int:=Unsigned_8(octet(1))+2**8*Unsigned_8(octet(2));
> or whatever endianness demands? Or is this the time to learn how to use 
> Unchecked_Conversion?

There are many ways to convert Stream_Element_Array "in situ" to string. 
However, in network protocols you rarely have any strings at all. 
Usually it is some binary data you need to decode into some machine 
type. (So is String or Wide_String actually)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: Sockets, Streams, and Element_Arrays: Much confusion
  2022-12-31 12:11  6% Sockets, Streams, and Element_Arrays: Much confusion Mark Gardner
@ 2022-12-31 13:11  0% ` Dmitry A. Kazakov
    2022-12-31 17:39  0% ` Simon Wright
  2023-01-05  7:55  5% ` Daniel Norte de Moraes
  2 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2022-12-31 13:11 UTC (permalink / raw)


On 2022-12-31 13:11, Mark Gardner wrote:

> GNAT.Sockets gives me a Stream_Element_Array, which I can't find any 
> documentation on how to make use of other than "You should also be able 
> to get a Stream, which you should use instead" (About ten years ago, on 
> this very newsgroup, somebody said not to use streams with UDP, or at 
> least not GNAT.Sockets.Stream).

Stream_Element_Array is declared in Ada.Streams as

    type Stream_Element_Array is
       array(Stream_Element_Offset range <>) of
          aliased Stream_Element;

For communication purpose it is an array of octets. Your datagram is 
represented as a Stream_Element_Array or a slice of.

As for streams, yes, it does not make sense to use them for networking, 
unless you override all stream primitives. The reasons for that are

- non-portability of predefined primitives
- low efficiency for complex data types
- encoding inefficiency as well

You will need to handle some application protocol artifacts, checksums, 
counters, strange encodings, sequence number etc. It is easier to this 
directly on the Stream_Element_Array elements.

And, well, do not use UDP, expect for broadcasting. There is no reason 
to use it. For multicast consider delivery-safe protocols like PGM. For 
single cast use TCP/IP. (If you need low latency see the socket NO_DELAY 
option)

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Sockets, Streams, and Element_Arrays: Much confusion
@ 2022-12-31 12:11  6% Mark Gardner
  2022-12-31 13:11  0% ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: Mark Gardner @ 2022-12-31 12:11 UTC (permalink / raw)


Hello, I've been having a bit of difficulty doing some UDP socket 
programming in Ada. As outlined in my stackoverflow question here 
(https://stackoverflow.com/q/74953052/7105391), I'm trying to reply to 
messages I am getting over UDP.

GNAT.Sockets gives me a Stream_Element_Array, which I can't find any 
documentation on how to make use of other than "You should also be able 
to get a Stream, which you should use instead" (About ten years ago, on 
this very newsgroup, somebody said not to use streams with UDP, or at 
least not GNAT.Sockets.Stream).

Adasockets gives me a String, which I can work with, except it throws 
away the from data recvfrom gives it, apparently making it impossible to 
reply to the querying address.

At this point, I'm half-tempted to make my own binding, but as I've 
never done that sort of thing before, I thought I'd ask the wisdom of 
the Usenet if there is a way to convert a Stream_Element_Array into the 
exotic types of Unsigned_16 and String.

^ permalink raw reply	[relevance 6%]

* Re: SimpleComponents / MQTT
  2022-07-01 11:05  6%     ` Dmitry A. Kazakov
@ 2022-07-01 13:22  0%       ` slos
  0 siblings, 0 replies; 200+ results
From: slos @ 2022-07-01 13:22 UTC (permalink / raw)


Le vendredi 1 juillet 2022 à 13:05:43 UTC+2, Dmitry A. Kazakov a écrit :
> On 2022-07-01 10:51, slos wrote: 
> > Le mercredi 29 juin 2022 à 17:00:20 UTC+2, Dmitry A. Kazakov a écrit : 
> >>> Could you please have a look on that behaviour ? 
> >> It means that the other side (mosquitto) dropped the connection. 
> >> 
> >> One possible case is when ping timeout (Keep_Alive) is set but the 
> >> client was silent for the period of time. You should send ping before 
> >> the timeout expires or reconnect. 
> > Hello Dmitry, 
> > Thanks for your answer. 
> > I had set the "Keep_Alive" parameter : 
> > Send_Connect (Client, "TestMQTTclient", Keep_Alive => 60.0); 
> > 
> > If it is not set, one gets : 
> > MQTT client test 1 started 
> > MQTT client connected to test.mosquitto.org 
> > Connect rejected identifier rejected
> AFAIK it is a bug in mosquitto that it does not accept zero ping interval.
> > Indeed, I get exceptions because of this line : 
> > GNAT.Exception_Traces.Trace_On (GNAT.Exception_Traces.Every_Raise); 
> > 
> > I have played with mosquitto on localhost and wanted to see what would happen if the broker was shut down. 
> > Problem is that I could not get an information or exception in this case.
> It is unrelated to MQTT, just general TCP/IP behavior: 
> 
> 1. If one side (broker) shuts the socket down, the other side's (the 
> client) read ends with 0 payload. 
> 
> 2. If it crashes, the socket is closed and nothing happens until some 
> OS-specific timeout (might be seconds) and then the socket get shut down 
> and see above. 
> 
> The second case could be improved by setting KEEP_ALIVE on the socket. 
> Not to confuse with MQTT's ping, which is rather a useless thing.
> > So I had to add a check of the ping response in order to know if the broker is still there but maybe you have a better idea.
> It is reverse. Ping is a sort of watchdog on the server side to drop off 
> sluggish clients. 
> 
> If you want to speed up recognition that the broker had crashed use 
> TCP/IP KEEP_ALIVE option. Differently to ping it requires nothing from 
> you, being implemented transparently by the TCP/IP stack.
> >> With SSL/TLS you could probably map users to certificates/keys and drop 
> >> user/password, but for the server side it is easier to have them in 
> >> order to maintain user access rights. 
> > I use Gnoga as well and there are explanations on how to use SSL/TLS in Gnoga's documentation. 
> > I wondered if such explanations where available to use with MQTT as well.
> There is nothing specific to MQTT. All protocol implementations in 
> Simple Components (MQTT, HTTP, SMTP etc) use a connection server object. 
> If you take one like GNAT.Sockets.Server.Secure (GNUTLS) or 
> GNAT.Sockets.Server.OpenSSL (OpenSSL) with MQTT client/server and that 
> will give you MQTTS.
> > Unrelated, you have created your packages as childs of GNAT.Sockets.
> GNAT.Sockets.Server needs access to the private part of GNAT.Sockets. 
> That is the reason.
> > Although it seems not a problem for using them, the applications can be built, that seems to be a problem for code navigation with GNAT Studio, even in latest version. 
> > Is that a limitation of the tool or something I'm doing wrong ?
> It never worked well, if you mean "go to declaration" stuff. I know that 
> AdaCore is changing the cross-reference stuff. Maybe it will get better 
> at some point. (before getting worse first! (:-))
> > By the way, thanks to your MQTT implementation, this demo application is sending SIEMENS S7 PLC data to the mosquitto broker : 
> > https://gitlab.com/ada-for-automation/ada-for-automation/-/tree/master/demo/142%20a4a_k0_S7
> Nice. 
> 
> P.S. In the proprietary code we rather use iTOT for SPS communication 
> which is far more efficient. Unfortunately it cannot be included into 
> the Simple Components.
> -- 
> Regards, 
> Dmitry A. Kazakov 
> http://www.dmitry-kazakov.de
Hi Dmitry,

Thanks a lot for the provided information. Much appreciated !

Best Regards,
Stéphane
https://www.ada4automation.org/

^ permalink raw reply	[relevance 0%]

* Re: SimpleComponents / MQTT
  2022-07-01  8:51  4%   ` slos
@ 2022-07-01 11:05  6%     ` Dmitry A. Kazakov
  2022-07-01 13:22  0%       ` slos
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2022-07-01 11:05 UTC (permalink / raw)


On 2022-07-01 10:51, slos wrote:
> Le mercredi 29 juin 2022 à 17:00:20 UTC+2, Dmitry A. Kazakov a écrit :
>>> Could you please have a look on that behaviour ?
>> It means that the other side (mosquitto) dropped the connection.
>>
>> One possible case is when ping timeout (Keep_Alive) is set but the
>> client was silent for the period of time. You should send ping before
>> the timeout expires or reconnect.
> Hello Dmitry,
> Thanks for your answer.
> I had set the "Keep_Alive" parameter :
> Send_Connect (Client, "TestMQTTclient", Keep_Alive => 60.0);
> 
> If it is not set, one gets :
> MQTT client test 1 started
> MQTT client connected to test.mosquitto.org
> Connect rejected identifier rejected

AFAIK it is a bug in mosquitto that it does not accept zero ping interval.

> Indeed, I get exceptions because of this line :
> GNAT.Exception_Traces.Trace_On (GNAT.Exception_Traces.Every_Raise);
> 
> I have played with mosquitto on localhost and wanted to see what would happen if the broker was shut down.
> Problem is that I could not get an information or exception in this case.

It is unrelated to MQTT, just general TCP/IP behavior:

1. If one side (broker) shuts the socket down, the other side's (the 
client) read ends with 0 payload.

2. If it crashes, the socket is closed and nothing happens until some 
OS-specific timeout (might be seconds) and then the socket get shut down 
and see above.

The second case could be improved by setting KEEP_ALIVE on the socket. 
Not to confuse with MQTT's ping, which is rather a useless thing.

> So I had to add a check of the ping response in order to know if the broker is still there but maybe you have a better idea.

It is reverse. Ping is a sort of watchdog on the server side to drop off 
sluggish clients.

If you want to speed up recognition that the broker had crashed use 
TCP/IP KEEP_ALIVE option. Differently to ping it requires nothing from 
you, being implemented transparently by the TCP/IP stack.

>> With SSL/TLS you could probably map users to certificates/keys and drop
>> user/password, but for the server side it is easier to have them in
>> order to maintain user access rights.
> I use Gnoga as well and there are explanations on how to use SSL/TLS in Gnoga's documentation.
> I wondered if such explanations where available to use with MQTT as well.

There is nothing specific to MQTT. All protocol implementations in 
Simple Components (MQTT, HTTP, SMTP etc) use a connection server object. 
If you take one like GNAT.Sockets.Server.Secure (GNUTLS) or 
GNAT.Sockets.Server.OpenSSL (OpenSSL) with MQTT client/server and that 
will give you MQTTS.

> Unrelated, you have created your packages as childs of GNAT.Sockets.

GNAT.Sockets.Server needs access to the private part of GNAT.Sockets. 
That is the reason.

> Although it seems not a problem for using them, the applications can be built, that seems to be a problem for code navigation with GNAT Studio, even in latest version.
> Is that a limitation of the tool or something I'm doing wrong ?

It never worked well, if you mean "go to declaration" stuff. I know that 
AdaCore is changing the cross-reference stuff. Maybe it will get better 
at some point. (before getting worse first! (:-))

> By the way, thanks to your MQTT implementation, this demo application is sending SIEMENS S7 PLC data to the mosquitto broker :
> https://gitlab.com/ada-for-automation/ada-for-automation/-/tree/master/demo/142%20a4a_k0_S7

Nice.

P.S. In the proprietary code we rather use iTOT for SPS communication 
which is far more efficient. Unfortunately it cannot be included into 
the Simple Components.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: SimpleComponents / MQTT
  2022-06-29 15:00  0% ` Dmitry A. Kazakov
@ 2022-07-01  8:51  4%   ` slos
  2022-07-01 11:05  6%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: slos @ 2022-07-01  8:51 UTC (permalink / raw)


Le mercredi 29 juin 2022 à 17:00:20 UTC+2, Dmitry A. Kazakov a écrit :
> > Could you please have a look on that behaviour ?
> It means that the other side (mosquitto) dropped the connection. 
> 
> One possible case is when ping timeout (Keep_Alive) is set but the 
> client was silent for the period of time. You should send ping before 
> the timeout expires or reconnect.
Hello Dmitry,
Thanks for your answer.
I had set the "Keep_Alive" parameter :
Send_Connect (Client, "TestMQTTclient", Keep_Alive => 60.0);

If it is not set, one gets :
MQTT client test 1 started
MQTT client connected to test.mosquitto.org
Connect rejected identifier rejected

Indeed, I get exceptions because of this line :
GNAT.Exception_Traces.Trace_On (GNAT.Exception_Traces.Every_Raise);

I have played with mosquitto on localhost and wanted to see what would happen if the broker was shut down.
Problem is that I could not get an information or exception in this case.

So I had to add a check of the ping response in order to know if the broker is still there but maybe you have a better idea.

> > It should be possible to use user name and password but I haven't found how with your implementation. 
> > Could you tell please ?
> User and password are set after TCP/IP connection established during 
> handshake (see Send_Connect).
> > Of course, one should use TLS in this case. Is it feasible and how ?
> Well, MQTT does not require SSL/TLS for user/password during the 
> handshake. But logically yes, without a secure layer (e.g. provided 
> GNUTLS or OpenSSL connection handlers) it makes little sense. 
> 
> With SSL/TLS you could probably map users to certificates/keys and drop 
> user/password, but for the server side it is easier to have them in 
> order to maintain user access rights. 
I use Gnoga as well and there are explanations on how to use SSL/TLS in Gnoga's documentation.
I wondered if such explanations where available to use with MQTT as well.

> (In my opinion MQTT is a toy thing not be used for serious applications, 
> though I admit, it is hugely popular)
Well, there are many toy things used for serious applications ! ;-)
"Ada for Automation" being one of those... created by an Ada amateur...

> > Also, how to provide a timestamp ?
> Hmm, where? MQTT is totally low-level. There are only string topic and 
> string messages, nothing else. Otherwise? if you want to send a time 
> stamp in a message use FILETIME or UNIX time epoch and pack 8 bytes UTC 
> offset to (low or big endian) in the corresponding resolution. MQTT 
> payload need not to be printable. 
You are right. I remember having played with nodes in Node-RED where there was something.
But from :
https://github.com/persan/mosquitto-ada
   C.Publish (Mid => null, Topic => "test", Payload => "[" & GNAT.Time_Stamp.Current_Time & "] Hej", Qos => QOS_0, Retain => False);
or :
http://mosquitto.org/man/mosquitto_pub-1.html
   Publish timestamp and temperature information to a remote host on a non-standard port and QoS 0:
    mosquitto_pub -h 192.168.1.1 -p 1885 -t sensors/temperature -m "1266193804 32"
The timestamp is just part of the message string.

Unrelated, you have created your packages as childs of GNAT.Sockets.
Although it seems not a problem for using them, the applications can be built, that seems to be a problem for code navigation with GNAT Studio, even in latest version.
Is that a limitation of the tool or something I'm doing wrong ?

By the way, thanks to your MQTT implementation, this demo application is sending SIEMENS S7 PLC data to the mosquitto broker :
https://gitlab.com/ada-for-automation/ada-for-automation/-/tree/master/demo/142%20a4a_k0_S7

> 
> -- 
> Regards, 
> Dmitry A. Kazakov 
> http://www.dmitry-kazakov.de
Best Regards,
Stéphane
https://www.ada4automation.org/

^ permalink raw reply	[relevance 4%]

* Re: SimpleComponents / MQTT
  2022-06-29 10:15  6% SimpleComponents / MQTT slos
@ 2022-06-29 15:00  0% ` Dmitry A. Kazakov
  2022-07-01  8:51  4%   ` slos
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2022-06-29 15:00 UTC (permalink / raw)


On 2022-06-29 12:15, slos wrote:

> I'm having fun playing with SimpleComponents MQTT implementation and I have some questions...
> 
> I'm on Debian Sid using :
> GNAT Studio 23.0w (20220512) hosted on x86_64-pc-linux-gnu
> GNAT 11.3.0 targeting x86_64-linux-gnu
> 
> GNAT Studio
> (c) 2001-2022 AdaCore
> 
> Building the test application is fine using :
> gprbuild -d -P/home/slos/Ada/SimpleComponents/components_4_62/test_components/components-connections_server-mqtt-test_mqtt.gpr -XObject_Dir=. -Xarch=x86_64 -XTarget_OS=Windows -XDevelopment=Debug -XLegacy=Ada2012 -XAtomic_Access=auto -XTasking=Multiple -XTraced_objects=Off /home/slos/Ada/SimpleComponents/components_4_62/test_components/test_mqtt_client.adb
> 
> Running using either "test.mosquitto.org" or local mosquitto gives an exception after some messages received :
> Exception raised
> raised GNAT.SOCKETS.SERVER.CONNECTION_ERROR : gnat-sockets-server.adb:1145
> 
> I don't recall having got exceptions with Gnat Community 2021 on Windows.
> Could you please have a look on that behaviour ?

It means that the other side (mosquitto) dropped the connection.

One possible case is when ping timeout (Keep_Alive) is set but the 
client was silent for the period of time. You should send ping before 
the timeout expires or reconnect.

> It should be possible to use user name and password but I haven't found how with your implementation.
> Could you tell please ?

User and password are set after TCP/IP connection established during 
handshake (see Send_Connect).

> Of course, one should use TLS in this case. Is it feasible and how ?

Well, MQTT does not require SSL/TLS for user/password during the 
handshake. But logically yes, without a secure layer (e.g. provided 
GNUTLS or OpenSSL connection handlers) it makes little sense.

With SSL/TLS you could probably map users to certificates/keys and drop 
user/password, but for the server side it is easier to have them in 
order to maintain user access rights.

(In my opinion MQTT is a toy thing not be used for serious applications, 
though I admit, it is hugely popular)

> Also, how to provide a timestamp ?

Hmm, where? MQTT is totally low-level. There are only string topic and 
string messages, nothing else. Otherwise? if you want to send a time 
stamp in a message use FILETIME or UNIX time epoch and pack 8 bytes UTC 
offset to (low or big endian) in the corresponding resolution. MQTT 
payload need not to be printable.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* SimpleComponents / MQTT
@ 2022-06-29 10:15  6% slos
  2022-06-29 15:00  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: slos @ 2022-06-29 10:15 UTC (permalink / raw)


Hello Dmitry,
I'm having fun playing with SimpleComponents MQTT implementation and I have some questions...

I'm on Debian Sid using :
GNAT Studio 23.0w (20220512) hosted on x86_64-pc-linux-gnu
GNAT 11.3.0 targeting x86_64-linux-gnu

GNAT Studio
(c) 2001-2022 AdaCore

Building the test application is fine using :
gprbuild -d -P/home/slos/Ada/SimpleComponents/components_4_62/test_components/components-connections_server-mqtt-test_mqtt.gpr -XObject_Dir=. -Xarch=x86_64 -XTarget_OS=Windows -XDevelopment=Debug -XLegacy=Ada2012 -XAtomic_Access=auto -XTasking=Multiple -XTraced_objects=Off /home/slos/Ada/SimpleComponents/components_4_62/test_components/test_mqtt_client.adb

Running using either "test.mosquitto.org" or local mosquitto gives an exception after some messages received :
Exception raised
raised GNAT.SOCKETS.SERVER.CONNECTION_ERROR : gnat-sockets-server.adb:1145

I don't recall having got exceptions with Gnat Community 2021 on Windows.
Could you please have a look on that behaviour ?

It should be possible to use user name and password but I haven't found how with your implementation.
Could you tell please ?

Of course, one should use TLS in this case. Is it feasible and how ?

Also, how to provide a timestamp ?

Thanks a lot for your kind support.

Best Regards,
Stéphane
https://www.ada4automation.org/

^ permalink raw reply	[relevance 6%]

* ANN: Simple Components v4.62
@ 2022-05-21 10:03  5% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-05-21 10:03 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- Pipe stream implementation added;

- GNAT 12.1 bugs worked around in several package, in particular, in 
GNAT.Sockets.Server;

- Bug fix in Generic_Set procedure Replace, parameter Updated unset;

- Bug fix in Tables.UTF8_Names procedure Replace, parameter Offset unset 
under circumstances.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: file "synchronization-interprocess.ads" not found
  2022-02-01 19:37  8%   ` hreba
@ 2022-02-01 20:11  6%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2022-02-01 20:11 UTC (permalink / raw)


On 2022-02-01 20:37, hreba wrote:
> On 29.01.22 20:09, Dmitry A. Kazakov wrote:
>> On 2022-01-29 17:31, hreba wrote:
> --- snip ---
>>> Source_Dirs. As I am trying to write a plugin, this is a library 
>>> project of kind relocatable.
>>
>> Do you have your own gpr-file? The with-section and the private part 
>> of synchronization-interprocess.ads is OS-dependent. In the provided 
>> gpr-file it is selected by the Target_OS project scenario.
>>
>> The source file for Linux is in the subdirectory os/linux.
>>
>> Similarly, when using ODBC, you must select the right OS driver and 
>> 32- vs 64-bit because ODBC API depends on the choice.
>>
>> The list of scenarios is here:
>>
>>     http://www.dmitry-kazakov.de/ada/components.htm#19
>>
> 
> Using the component's project file is not possible because
> 
> -- 
> driven_pend.gpr:7:17: shared library project "driven_pend" cannot import 
> project "tables" that is not a shared library project
> -- 

Actually it is possible to circumvent using gcc linker switches like 
--whole-archive. But admittedly, it is too complicated.

> so I included in my project file's Source_Dirs the Components 
> subdirectories
>   - os/linux
>   - odbc/unixodbc/x86_64
> what resulted in

Why do you want to include everything? I guess that you do not use

    for Source_Files

in your project and this includes everything of which you likely need none.

If you look at the sources you will find lots of independent projects. 
There exist many gpr files each of which has a file list

    for Source_Files use (...);

Take only what you actually need. Copy the file lists from there and put 
them into your for Source_Files use. This will exclude things you do not 
need. Start with only your files and incrementally add lists from the 
projects containing missing files.

> -- 
> gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
> file "g-socser.ads" not found
> gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
> "GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN.UNSIGNEDS (body)" 
> depends on 
> "GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN.UNSIGNEDS (spec)"
> gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
> "GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN.UNSIGNEDS (spec)" 
> depends on "GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN (spec)"
> gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
> "GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN (spec)" depends on 
> "GNAT.SOCKETS.CONNECTION_STATE_MACHINE (spec)"
> gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
> "GNAT.SOCKETS.CONNECTION_STATE_MACHINE (spec)" depends on 
> "GNAT.SOCKETS.SERVER (spec)"
> -- > Executing
>      find -name "g-socser.ads"
> in directory Components didn't return any result.

g-socser.ads is the standard AdaCore's GNAT.Sockets package. You must 
have it, if GNAT is installed.

I guess that the actual problem is that it cannot find 
gnat-sockets-server.ads which again dependends on the GNAT compiler 
capabilities. There are 3 incarnations of:

1. Standard Ada in atomic-access/ada

2. Ada incapable of 64-bit atomic access in atomic-access/gcc

3. Ada incapable of 64-bit atomic access yet using 64-bit for stream 
data types. This one is in atomic-access/gcc-long-offsets

On a 64-bit machine it is #1. On a 32-bit machine it is most likely #3.

But, again, you probably do not need any of these.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: file "synchronization-interprocess.ads" not found
  @ 2022-02-01 19:37  8%   ` hreba
  2022-02-01 20:11  6%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: hreba @ 2022-02-01 19:37 UTC (permalink / raw)


On 29.01.22 20:09, Dmitry A. Kazakov wrote:
> On 2022-01-29 17:31, hreba wrote:
--- snip ---
>> Source_Dirs. As I am trying to write a plugin, this is a library 
>> project of kind relocatable.
> 
> Do you have your own gpr-file? The with-section and the private part of 
> synchronization-interprocess.ads is OS-dependent. In the provided 
> gpr-file it is selected by the Target_OS project scenario.
> 
> The source file for Linux is in the subdirectory os/linux.
> 
> Similarly, when using ODBC, you must select the right OS driver and 32- 
> vs 64-bit because ODBC API depends on the choice.
> 
> The list of scenarios is here:
> 
>     http://www.dmitry-kazakov.de/ada/components.htm#19
> 

Using the component's project file is not possible because

--
driven_pend.gpr:7:17: shared library project "driven_pend" cannot import 
project "tables" that is not a shared library project
--

so I included in my project file's Source_Dirs the Components subdirectories
  - os/linux
  - odbc/unixodbc/x86_64
what resulted in

--
gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
file "g-socser.ads" not found
gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
"GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN.UNSIGNEDS (body)" 
depends on 
"GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN.UNSIGNEDS (spec)"
gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
"GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN.UNSIGNEDS (spec)" 
depends on "GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN (spec)"
gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
"GNAT.SOCKETS.CONNECTION_STATE_MACHINE.LITTLE_ENDIAN (spec)" depends on 
"GNAT.SOCKETS.CONNECTION_STATE_MACHINE (spec)"
gnat-sockets-connection_state_machine-little_endian-unsigneds.ads:28:60: 
"GNAT.SOCKETS.CONNECTION_STATE_MACHINE (spec)" depends on 
"GNAT.SOCKETS.SERVER (spec)"
--

Executing
	find -name "g-socser.ads"
in directory Components didn't return any result.

Regards,
-- 
Frank Hrebabetzky, Kronach	+49 / 9261 / 950 0565

^ permalink raw reply	[relevance 8%]

* ANN: Simple Components for Ada v4.59
@ 2021-11-06 12:04  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-11-06 12:04 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- The primitive operation Clear was added to GNAT.Sockets.Server.Connect;

- Julia bindings moved to the version 1.6.3;

- The functions Eval_char_array, Get_Safe_Restore, Load_File_String, 
Set_Safe_Restore were added to Julia bindings;

- Functions To_Julia and Value added to Julia bindings for Ada types 
Time and Day_Duration;

- To_Julia defined on tuples fixed when types of elements are not 
directly visible.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* ANN: Simple Components v
@ 2021-01-13 12:01  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2021-01-13 12:01 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- The packages Universally_Unique_Identifiers and 
Universally_Unique_Identifiers.Edit were added to support UUID;
- Reboot procedure was added to the package 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: Read/write access to Unix character devices
  2020-12-21  4:59  6% Read/write access to Unix character devices philip...@gmail.com
  2020-12-22  1:23  5% ` Randy Brukardt
@ 2020-12-28 13:26  0% ` Björn Lundin
  1 sibling, 0 replies; 200+ results
From: Björn Lundin @ 2020-12-28 13:26 UTC (permalink / raw)


Den 2020-12-21 kl. 05:59, skrev philip...@gmail.com:
> Lately I have been working with Unix (really Linux, FreeBSD, and OpenBSD) character devices (these happen to be USB raw HID devices, but the problem is more general than that).  The way these work is that each hardware device has a character device node file in /dev/, like /dev/hidraw1.  You open the file for both read and write access.  Then you can send a command to the device by writing a binary blob and get a response by subsequently reading a binary blob.  For what I am doing, it is important not to block on reads forever if there is not response forthcoming, so I need at least read timeouts.
> 
> So far, I have been binding the C library functions open(), close(), read(), write(), and poll() with pragma Import.  That works, but I have wondered if there is some way of accomplishing the same thing more portably.  The packages GNAT.Sockets and GNAT.Serial_Communicatons can be viewed as special case solutions, but I would like a general solution.
> 
> What I would really like is Ada.Sequential_IO with InOut_File and a timeout mechanism, perhaps like the select() wrapper in GNAT.Sockets.
> 
> So far I haven't found anything in the Ada. or GNAT. that supports InOut_File semantics (other than Direct_IO) let alone timeouts.  Does anybody have any suggestions?
> 
> Phil
> 


I'm perhaps too late for a useful suggestion, but I use this pattern 
when I pass messages through named pipes between unrelated processes.


The reading process starts a task T1 which reads the pipe blocking.
When data arrives it puts it in a list via a protected object,
then it goes back to read blocking again.


T1:
loop
   read device
   PO.Put(data from device)
   exit when data is special shutdown-message
end loop


The main of the process does a IO.receive which in turn does a 'Get' on 
a protected object where 'get' is an entry of the PO with condition 
list.count > 0

main:
   loop
     IO.Receive(Data, Timeout)
     case Data.id is
       when timeout => DoSomethingElse
       when  reply  => Treat(Data)
       when shutdown => exit
     end case
   end loop;


So - the main hangs on receive until a message arrives.
And with receive, there is an optional timeout, that if > 0, starts a 
new task T2 that is a timer. If no message has arrived within time,
a timeout message is put by T2 into the list, and the T2 dies.

pkg IO
procedure Receive (msg out: some type ; timeout : duration := 0.0) is
   TTP : Timer_Task_Pointer_Type;
   TO  : aliased Duration := Timeout;
begin
  if Timeout > 0.0 then
    TTP := new Timer_Task_Type(TO'Unchecked_access);
    PO.Get(msg); <-- we hang here until msg from device or timeout from T2
    begin
      TTP.Stop;
      loop
        exit when TTP.all'Terminated;
        delay 0.0001; --workaround gnat bug
      end loop;
    exception
      when Tasking_Error => null;
    end;
    Free(TTP);
  end if;
end receive;


T2
   task type Timer_Task_Type(Timeout_Time : access Duration) is
     entry Stop;
   end Timer_Task_Type;

   task body Timer_Task_Type is
     Timeout_Message : Message_Type;
   begin
     select
       delay Timeout_Time.all;
       Timeout_Message.Msg.Header.Identity := Time_Out_Identity;
       PO.Put(Timeout_Message);
     or
       accept Stop;
     end select;
   end Timer_Task_Type;

   type Timer_Task_Pointer_Type is access all Timer_Task_Type;

   procedure Free is new 
Unchecked_Deallocation(Timer_Task_Type,Timer_Task_Pointer_Type);




Main is released by this timeout message and can do other things while 
T1 still hangs on the device waiting for data.


To exit the process I post a special exit message that the task puts 
into the list and then exits its task loop, thus dies.

Then the process shuts down when it acts upon the shutdown message.

In your case you may not be able to send such a message to the task, but
that does perhaps not matter. abort the task when shutting down your 
process - if you ever shut it down that is.


-- 
Björn

^ permalink raw reply	[relevance 0%]

* Re: Read/write access to Unix character devices
  2020-12-21  4:59  6% Read/write access to Unix character devices philip...@gmail.com
@ 2020-12-22  1:23  5% ` Randy Brukardt
  2020-12-28 13:26  0% ` Björn Lundin
  1 sibling, 0 replies; 200+ results
From: Randy Brukardt @ 2020-12-22  1:23 UTC (permalink / raw)


I would use Stream_IO for this, but you'd need help from your implementer to 
get timeouts/nonblocking I/O. If they have them, they'd be some sort of Form 
parameter (that's what the typically ignored Form parameter is for).

Stream_IO is a lot more flexible that Sequential_IO and Direct_IO. (Some 
implementations implement those older Ada 83 packages in terms of 
Stream_IO.)

                          Randy.

"philip...@gmail.com" <philip.munts@gmail.com> wrote in message 
news:6ece98b8-a82e-40e7-9a0e-37b40a175fb0n@googlegroups.com...
Lately I have been working with Unix (really Linux, FreeBSD, and OpenBSD) 
character devices (these happen to be USB raw HID devices, but the problem 
is more general than that).  The way these work is that each hardware device 
has a character device node file in /dev/, like /dev/hidraw1.  You open the 
file for both read and write access.  Then you can send a command to the 
device by writing a binary blob and get a response by subsequently reading a 
binary blob.  For what I am doing, it is important not to block on reads 
forever if there is not response forthcoming, so I need at least read 
timeouts.

So far, I have been binding the C library functions open(), close(), read(), 
write(), and poll() with pragma Import.  That works, but I have wondered if 
there is some way of accomplishing the same thing more portably.  The 
packages GNAT.Sockets and GNAT.Serial_Communicatons can be viewed as special 
case solutions, but I would like a general solution.

What I would really like is Ada.Sequential_IO with InOut_File and a timeout 
mechanism, perhaps like the select() wrapper in GNAT.Sockets.

So far I haven't found anything in the Ada. or GNAT. that supports 
InOut_File semantics (other than Direct_IO) let alone timeouts.  Does 
anybody have any suggestions?

Phil 


^ permalink raw reply	[relevance 5%]

* Read/write access to Unix character devices
@ 2020-12-21  4:59  6% philip...@gmail.com
  2020-12-22  1:23  5% ` Randy Brukardt
  2020-12-28 13:26  0% ` Björn Lundin
  0 siblings, 2 replies; 200+ results
From: philip...@gmail.com @ 2020-12-21  4:59 UTC (permalink / raw)


Lately I have been working with Unix (really Linux, FreeBSD, and OpenBSD) character devices (these happen to be USB raw HID devices, but the problem is more general than that).  The way these work is that each hardware device has a character device node file in /dev/, like /dev/hidraw1.  You open the file for both read and write access.  Then you can send a command to the device by writing a binary blob and get a response by subsequently reading a binary blob.  For what I am doing, it is important not to block on reads forever if there is not response forthcoming, so I need at least read timeouts.

So far, I have been binding the C library functions open(), close(), read(), write(), and poll() with pragma Import.  That works, but I have wondered if there is some way of accomplishing the same thing more portably.  The packages GNAT.Sockets and GNAT.Serial_Communicatons can be viewed as special case solutions, but I would like a general solution.

What I would really like is Ada.Sequential_IO with InOut_File and a timeout mechanism, perhaps like the select() wrapper in GNAT.Sockets.

So far I haven't found anything in the Ada. or GNAT. that supports InOut_File semantics (other than Direct_IO) let alone timeouts.  Does anybody have any suggestions?

Phil

^ permalink raw reply	[relevance 6%]

* ANN: Simple components v4.53
@ 2020-12-13  9:02  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2020-12-13  9:02 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

    - Get_Reader_Timeout, Set_Reader_Timeout, Wait_For_Tasks were added 
to the package GNAT.Sockets.Server.Blocking;
    - JSON parser fixed to accept empty objects {} and empty array [];
    - OpenSSL bindings were extended;
    - The procedure Next_Unbiased was added to the package 
Generic_Random_Sequence.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* ANN: Simple Components for Ada v4.51
@ 2020-10-18  6:43  6% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2020-10-18  6:43 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- Memory leak fixed in the package Generic_Unbounded_Ptr_Array;
- Bug fix in data selector initialization (in the package 
GNAT.Sockets.Connection_State_Machine);
- An exception-free variant of Put was added to the 
Generic_Indefinite_FIFO package;
- ModBus TCP/IP implementation bug fix (the package 
GNAT.Sockets.Connection_State_Machine.MODBUS_Client);
- Code modified to work around GCC 10.0.1 optimization bug.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: ANN: Simple Components for Ada 4.51 IEEE 754-2008 Decimal
  2020-08-31 13:28  4% ANN: Simple Components for Ada 4.51 IEEE 754-2008 Decimal Dmitry A. Kazakov
@ 2020-09-03  4:30  0% ` linda white
  0 siblings, 0 replies; 200+ results
From: linda white @ 2020-09-03  4:30 UTC (permalink / raw)


On Monday, 31 August 2020 18:58:16 UTC+5:30, Dmitry A. Kazakov  wrote:
> The current version provides implementations of smart pointers, directed 
> graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
> arrays, expression analyzers, lock-free data structures, synchronization 
> primitives (events, race condition free pulse events, arrays of events, 
> reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
> non-repeating numbers, symmetric encoding and decoding, IEEE 754 
> representations support, streams, multiple connections server/client 
> designing tools and protocols implementations. The library is kept 
> conform to the Ada 95, Ada 2005, Ada 2012 language standards.
> 
>     http://www.dmitry-kazakov.de/ada/components.htm
> 
> Changes (1 September 2020) to the version 4.50:
> 
> - The HTTP client behavior changed not to close connection when keep 
> alive flag is set unless the server explicitly requests closing it;
> 
> - Non-standard request headers added to the HTTP implementation: 
> X-Requested-By, X-Requested-With, X-XSRF-TOKEN, X-CSRF-TOKEN;
> 
> - The package IEEE_754.Decimal32 was added. The package implements IEEE 
> 754-2008 decimal32 format;
> 
> - The package IEEE_754.Decimal64 was added. The package implements IEEE 
> 754-2008 decimal64 format;
> 
> - The package IEEE_754.Decimal128 was added. The package implements IEEE 
> 754-2008 decimal128 format;
> 
> - An implementation of 128-bit integers was added to the package IEEE_754;
> 
> - The package IEEE_754.Edit was added;
> 
> - The package provides strings formatting facilities for 128-bit integers;
> 
> - Fallback time zone names changes in the package 
> GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client.Time_Zones.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* ANN: Simple Components for Ada 4.51 IEEE 754-2008 Decimal
@ 2020-08-31 13:28  4% Dmitry A. Kazakov
  2020-09-03  4:30  0% ` linda white
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-08-31 13:28 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations. The library is kept 
conform to the Ada 95, Ada 2005, Ada 2012 language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes (1 September 2020) to the version 4.50:

- The HTTP client behavior changed not to close connection when keep 
alive flag is set unless the server explicitly requests closing it;

- Non-standard request headers added to the HTTP implementation: 
X-Requested-By, X-Requested-With, X-XSRF-TOKEN, X-CSRF-TOKEN;

- The package IEEE_754.Decimal32 was added. The package implements IEEE 
754-2008 decimal32 format;

- The package IEEE_754.Decimal64 was added. The package implements IEEE 
754-2008 decimal64 format;

- The package IEEE_754.Decimal128 was added. The package implements IEEE 
754-2008 decimal128 format;

- An implementation of 128-bit integers was added to the package IEEE_754;

- The package IEEE_754.Edit was added;

- The package provides strings formatting facilities for 128-bit integers;

- Fallback time zone names changes in the package 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client.Time_Zones.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: ANN: Simple Components v4.49
  2020-05-07  7:36  4% ANN: Simple Components v4.49 Dmitry A. Kazakov
@ 2020-05-09  9:32  0% ` Azathoth Hastur
  0 siblings, 0 replies; 200+ results
From: Azathoth Hastur @ 2020-05-09  9:32 UTC (permalink / raw)


On Thursday, May 7, 2020 at 3:36:07 AM UTC-4, Dmitry A. Kazakov wrote:
> The current version provides implementations of smart pointers, directed 
> graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
> arrays, expression analyzers, lock-free data structures, synchronization 
> primitives (events, race condition free pulse events, arrays of events, 
> reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
> non-repeating numbers, symmetric encoding and decoding, IEEE 754 
> representations support, streams, multiple connections server/client 
> designing tools and protocols implementations.
> 
>     http://www.dmitry-kazakov.de/ada/components.htm
> 
> Changes to the previous version:
> 
> - Bug fix in GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled 
> that prevented signaling successful connection;
> 
> - Sample code Test_HTTPS_OpenSSL_JSON_Client added;
> 
> - Free_Space function added to Generic_FIFO;
> 
> - The package Generic_Bounded_Map added.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Are these general purpose tools?

I am new to ada.

I primarily am looking at gnoga.com for web app tools for my consulting practice.

^ permalink raw reply	[relevance 0%]

* ANN: Simple Components v4.49
@ 2020-05-07  7:36  4% Dmitry A. Kazakov
  2020-05-09  9:32  0% ` Azathoth Hastur
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-05-07  7:36 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- Bug fix in GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled 
that prevented signaling successful connection;

- Sample code Test_HTTPS_OpenSSL_JSON_Client added;

- Free_Space function added to Generic_FIFO;

- The package Generic_Bounded_Map added.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: Simple parse from https website
  2020-04-02 19:34  7%           ` Rego, P.
  2020-04-03  5:19  0%             ` Jere
@ 2020-04-03  6:47  0%             ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2020-04-03  6:47 UTC (permalink / raw)


On 2020-04-02 21:34, Rego, P. wrote:
>> Egh, no, this is not AWS and not a part of GNAT Community 2019. I just
>> tested if your site worked with Simple Components.
>>
>> So GNAT.Sockets.Server is a part of Simple Components. I know it is
>> confusing but it must be a child of GNAT.Sockets to see a few things
>> declared there privately.
> 
> Oh, got it now =)
> Ok, so I included Simple Components as a source folder (using source from your site http://www.dmitry-kazakov.de/ada/components_4_48.tgz). But I got those compilation errors:
> 
>          16:6 "Gnat.Sockets.Connection_State_Machine (spec)" depends on "Gnat.Sockets.Server (spec)"
>          16:6 "Json_Dmitry (body)" depends on "Gnat.Sockets.Connection_State_Machine (spec)"
>          5:6 file "g-socser.ads" not found
>          6:6 file "g-socser.ads" not found
>          16:6 file "g-socser.ads" not found
>          14:6 file "test_http_servers.ads" not found
> 
> It seems that the compiler is looking for abbreviated names for the GNAT.Sockets child packages (but they are there). How can I force the compiler/builder to look for the extended names?

You need to set up the project with-ing corresponding gpr-files.

It is a bit off-topic here. Let's keep it outside c.l.a. Send me an 
E-mail, and I will help you to set things straight.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Re: Simple parse from https website
  2020-04-02 19:34  7%           ` Rego, P.
@ 2020-04-03  5:19  0%             ` Jere
  2020-04-03  6:47  0%             ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: Jere @ 2020-04-03  5:19 UTC (permalink / raw)


On Thursday, April 2, 2020 at 3:35:00 PM UTC-4, Rego, P. wrote:
> > Egh, no, this is not AWS and not a part of GNAT Community 2019. I just 
> > tested if your site worked with Simple Components.
> > 
> > So GNAT.Sockets.Server is a part of Simple Components. I know it is 
> > confusing but it must be a child of GNAT.Sockets to see a few things 
> > declared there privately.
> 
> Oh, got it now =)
> Ok, so I included Simple Components as a source folder (using source from your site http://www.dmitry-kazakov.de/ada/components_4_48.tgz). But I got those compilation errors:
> 
>         16:6 "Gnat.Sockets.Connection_State_Machine (spec)" depends on "Gnat.Sockets.Server (spec)"
>         16:6 "Json_Dmitry (body)" depends on "Gnat.Sockets.Connection_State_Machine (spec)"
>         5:6 file "g-socser.ads" not found
>         6:6 file "g-socser.ads" not found
>         16:6 file "g-socser.ads" not found
>         14:6 file "test_http_servers.ads" not found
> 
> It seems that the compiler is looking for abbreviated names for the GNAT.Sockets child packages (but they are there). How can I force the compiler/builder to look for the extended names?

Did you try building simple components as a library and 
"withing" the gpr file instead of adding it to your source
directories?

^ permalink raw reply	[relevance 0%]

* Re: Simple parse from https website
  2020-04-02 19:05  6%         ` Dmitry A. Kazakov
@ 2020-04-02 19:34  7%           ` Rego, P.
  2020-04-03  5:19  0%             ` Jere
  2020-04-03  6:47  0%             ` Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Rego, P. @ 2020-04-02 19:34 UTC (permalink / raw)


> Egh, no, this is not AWS and not a part of GNAT Community 2019. I just 
> tested if your site worked with Simple Components.
> 
> So GNAT.Sockets.Server is a part of Simple Components. I know it is 
> confusing but it must be a child of GNAT.Sockets to see a few things 
> declared there privately.

Oh, got it now =)
Ok, so I included Simple Components as a source folder (using source from your site http://www.dmitry-kazakov.de/ada/components_4_48.tgz). But I got those compilation errors:

        16:6 "Gnat.Sockets.Connection_State_Machine (spec)" depends on "Gnat.Sockets.Server (spec)"
        16:6 "Json_Dmitry (body)" depends on "Gnat.Sockets.Connection_State_Machine (spec)"
        5:6 file "g-socser.ads" not found
        6:6 file "g-socser.ads" not found
        16:6 file "g-socser.ads" not found
        14:6 file "test_http_servers.ads" not found

It seems that the compiler is looking for abbreviated names for the GNAT.Sockets child packages (but they are there). How can I force the compiler/builder to look for the extended names?

^ permalink raw reply	[relevance 7%]

* Re: Simple parse from https website
  2020-04-02 18:27  6%       ` Rego, P.
@ 2020-04-02 19:05  6%         ` Dmitry A. Kazakov
  2020-04-02 19:34  7%           ` Rego, P.
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-04-02 19:05 UTC (permalink / raw)


On 2020-04-02 20:27, Rego, P. wrote:

> Omg... (almost) Perfect(!lol)...just discovered that GNAT.Sockets has a signature change, some subpackages are no more exposed (like GNAT.SOCKETS.Server). I am using GNAT Community 2019.
> 
> Builder results
>          17:6 file "g-scstma.ads" not found
>          6:6 file "g-socser.ads" not found
>          7:6 file "g-socser.ads" not found
>          18:6 file "g-socser.ads" not found
>          8:6 file "openssl.ads" not found
>          9:6 file "parsers.ads" not found
>          10:6 file "parsers.ads" not found
>          19:6 file "parsers.ads" not found
>          20:6 file "stack_storage.ads" not found
>          11:6 file "strings_edit.ads" not found
>          12:6 file "strings_edit.ads" not found
>          13:6 file "strings_edit.ads" not found
>          14:6 file "strings_edit.ads" not found
>          15:6 file "test_http_servers.ads" not found

Egh, no, this is not AWS and not a part of GNAT Community 2019. I just 
tested if your site worked with Simple Components.

So GNAT.Sockets.Server is a part of Simple Components. I know it is 
confusing but it must be a child of GNAT.Sockets to see a few things 
declared there privately.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Simple parse from https website
  2020-04-02 17:16  7%     ` Dmitry A. Kazakov
@ 2020-04-02 18:27  6%       ` Rego, P.
  2020-04-02 19:05  6%         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Rego, P. @ 2020-04-02 18:27 UTC (permalink / raw)


> No, that site looks OK. I modified my OpenSSL HTTP client. I just added 
> JSON parser and procedure Dump to print the JSON object:
> 
> ----------------------------- test_https_openssl_json_client.adb -----
> with Ada.Exceptions;               use Ada.Exceptions;
> with Ada.Text_IO;                  use Ada.Text_IO;
> with Ada.Streams;                  use Ada.Streams;
> --with GNAT.Exception_Traces;      use GNAT.Exception_Traces;
> with GNAT.Sockets.Server.Handles;  use GNAT.Sockets.Server.Handles;
> with GNAT.Sockets.Server.OpenSSL;  use GNAT.Sockets.Server.OpenSSL;
> with OpenSSL;                      use OpenSSL;
> with Parsers.JSON;                 use Parsers.JSON;
> with Parsers.JSON.String_Source;   use Parsers.JSON.String_Source;
> with Strings_Edit.Integers;        use Strings_Edit.Integers;
> with Strings_Edit.Quoted;          use Strings_Edit.Quoted;
> with Strings_Edit.Streams;         use Strings_Edit.Streams;
> with Strings_Edit.Long_Floats;     use Strings_Edit.Long_Floats;
> with Test_HTTP_Servers.OpenSSL;    use Test_HTTP_Servers.OpenSSL;
> 
> with GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;
> with GNAT.Sockets.Server.Pooled;
> with Parsers.String_Source;
> with Stack_Storage;
> 
> procedure Test_HTTPS_OpenSSL_JSON_Client is
>     use GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;
> 
>     Address : constant String := "poloniex.com";
>     Path    : constant String := "public?command=returnTicker";
>     Port    : constant := 443;
> 
>     procedure Dump (Prefix : String; Value : JSON_Value) is
>     begin
>        case Value.JSON_Type is
>           when JSON_Boolean =>
>              Put_Line (Prefix & Boolean'Image (Value.Condition));
>           when JSON_Null =>
>              Put_Line (Prefix & "null");
>           when JSON_Number =>
>              Put_Line (Prefix & Image (Value.Value));
>           when JSON_String =>
>              Put_Line (Prefix & Quote (Value.Text.all));
>           when JSON_Array =>
>              Put_Line (Prefix & "(");
>              for Index in Value.Sequence'Range loop
>                 Dump (Prefix & "   ", Value.Sequence (Index));
>              end loop;
>              Put_Line (Prefix & ")");
>           when JSON_Object =>
>              Put_Line (Prefix & "{");
>              for Index in Value.Map'Range loop
>                 Put_Line (Prefix & "   " & Value.Map (Index).Name.all & 
> "=");
>                 Dump (Prefix & "      ", Value.Map (Index).Value);
>              end loop;
>              Put_Line (Prefix & "}");
>        end case;
>     end Dump;
> begin
>     declare
>        Factory : aliased HTTPS_OpenSSL_Factory
>                          (  Request_Length  => 200,
>                             Input_Size      => 40,
>                             Output_Size     => 1024,
>                             Decoded_Size    => 40,
>                             Max_Connections => 100
>                          );
>     begin
>        Set_Default_Verify_Paths (Factory, Client_Context);
>        declare
>           Message   : aliased String_Stream (1024 * 100);
>           Server    : aliased GNAT.Sockets.Server.
>                               Connections_Server (Factory'Access, 0);
>           Reference : GNAT.Sockets.Server.Handles.Handle;
>        begin
>           Put_Line ("HTTP client started");
>           Set
>           (  Reference,
>              new HTTP_Session_Signaled
>                  (  Server'Unchecked_Access,
>                     200,
>                     512,
>                     1024
>           )      );
>           declare
>              Client : HTTP_Session_Signaled renames
>                       HTTP_Session_Signaled (Ptr (Reference).all);
>           begin
>              Connect (Client, Address, Port);
>              Get
>              (  Client,
>                 "https://" & Address & "/" & Path,
>                 Message'Unchecked_Access
>              );
>              Wait (Client, False);
>              Put_Line
>              (  Image (Get_Response_Code (Client))
>              &  " "
>              &  Get_Response_Reason (Client)
>              &  " Message >>>>>>>>>>>>>>>>>>>>"
>              );
>              declare
>                 Content : aliased String := Get (Message);
>                 Source  : aliased Parsers.String_Source.
>                                   Source (Content'Access);
>                 Arena   : aliased Stack_Storage.Pool (1024, 10);
>                 Data    : constant JSON_Value :=
>                                    Parse (Source'Access, Arena'Access);
>              begin
>                 Dump ("", Data);
>              end;
>              Put_Line ("<<<<<<<<<<<<<<<<<<<< Message");
>           end;
>           Put_Line ("HTTP client stopping");
>        end;
>     end;
> exception
>     when Error : others =>
>        Put_Line ("Error: " & Exception_Information (Error));
> end Test_HTTPS_OpenSSL_JSON_Client;
> ----------------------------- test_https_openssl_json_client.adb -----
> 
> It connects fine and spills lots of garbage like:
> 
>    ...
>     USDT_SNX=
>        {
>           id=
>              290.9999999999999
>           last=
>              "0.00000000"
>           lowestAsk=
>              "0.00000000"
>           highestBid=
>              "0.00000000"
>           percentChange=
>              "0.00000000"
>           baseVolume=
>              "0.00000000"
>           quoteVolume=
>              "0.00000000"
>           isFrozen=
>              "0"
>           high24hr=
>              "0.00000000"
>           low24hr=
>              "0.00000000"
>        }
>     TRX_SNX=
>        {
>           id=
>              292.0000000000000
>           last=
>              "0.00000000"
>           lowestAsk=
>              "0.00000000"
>           highestBid=
>              "0.00000000"
>           percentChange=
>              "0.00000000"
>      ...
> 
> and so on. Funny enough, they put numbers as strings, so it seems.
> 
> It is not very efficient as written. You see, the code it accumulates 
> all response in a string stream buffer. Then takes a string from that. 
> Then it parses the obtained string into a JSON object. So it is two 
> copies too many. One could parse the response on the fly without 
> accumulating it whole in the memory. But it would mean more efforts.

Omg... (almost) Perfect(!lol)...just discovered that GNAT.Sockets has a signature change, some subpackages are no more exposed (like GNAT.SOCKETS.Server). I am using GNAT Community 2019.

Builder results
        17:6 file "g-scstma.ads" not found
        6:6 file "g-socser.ads" not found
        7:6 file "g-socser.ads" not found
        18:6 file "g-socser.ads" not found
        8:6 file "openssl.ads" not found
        9:6 file "parsers.ads" not found
        10:6 file "parsers.ads" not found
        19:6 file "parsers.ads" not found
        20:6 file "stack_storage.ads" not found
        11:6 file "strings_edit.ads" not found
        12:6 file "strings_edit.ads" not found
        13:6 file "strings_edit.ads" not found
        14:6 file "strings_edit.ads" not found
        15:6 file "test_http_servers.ads" not found


^ permalink raw reply	[relevance 6%]

* Re: Simple parse from https website
  @ 2020-04-02 17:16  7%     ` Dmitry A. Kazakov
  2020-04-02 18:27  6%       ` Rego, P.
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2020-04-02 17:16 UTC (permalink / raw)


On 2020-04-02 16:48, Rego, P. wrote:

> Ops...not, just testing more simpler cases. I am trying to get the data from
> https://poloniex.com/public?command=returnTicker
> 
> Just tried with google to check if it's problem from polo ticker. But the exception was the same.

No, that site looks OK. I modified my OpenSSL HTTP client. I just added 
JSON parser and procedure Dump to print the JSON object:

----------------------------- test_https_openssl_json_client.adb -----
with Ada.Exceptions;               use Ada.Exceptions;
with Ada.Text_IO;                  use Ada.Text_IO;
with Ada.Streams;                  use Ada.Streams;
--with GNAT.Exception_Traces;      use GNAT.Exception_Traces;
with GNAT.Sockets.Server.Handles;  use GNAT.Sockets.Server.Handles;
with GNAT.Sockets.Server.OpenSSL;  use GNAT.Sockets.Server.OpenSSL;
with OpenSSL;                      use OpenSSL;
with Parsers.JSON;                 use Parsers.JSON;
with Parsers.JSON.String_Source;   use Parsers.JSON.String_Source;
with Strings_Edit.Integers;        use Strings_Edit.Integers;
with Strings_Edit.Quoted;          use Strings_Edit.Quoted;
with Strings_Edit.Streams;         use Strings_Edit.Streams;
with Strings_Edit.Long_Floats;     use Strings_Edit.Long_Floats;
with Test_HTTP_Servers.OpenSSL;    use Test_HTTP_Servers.OpenSSL;

with GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;
with GNAT.Sockets.Server.Pooled;
with Parsers.String_Source;
with Stack_Storage;

procedure Test_HTTPS_OpenSSL_JSON_Client is
    use GNAT.Sockets.Connection_State_Machine.HTTP_Client.Signaled;

    Address : constant String := "poloniex.com";
    Path    : constant String := "public?command=returnTicker";
    Port    : constant := 443;

    procedure Dump (Prefix : String; Value : JSON_Value) is
    begin
       case Value.JSON_Type is
          when JSON_Boolean =>
             Put_Line (Prefix & Boolean'Image (Value.Condition));
          when JSON_Null =>
             Put_Line (Prefix & "null");
          when JSON_Number =>
             Put_Line (Prefix & Image (Value.Value));
          when JSON_String =>
             Put_Line (Prefix & Quote (Value.Text.all));
          when JSON_Array =>
             Put_Line (Prefix & "(");
             for Index in Value.Sequence'Range loop
                Dump (Prefix & "   ", Value.Sequence (Index));
             end loop;
             Put_Line (Prefix & ")");
          when JSON_Object =>
             Put_Line (Prefix & "{");
             for Index in Value.Map'Range loop
                Put_Line (Prefix & "   " & Value.Map (Index).Name.all & 
"=");
                Dump (Prefix & "      ", Value.Map (Index).Value);
             end loop;
             Put_Line (Prefix & "}");
       end case;
    end Dump;
begin
    declare
       Factory : aliased HTTPS_OpenSSL_Factory
                         (  Request_Length  => 200,
                            Input_Size      => 40,
                            Output_Size     => 1024,
                            Decoded_Size    => 40,
                            Max_Connections => 100
                         );
    begin
       Set_Default_Verify_Paths (Factory, Client_Context);
       declare
          Message   : aliased String_Stream (1024 * 100);
          Server    : aliased GNAT.Sockets.Server.
                              Connections_Server (Factory'Access, 0);
          Reference : GNAT.Sockets.Server.Handles.Handle;
       begin
          Put_Line ("HTTP client started");
          Set
          (  Reference,
             new HTTP_Session_Signaled
                 (  Server'Unchecked_Access,
                    200,
                    512,
                    1024
          )      );
          declare
             Client : HTTP_Session_Signaled renames
                      HTTP_Session_Signaled (Ptr (Reference).all);
          begin
             Connect (Client, Address, Port);
             Get
             (  Client,
                "https://" & Address & "/" & Path,
                Message'Unchecked_Access
             );
             Wait (Client, False);
             Put_Line
             (  Image (Get_Response_Code (Client))
             &  " "
             &  Get_Response_Reason (Client)
             &  " Message >>>>>>>>>>>>>>>>>>>>"
             );
             declare
                Content : aliased String := Get (Message);
                Source  : aliased Parsers.String_Source.
                                  Source (Content'Access);
                Arena   : aliased Stack_Storage.Pool (1024, 10);
                Data    : constant JSON_Value :=
                                   Parse (Source'Access, Arena'Access);
             begin
                Dump ("", Data);
             end;
             Put_Line ("<<<<<<<<<<<<<<<<<<<< Message");
          end;
          Put_Line ("HTTP client stopping");
       end;
    end;
exception
    when Error : others =>
       Put_Line ("Error: " & Exception_Information (Error));
end Test_HTTPS_OpenSSL_JSON_Client;
----------------------------- test_https_openssl_json_client.adb -----

It connects fine and spills lots of garbage like:

   ...
    USDT_SNX=
       {
          id=
             290.9999999999999
          last=
             "0.00000000"
          lowestAsk=
             "0.00000000"
          highestBid=
             "0.00000000"
          percentChange=
             "0.00000000"
          baseVolume=
             "0.00000000"
          quoteVolume=
             "0.00000000"
          isFrozen=
             "0"
          high24hr=
             "0.00000000"
          low24hr=
             "0.00000000"
       }
    TRX_SNX=
       {
          id=
             292.0000000000000
          last=
             "0.00000000"
          lowestAsk=
             "0.00000000"
          highestBid=
             "0.00000000"
          percentChange=
             "0.00000000"
     ...

and so on. Funny enough, they put numbers as strings, so it seems.

It is not very efficient as written. You see, the code it accumulates 
all response in a string stream buffer. Then takes a string from that. 
Then it parses the obtained string into a JSON object. So it is two 
copies too many. One could parse the response on the fly without 
accumulating it whole in the memory. But it would mean more efforts.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 7%]

* Re: Socket & Multicast problems / GNAT.Sockets
  2019-11-05 20:11  6%   ` Shark8
@ 2019-11-05 20:45  6%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2019-11-05 20:45 UTC (permalink / raw)


On 2019-11-05 21:11, Shark8 wrote:
> On Tuesday, November 5, 2019 at 12:57:07 PM UTC-7, Dmitry A. Kazakov wrote:
>> On 2019-11-05 20:06, Shark8 wrote:
>>
>>> Most of the messages can, I think, be mapped out to Ada's records fairly easily but that's getting ahead of myself — what I'm having trouble with is getting a socket to receive from the proper multicast address[es] — there is a note in the GNAT.Sockets example [which isn't working] that joining a multicast-group has to be set as an option subsequent to binding the socket when running on Windows.
>>
>> Did you check this:
>>
>> https://stackoverflow.com/questions/58151208/receiving-multicast-traffic-using-gnat-sockets
> Ah, I had not seen this one; but I did look around on StackOverflow.
> 
>>
>> P.S. I don't know what the example above does exactly. E.g. if it
>> configures an IGMP group and runs PGM on it. Is it PGM what you want to use?
> No, I don't think so.
> It's essentially a custom protocol / message-system used at a particular installation of the NSO.

PGM is a stream-oriented multicast just like TCP is stream-oriented 
unicast. You put your protocol on top of it.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 6%]

* Re: Socket & Multicast problems / GNAT.Sockets
  2019-11-05 19:57 12% ` Dmitry A. Kazakov
@ 2019-11-05 20:11  6%   ` Shark8
  2019-11-05 20:45  6%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Shark8 @ 2019-11-05 20:11 UTC (permalink / raw)


On Tuesday, November 5, 2019 at 12:57:07 PM UTC-7, Dmitry A. Kazakov wrote:
> On 2019-11-05 20:06, Shark8 wrote:
> 
> > Most of the messages can, I think, be mapped out to Ada's records fairly easily but that's getting ahead of myself — what I'm having trouble with is getting a socket to receive from the proper multicast address[es] — there is a note in the GNAT.Sockets example [which isn't working] that joining a multicast-group has to be set as an option subsequent to binding the socket when running on Windows.
> 
> Did you check this:
> 
> https://stackoverflow.com/questions/58151208/receiving-multicast-traffic-using-gnat-sockets
Ah, I had not seen this one; but I did look around on StackOverflow.

> 
> P.S. I don't know what the example above does exactly. E.g. if it 
> configures an IGMP group and runs PGM on it. Is it PGM what you want to use?
No, I don't think so.
It's essentially a custom protocol / message-system used at a particular installation of the NSO.


^ permalink raw reply	[relevance 6%]

* Re: Socket & Multicast problems / GNAT.Sockets
  2019-11-05 19:06 12% Socket & Multicast problems / GNAT.Sockets Shark8
  2019-11-05 19:10  6% ` Shark8
@ 2019-11-05 19:57 12% ` Dmitry A. Kazakov
  2019-11-05 20:11  6%   ` Shark8
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2019-11-05 19:57 UTC (permalink / raw)


On 2019-11-05 20:06, Shark8 wrote:

> Most of the messages can, I think, be mapped out to Ada's records fairly easily but that's getting ahead of myself — what I'm having trouble with is getting a socket to receive from the proper multicast address[es] — there is a note in the GNAT.Sockets example [which isn't working] that joining a multicast-group has to be set as an option subsequent to binding the socket when running on Windows.

Did you check this:

https://stackoverflow.com/questions/58151208/receiving-multicast-traffic-using-gnat-sockets

> (Is there a better package/library for operating on sockets? I've done a little searching, but I haven't found anything that looks particularly good.)

GNAT.Sockets is medium to thin bindings. There are sources so you can 
check yourself what GNAT.Socket does relatively easily. You can also 
extend it sometimes. For example, there is no SocketCAN support there, 
but that works anyway.

P.S. I don't know what the example above does exactly. E.g. if it 
configures an IGMP group and runs PGM on it. Is it PGM what you want to use?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 12%]

* Re: Socket & Multicast problems / GNAT.Sockets
  2019-11-05 19:06 12% Socket & Multicast problems / GNAT.Sockets Shark8
@ 2019-11-05 19:10  6% ` Shark8
  2019-11-05 19:57 12% ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: Shark8 @ 2019-11-05 19:10 UTC (permalink / raw)


There is a Java-utility that reads the messages of the system, I don't know if it will help; but if needed I can post the source [Java] for portions of it.

^ permalink raw reply	[relevance 6%]

* Socket & Multicast problems / GNAT.Sockets
@ 2019-11-05 19:06 12% Shark8
  2019-11-05 19:10  6% ` Shark8
  2019-11-05 19:57 12% ` Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Shark8 @ 2019-11-05 19:06 UTC (permalink / raw)


Ok, I have a system at work that is using custom methods, both TCP and UDP, and multicast / unicast. Now, I am getting stumped with the GNAT.Sockets translation of the equivalent connections, probably because I've not used Sockets before and most of the examples I've tried haven't worked.

Most of the messages can, I think, be mapped out to Ada's records fairly easily but that's getting ahead of myself — what I'm having trouble with is getting a socket to receive from the proper multicast address[es] — there is a note in the GNAT.Sockets example [which isn't working] that joining a multicast-group has to be set as an option subsequent to binding the socket when running on Windows.

(Is there a better package/library for operating on sockets? I've done a little searching, but I haven't found anything that looks particularly good.)


^ permalink raw reply	[relevance 12%]

* ANN: Simple Components v4.40
@ 2019-05-14 17:05  6% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2019-05-14 17:05 UTC (permalink / raw)


The software version provides implementations of smart pointers, 
directed graphs, sets, maps, B-trees, stacks, tables, string editing, 
unbounded arrays, expression analyzers, lock-free data structures, 
synchronization primitives (events, race condition free pulse events, 
arrays of events, reentrant mutexes, deadlock-free arrays of mutexes), 
pseudo-random non-repeating numbers, symmetric encoding and decoding, 
IEEE 754 representations support, streams, multiple connections 
server/client designing tools and various protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- The package OpenSSL was added to provide bindings to OpenSSL;

- The package GNAT.Sockets.Server.OpenSSL was added to support secure 
servers based on OpenSSL;

- Multiple procedures were added to the package 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client to support 
devices topology management and time management;

- Race condition in Object.Release fixed. The profile of the primitive 
operation Object.Decrement_Count has been modified.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Ada x <whatever> Datagram Sockets
  @ 2019-02-12 11:35  3%                     ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2019-02-12 11:35 UTC (permalink / raw)


"Randy Brukardt" <randy@rrsoftware.com> writes:

> "Simon Wright" <simon@pushface.org> wrote in message 
> news:ly5ztry1f8.fsf@pushface.org...
>> "Randy Brukardt" <randy@rrsoftware.com> writes:
> ...
>> [1] not sure that FIFO_Streams offers this without copying the contents
>> out?
>
> It doesn't, but I'm not sure how it could. It's not possible for a single 
> data type to be two different streams at the same time. Moreover, at least 
> some of the time, the result isn't going to a stream at all. And I haven't 
> personally seen a case where the extra cost of copying the data is 
> significant (the target stream/API being much slower). I could see where it 
> might matter, particularly in a transfer to some other kind of memory.

You may well be right about the extra cost. As I saw it, I needed to
eliminate the need for the users to declare a buffer, read into it, and
send it to the socket (represented in GNAT.Sockets as a stream), when
there was already a perfectly good buffer in the memory stream. There
were quite a few users.

I had fun getting FIFO_Streams to build in Ada 2012. Obviously had to
remove the 2020 aspects, and recast the (declare ...). Only the bounded
version, because the unbounded version would be much more
work. Unfortunately this means GNATprove couldn't be used, because
SPARK2014 doesn't allow discriminants on derived types (SPARK RM
3.7(2)). All the same, the assertions were a huge help.

Test code:

   with Ada.Streams.FIFO_Streams.Bounded;
   with Ada.Text_IO; use Ada.Text_IO;
   procedure Test is
      S : aliased Ada.Streams.FIFO_Streams.Bounded.Stream_Type (31);
   begin
      for J in 1 .. 9 loop
         String'Output (S'Access, "hello!" & J'Image);
         declare
            Buff : Ada.Streams.Stream_Element_Array (1 .. 32);
            Last : Ada.Streams.Stream_Element_Offset;
         begin
            S.Read (Item   => Buff,
                    Last   => Last);
            for K in 1 .. Last loop
               Put (Buff (K)'Image);
            end loop;
            New_Line;
         end;
      end loop;
   end Test;

Output:

   $ ./test
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 49
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 50
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 51
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 52
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 53
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 54
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 55
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 56
    1 0 0 0 8 0 0 0 104 101 108 108 111 33 32 57


^ permalink raw reply	[relevance 3%]

* Re: Ada x <whatever> Datagram Sockets
  @ 2019-02-08 20:00  5%           ` Rego, P.
  0 siblings, 0 replies; 200+ results
From: Rego, P. @ 2019-02-08 20:00 UTC (permalink / raw)


> For giggles try modifying your receive code a bit:
> 
>       declare
>          subtype Test_String is String(1..5);
>          Message : Test_String := Test_String'Input (Channel);
>       begin
>          Address := SOCKETS.Get_Address (Channel);
>          Text_IO.Put_Line (Message & " from " & SOCKETS.Image (Address));
>          Test_String'Output (Channel, Message);
>       end; 

The exception continues to come, but now the catcher comes from 
>          Message : Test_String := Test_String'Input (Channel);
line.

> I don't recall if C actually sends the '\0' at the end or not
> for sockets, so if it doesn't, then change the Test_String declaration
> to
> 
>       subtype Test_String is String(1..4);
> 
> However, I think it does send the '\0', so you will also have to
> handle that in your Ada code (since strings don't terminate with a
> '\0' in Ada).
It does not seem to be an '\0' problem, since the reception container is not limited (so, I don't mind receiving a 5 lenght message instead of 4), and the message (should be) is too small. The real messages will not be so long as well, in the real case it should have the same issue.

> I've never used streams with the GNAT socket package for production code,
> so I cannot comment on them, but the package definitely offers other
> options besides streams.  

Well... specifically GNAT.Sockets, from g-socket.ads I couldn't find any Receive_Sockets -like signature using any data container different than streams. 


> I generally have a task that periodically
> reads up to a specific number of bytes into a buffer and then my other
> tasks can handle the data as they see fit.  

This will be the next step :-) 

^ permalink raw reply	[relevance 5%]

* Gnat Sockets - Obtaining all the home addresses
@ 2019-02-07  8:58  9% ahlan
  0 siblings, 0 replies; 200+ results
From: ahlan @ 2019-02-07  8:58 UTC (permalink / raw)


My Ada programs need to obtain all the IP4 home addresses of the PC on which they execute.
Not just the first but all of them - it is now common for PCs to have more than one adapter - for example wired Ethernet and Wifi and these can be connected to different networks and therefore have totally different IP4 addresses.
I would like to write the code in an OS independent way and therefore currently use Gnat Sockets
In all the examples I have seen Get_Host_By_Name is called with Host_Name as its parameter.
This returns a Host_Entry_Type from which the function Addresses can obtain the host addresses.
Under Windows Addresses_Length returns the number of active network adapters and Addresses returns all the host addresses.
However on my Mac running Mojave with two network adapters on two different networks Get_Host_By_Name only returns one address.
Is this a bug or am I misunderstanding something?
I haven't tried it out under Linux as all my Linux machines only have one network adapter so maybe the problem isn't limited to Osx.
In any case, if this is not the way to do it - how should I obtain all the home addresses in an OS independent manner?
Can anyone advise me?

Best wishes as always,
MfG
Ahlan


^ permalink raw reply	[relevance 9%]

* Re: Ada x <whatever> Datagram Sockets
  2019-02-07  0:42  0% ` Jere
@ 2019-02-07  5:28  0%   ` Rego, P.
    0 siblings, 1 reply; 200+ results
From: Rego, P. @ 2019-02-07  5:28 UTC (permalink / raw)


On Wednesday, February 6, 2019 at 10:42:56 PM UTC-2, Jere wrote:
> On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote:
> > I am trying to communicate a Windows Ada application with another application in the same machine (an specific C++ porting called MQL) using datagram sockets. The core Ada app was extracted from GNAT.Sockets documentation, from the ping-pong caller. 
> > *SNIPPED*
> > 
> > The problem is that when I send the message (from MQL side), my Ada server returns
> > 
> > raised GNAT.SOCKETS.SOCKET_ERROR : [10040] Message too long
> > Call stack traceback locations:
> > 0x424e6c 0x426ddb 0x426e17 0x4200a8 0x42174e 0x4019fc 0x40246d 0x4013db 0x74198482 0x778f3ab6 0x778f3a86
> > 
> > and investigating the libraries, Channel : SOCKETS.Stream_Access will really receive any data size.
> > 
> > So... how can avoid the exception?
> > 
> > Thanks!
> 
> How big of a message are you trying to send?  Datagram sockets have
> an upper limit on the payload size (65507 bytes for ipv4) regardless
> of the language.

Just the string "test". I also confirmed that the MQL container (uchar data[]) has really the size 5.

I also forgot to mention that the communication from both client-server applications show no problem at all, I mean, MQL to MQL and Ada to Ada have no errors. The problem comes only when trying MQL to Ada.

^ permalink raw reply	[relevance 0%]

* Re: Ada x <whatever> Datagram Sockets
  2019-02-06 23:10  8% Ada x <whatever> Datagram Sockets Rego, P.
@ 2019-02-07  0:42  0% ` Jere
  2019-02-07  5:28  0%   ` Rego, P.
  0 siblings, 1 reply; 200+ results
From: Jere @ 2019-02-07  0:42 UTC (permalink / raw)


On Wednesday, February 6, 2019 at 6:10:37 PM UTC-5, Rego, P. wrote:
> I am trying to communicate a Windows Ada application with another application in the same machine (an specific C++ porting called MQL) using datagram sockets. The core Ada app was extracted from GNAT.Sockets documentation, from the ping-pong caller. 
> *SNIPPED*
> 
> The problem is that when I send the message (from MQL side), my Ada server returns
> 
> raised GNAT.SOCKETS.SOCKET_ERROR : [10040] Message too long
> Call stack traceback locations:
> 0x424e6c 0x426ddb 0x426e17 0x4200a8 0x42174e 0x4019fc 0x40246d 0x4013db 0x74198482 0x778f3ab6 0x778f3a86
> 
> and investigating the libraries, Channel : SOCKETS.Stream_Access will really receive any data size.
> 
> So... how can avoid the exception?
> 
> Thanks!

How big of a message are you trying to send?  Datagram sockets have
an upper limit on the payload size (65507 bytes for ipv4) regardless
of the language.


^ permalink raw reply	[relevance 0%]

* Ada x <whatever> Datagram Sockets
@ 2019-02-06 23:10  8% Rego, P.
  2019-02-07  0:42  0% ` Jere
  0 siblings, 1 reply; 200+ results
From: Rego, P. @ 2019-02-06 23:10 UTC (permalink / raw)


I am trying to communicate a Windows Ada application with another application in the same machine (an specific C++ porting called MQL) using datagram sockets. The core Ada app was extracted from GNAT.Sockets documentation, from the ping-pong caller. 

with GNAT.Sockets;
with Text_IO;
with Ada.Exceptions; use Ada.Exceptions;

procedure DG_SERVER is
   package SOCKETS renames GNAT.Sockets;
   Socket  : SOCKETS.Socket_Type;
   Address : SOCKETS.Sock_Addr_Type;
   Channel : SOCKETS.Stream_Access;
   Group : constant String := "239.255.128.128";

begin

   SOCKETS.Initialize;
   SOCKETS.Create_Socket (Socket, SOCKETS.Family_Inet, SOCKETS.Socket_Datagram);
   SOCKETS.Set_Socket_Option
     (Socket,
      SOCKETS.Socket_Level,
      (SOCKETS.Reuse_Address, True));
   SOCKETS.Set_Socket_Option
     (Socket,
      SOCKETS.IP_Protocol_For_IP_Level,
      (SOCKETS.Multicast_TTL, 1));
   SOCKETS.Set_Socket_Option
     (Socket,
      SOCKETS.IP_Protocol_For_IP_Level,
      (SOCKETS.Multicast_Loop, True));
   Address.Addr := SOCKETS.Any_Inet_Addr;
   Address.Port := 55505;
   SOCKETS.Bind_Socket (Socket, Address);
   SOCKETS.Set_Socket_Option
     (Socket,
      SOCKETS.IP_Protocol_For_IP_Level,
      (SOCKETS.Add_Membership, SOCKETS.Inet_Addr (Group), SOCKETS.Any_Inet_Addr));
   Address.Addr := SOCKETS.Inet_Addr (Group);
   loop
      Channel := SOCKETS.Stream (Socket, Address);
      declare
         Message : String := String'Input (Channel);
      begin
         Address := SOCKETS.Get_Address (Channel);
         Text_IO.Put_Line (Message & " from " & SOCKETS.Image (Address));
         String'Output (Channel, Message);
      end;
   end loop;
exception
   when The_Error : others =>
      Text_IO.Put_Line("!!! "&Ada.Exceptions.Exception_Information (The_Error));
end DG_SERVER;

The problem is that when I send the message (from MQL side), my Ada server returns

raised GNAT.SOCKETS.SOCKET_ERROR : [10040] Message too long
Call stack traceback locations:
0x424e6c 0x426ddb 0x426e17 0x4200a8 0x42174e 0x4019fc 0x40246d 0x4013db 0x74198482 0x778f3ab6 0x778f3a86

and investigating the libraries, Channel : SOCKETS.Stream_Access will really receive any data size.

So... how can avoid the exception?

Thanks!


^ permalink raw reply	[relevance 8%]

* ANN: Simple Components for Ada v4.36
@ 2019-01-08 11:50  7% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2019-01-08 11:50 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations. The library is kept 
conform to the Ada 95, Ada 2005, Ada 2012 language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- The package GNAT.Sockets.Server.Blocking was added to provide 
connection servers handling blocking I/O;
- Procedures Send_Socket and Receive_Socket were added to the package 
GNAT.Sockets.Server;
- Procedures Reconnect and Request_Disconnect were added to the package 
GNAT.Sockets.Server;
- The functions Is_Configured, Is_In, Has_Device_Configuration were 
added GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client;
- Airing time decoding/encoding error in 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 7%]

* Simple components for Ada v4.33
@ 2018-11-24 17:38  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-11-24 17:38 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations. The library is kept 
conform to the Ada 95, Ada 2005, Ada 2012 language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

    - SQLite3 bindings were updated to the SQLite3 version 3.25.3;
    - The Version function was added in the package SQLite;
    - Higher-order tracing operation can be overridden in the package 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Re: GNAT Sockets UDP problem on Windows 10.
  2018-11-23  6:27 11% GNAT Sockets UDP problem on Windows 10 Petter Fryklund
@ 2018-11-23  8:41  6% ` Petter Fryklund
  0 siblings, 0 replies; 200+ results
From: Petter Fryklund @ 2018-11-23  8:41 UTC (permalink / raw)


Den fredag 23 november 2018 kl. 07:27:45 UTC+1 skrev Petter Fryklund:
> Hi all,
> 
> I get socket error 10051, network unreachable when trying to send on Windows 10. Everything works fine on Windows 7. Also, Delphi programs work fine on Windows 10. What is special with GNAT Sockets and what do I do to overcome this hurdle?
> 
> Regards,
> Petter

When creating the reproducer I first found out that I mistakenly had copied code from a TCP client that also did Connect. When that was fixed I found that I had made an unnecessary Bind of the sending socket (as a response to the compiler warning that  the socket was read but not initialized), strangely this was alright on W7, but not on W10. We are now fine (for now ;-)

Regards,
Petter


^ permalink raw reply	[relevance 6%]

* GNAT Sockets UDP problem on Windows 10.
@ 2018-11-23  6:27 11% Petter Fryklund
  2018-11-23  8:41  6% ` Petter Fryklund
  0 siblings, 1 reply; 200+ results
From: Petter Fryklund @ 2018-11-23  6:27 UTC (permalink / raw)


Hi all,

I get socket error 10051, network unreachable when trying to send on Windows 10. Everything works fine on Windows 7. Also, Delphi programs work fine on Windows 10. What is special with GNAT Sockets and what do I do to overcome this hurdle?

Regards,
Petter

^ permalink raw reply	[relevance 11%]

* ANN: Simple components v4.31
@ 2018-11-07 17:08  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-11-07 17:08 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations. The library is kept 
conform to the Ada 95, Ada 2005, Ada 2012 language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes the previous version:

- Bug fix in GNAT.Sockets.MQTT.Server.Push, a check for the case when no 
client is connected.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 4%]

* Re: Reusable free code: Simple components - MODBUS.Synchronos.connect not returning
  2018-08-28  8:04  4% Reusable free code: Simple components - MODBUS.Synchronos.connect not returning Karl Müller
@ 2018-08-28 16:03  0% ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-08-28 16:03 UTC (permalink / raw)


On 2018-08-28 10:04, Karl Müller wrote:
> Hello,
> 
> it's my first contribution to this sophisticated newsgroup and I hope 
> I'm not disturbing too much.
> 
> Trying the Modbus test programs of the Simple components from Dmitry 
> Kazakov I made the experience that the MODBUS.Synchronos client is not 
> returning after calling the connect procedure. When I set the Timeout 
> value to 5 seconds the Tracer is writing and after that time the program 
> exits:
> 
> 127.0.0.1:1502 < --- Stop polling, nothing to send
> 127.0.0.1:1502 < +++ Resume polling, blocking timeout expired
> 127.0.0.1:1502 < --- Stop polling, nothing to send
> Worker task exiting
> raised 
> GNAT.SOCKETS.CONNECTION_STATE_MACHINE.MODBUS_CLIENT.SYNCHRONOUS.TIMEOUT_ERROR 
> : Connection timeout expired
> 
> To my suprise the MODBUS test program with multiple connections is 
> working as expected.
> 
> Is there anything I'm not aware off when using the 
> MODBUS_CLIENT.SYNCHRONOS?

A synchronous client blocks on Connect until the server accepts 
connection or else the timeout expires. Or do you mean something else?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Reusable free code: Simple components - MODBUS.Synchronos.connect not returning
@ 2018-08-28  8:04  4% Karl Müller
  2018-08-28 16:03  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Karl Müller @ 2018-08-28  8:04 UTC (permalink / raw)


Hello,

it's my first contribution to this sophisticated newsgroup and I hope 
I'm not disturbing too much.

Trying the Modbus test programs of the Simple components from Dmitry 
Kazakov I made the experience that the MODBUS.Synchronos client is not 
returning after calling the connect procedure. When I set the Timeout 
value to 5 seconds the Tracer is writing and after that time the program 
exits:

127.0.0.1:1502 < --- Stop polling, nothing to send
127.0.0.1:1502 < +++ Resume polling, blocking timeout expired
127.0.0.1:1502 < --- Stop polling, nothing to send
Worker task exiting
raised 
GNAT.SOCKETS.CONNECTION_STATE_MACHINE.MODBUS_CLIENT.SYNCHRONOUS.TIMEOUT_ERROR 
: Connection timeout expired

To my suprise the MODBUS test program with multiple connections is 
working as expected.

Is there anything I'm not aware off when using the MODBUS_CLIENT.SYNCHRONOS?

Regards

Karl

^ permalink raw reply	[relevance 4%]

* ANN: Simple components for Ada v 4.30
@ 2018-08-05 11:21  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-08-05 11:21 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- An implementation of inter-process communication based on pthread was 
added for OS X and FreeBSD targets (thanks to Pascal Pignard);
- Missing test file test_data_client.adb restored;
- Bug fix in Generic_Blackboard causing sporadic infrequent data loss;
- GNUTLS bindings bug fix in setting Diffie-Hellman parameters when the 
key length is estimated negative;
- GNUTLS bindings were adapted to support OS X and FreeBSD targets;
- Create_Socket operation was added to Connections_Server in the package 
GNAT.Sockets.Server.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 4%]

* Privacy and child packages (Was: Teaching C/C++ from Ada perspective?)
  @ 2018-07-07  8:48  6%                                       ` Jacob Sparre Andersen
  0 siblings, 0 replies; 200+ results
From: Jacob Sparre Andersen @ 2018-07-07  8:48 UTC (permalink / raw)


Micronian Coder <micronian2@gmail.com> writes:

> Jean-Pierre beat me to it, but I concur that child packages is Ada's
> answer to C++ friend. I find child packages much better than C++
> friend because you can keep adding additional subprograms, say for
> testing purposes, without ever touching the original package.

Yes.

But the down-side(?) is that a clever programmer can use a child package
to leak private information from its parent.

You can see the package GNAT.Sockets.Compatibility in
<https://bitbucket.org/sparre/gnat-sockets-extras> for an example.  In
this case I used it to be able to use the same input/output operations
for both network connections and regular files.

Greetings,

Jacob
-- 
'I don't think you can fight a whole universe, sir!'
'It's the prerogative of every life form, Mr Stibbons!'

^ permalink raw reply	[relevance 6%]

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  @ 2018-07-06  8:24  5%                 ` Petter Fryklund
  0 siblings, 0 replies; 200+ results
From: Petter Fryklund @ 2018-07-06  8:24 UTC (permalink / raw)


Now I've studied the case a little more and I've found out that in our unit that interfaces with GNAT.Sockets we also uses Get_Host_By_Name. That maybe explains the problem. It's hard to choose interface if both are localhost. We will have to solve this differently somewhere in the 5 deep call-chain. 

Thanks for all the help Dmitry.

Regards,
Petter

^ permalink raw reply	[relevance 5%]

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04 13:07  6%         ` Petter Fryklund
@ 2018-07-04 13:42  0%           ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-07-04 13:42 UTC (permalink / raw)


On 2018-07-04 15:07, Petter Fryklund wrote:

> Maybe GNAT.Sockets.Thin can be used to set SO_BINDTODEVICE, but I cannot find a copy of sys/sockets.h that includes the numerical value for SO_BINDTODEV. Also, I've come across both SO_BINDTODEV and SO_BINDTODEVICE. Which is more commonly used?

When I had to use Linux raw sockets I too used GNAT.Thin and defined 
missing constants like IPPROTO_RAW. It worked OK.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  @ 2018-07-04 13:07  6%         ` Petter Fryklund
  2018-07-04 13:42  0%           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Petter Fryklund @ 2018-07-04 13:07 UTC (permalink / raw)


Maybe GNAT.Sockets.Thin can be used to set SO_BINDTODEVICE, but I cannot find a copy of sys/sockets.h that includes the numerical value for SO_BINDTODEV. Also, I've come across both SO_BINDTODEV and SO_BINDTODEVICE. Which is more commonly used?

Regards,
Petter 

^ permalink raw reply	[relevance 6%]

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  2018-07-04  9:50  5%   ` Petter Fryklund
@ 2018-07-04 10:23  5%     ` Dmitry A. Kazakov
    0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-07-04 10:23 UTC (permalink / raw)


On 2018-07-04 11:50, Petter Fryklund wrote:

> The wording isn't exactly like yours (we use GNAT Sockets), but it is similar to the code we use. It works fine in Windows, but not in Linux. The embedded Linux system has several network devices, that is why I think we need so_bindtodev.

It is GNAT.Sockets and it works under Linux, AFAIK.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: UDP Send gets NETWORK_IS_UNREACHABLE
  @ 2018-07-04  9:50  5%   ` Petter Fryklund
  2018-07-04 10:23  5%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Petter Fryklund @ 2018-07-04  9:50 UTC (permalink / raw)


Thanks for answering, Dmitry.

The wording isn't exactly like yours (we use GNAT Sockets), but it is similar to the code we use. It works fine in Windows, but not in Linux. The embedded Linux system has several network devices, that is why I think we need so_bindtodev.

Regards,
Petter


^ permalink raw reply	[relevance 5%]

* ANN: Simple components for Ada v4.29
@ 2018-06-02 14:34  7% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2018-06-02 14:34 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, streams, multiple connections server/client 
designing tools and protocols implementations. The library is kept 
conform to the Ada 95, Ada 2005, Ada 2012 language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- Handling faulty devices added to the package 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client;

- Asynchronous execution of remote calls is supported;

- Bug fix in the function To_HTML from 
GNAT.Sockets.Connection_State_Machine.HTTP_Server;

- Bug fix GNAT.Sockets.Server.Secure.Anonymous, misspelled Initialize.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 7%]

* Re: TCP Server & Client
  2018-03-25  8:22  4% ` Simon Wright
@ 2018-03-25 19:17  0%   ` Andrew Shvets
  0 siblings, 0 replies; 200+ results
From: Andrew Shvets @ 2018-03-25 19:17 UTC (permalink / raw)


On Sunday, March 25, 2018 at 4:22:32 AM UTC-4, Simon Wright wrote:
> Andrew Shvets <an....@gmail.com> writes:
> 
> > procedure TCP_Client is
> [...]
> >   GNAT.Sockets.Create_Socket(Socket, GNAT.Sockets.Family_Inet, GNAT.Sockets.Socket_Stream);
> 
> >   GNAT.Sockets.Set_Socket_Option(Socket, GNAT.Sockets.Socket_Level, (GNAT.Sockets.Reuse_Address, True));
> 
> >   GNAT.Sockets.Send_Socket(Socket, Data, Last, Address);
> 
> If you look at the spec of GNAT.Sockets for a long time you will see
> that there are 3 versions of Send_Socket, only 2 of which I would expect
> to use, and you've chosen the wrong one (the last, datagram,
> version). You need the second:
> 
>    procedure Send_Socket
>      (Socket : Socket_Type;
>       Item   : Ada.Streams.Stream_Element_Array;
>       Last   : out Ada.Streams.Stream_Element_Offset;
>       Flags  : Request_Flag_Type := No_Request_Flag);
> 
> More importantly, you've left out the Connect_Socket call (which is what
> the server Accept_Socket call is waiting for).
> 
> Check out the commentary at the beginning of g-socket.ads, look for
> 'task body ping'.
> 
> 
> Also, in TCP_Server, you should be calling Receive_Socket on Sock (the
> new socket which is actually connected to TCP_Client).

Thank you Simon.  That did the trick.


^ permalink raw reply	[relevance 0%]

* Re: TCP Server & Client
  2018-03-25  4:04  9% TCP Server & Client Andrew Shvets
@ 2018-03-25  8:22  4% ` Simon Wright
  2018-03-25 19:17  0%   ` Andrew Shvets
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2018-03-25  8:22 UTC (permalink / raw)


Andrew Shvets <andrew.shvets@gmail.com> writes:

> procedure TCP_Client is
[...]
>   GNAT.Sockets.Create_Socket(Socket, GNAT.Sockets.Family_Inet, GNAT.Sockets.Socket_Stream);

>   GNAT.Sockets.Set_Socket_Option(Socket, GNAT.Sockets.Socket_Level, (GNAT.Sockets.Reuse_Address, True));

>   GNAT.Sockets.Send_Socket(Socket, Data, Last, Address);

If you look at the spec of GNAT.Sockets for a long time you will see
that there are 3 versions of Send_Socket, only 2 of which I would expect
to use, and you've chosen the wrong one (the last, datagram,
version). You need the second:

   procedure Send_Socket
     (Socket : Socket_Type;
      Item   : Ada.Streams.Stream_Element_Array;
      Last   : out Ada.Streams.Stream_Element_Offset;
      Flags  : Request_Flag_Type := No_Request_Flag);

More importantly, you've left out the Connect_Socket call (which is what
the server Accept_Socket call is waiting for).

Check out the commentary at the beginning of g-socket.ads, look for
'task body ping'.


Also, in TCP_Server, you should be calling Receive_Socket on Sock (the
new socket which is actually connected to TCP_Client).


^ permalink raw reply	[relevance 4%]

* TCP Server & Client
@ 2018-03-25  4:04  9% Andrew Shvets
  2018-03-25  8:22  4% ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Andrew Shvets @ 2018-03-25  4:04 UTC (permalink / raw)


Hello, I'm trying to write a small client/server example:

This is the client:
==============================================================================
with Ada.Streams;
with Ada.Text_IO;

with GNAT.Sockets;

procedure TCP_Client is
  Address : GNAT.Sockets.Sock_Addr_Type;
  Socket : GNAT.Sockets.Socket_Type;
  Data : constant Ada.Streams.Stream_Element_Array(1 .. 512) := (others => 42);
  Last : Ada.Streams.Stream_Element_Offset;
begin
  GNAT.Sockets.Initialize;

  Address.Port := 50001;
  Address.Addr := GNAT.Sockets.Inet_Addr("127.0.0.1");
  Ada.Text_IO.Put_Line("Hello 1");
  GNAT.Sockets.Create_Socket(Socket, GNAT.Sockets.Family_Inet, GNAT.Sockets.Socket_Stream);
  Ada.Text_IO.Put_Line("Hello 2");
  GNAT.Sockets.Set_Socket_Option(Socket, GNAT.Sockets.Socket_Level, (GNAT.Sockets.Reuse_Address, True));
  Ada.Text_IO.Put_Line("Hello 3");
  GNAT.Sockets.Send_Socket(Socket, Data, Last, Address);
  Ada.Text_IO.Put_Line("last :" & Last'Img);

  GNAT.Sockets.Finalize;
end TCP_Client;
==============================================================================

This is the server:
==============================================================================
with Ada.Streams;
with Ada.Text_IO;

with GNAT.Sockets;

procedure TCP_Server is
  Server : GNAT.Sockets.Socket_Type;
  Sock   : GNAT.Sockets.Socket_Type;
  Address : GNAT.Sockets.Sock_Addr_Type;
  From : GNAT.Sockets.Sock_Addr_Type;
  Data : Ada.Streams.Stream_Element_Array(1 .. 512);
  Last : Ada.Streams.Stream_Element_Offset;
  Watchdog : Natural := 0;
begin
  GNAT.Sockets.Initialize;

  GNAT.Sockets.Create_Socket(Server, GNAT.Sockets.Family_Inet, GNAT.Sockets.Socket_Stream);
  GNAT.Sockets.Set_Socket_Option(Server, GNAT.Sockets.Socket_Level, (GNAT.Sockets.Reuse_Address, True));
  Address.Addr := GNAT.Sockets.Any_Inet_Addr;
  Address.Port := 50001;
  GNAT.Sockets.Bind_Socket(Server, Address);

  loop
    begin
      GNAT.Sockets.Listen_Socket(Server);
      GNAT.Sockets.Accept_Socket(Server, Sock, Address); 
      GNAT.Sockets.Receive_Socket(Server, Data, Last, From);
      Ada.Text_IO.Put_Line("last : " & Last'Img);
      Ada.Text_IO.Put_Line("from : " & GNAT.Sockets.Image(From.Addr));
    exception
      when GNAT.Sockets.Socket_Error =>
        Ada.Text_IO.Put_Line("ERROR: Socket error caught.");
    end;
  end loop;
end TCP_Server;
==============================================================================


When I run the client, this is what I see:
Hello 1
Hello 2
Hello 3

raised GNAT.SOCKETS.SOCKET_ERROR : [32] Broken pipe




Why is this happening?  If possible, I'd like to use the Send_Socket method in the client.  Thanks.


^ permalink raw reply	[relevance 9%]

* Re: GNAT implementation of socket sets
  2018-01-19 17:29  6% GNAT implementation of socket sets Dmitry A. Kazakov
@ 2018-01-19 19:10  0% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2018-01-19 19:10 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> GNAT.Sockets implementation of Socket_Set_Type has no operation to
> walk that set by position. It seemed not a big issue until I noticed
> that the implementation of
>
>    procedure Get (Item : in out Socket_Set_Type; Socket : out Socket_Type);
>    --  Extract a Socket from socket set Item. Socket is set to
>    --  No_Socket when the set is empty.
>
> seems to always return the last element of the set.

Indeed.

Implemented as:

   /* Get last socket and remove it from the socket set SET.  LAST is the
      maximum value of the largest socket.  This hint is used to avoid scanning
      very large socket sets.  On return, LAST is set to the actual largest
      socket in the socket set. */

   void
   __gnat_get_socket_from_set (fd_set *set, int *last, int *socket)
   {
     *socket = *last;
     FD_CLR (*socket, set);
     __gnat_last_socket_in_set (set, last);
   }

where

   void
   __gnat_last_socket_in_set (fd_set *set, int *last)
   {
     int s;
     int l;
     l = -1;

   #ifdef _WIN32
     /* More efficient method for NT. */
     for (s = 0; s < set->fd_count; s++)
       if ((int) set->fd_array[s] > l)
         l = set->fd_array[s];

   #else

     for (s = *last; s != -1; s--)
       if (FD_ISSET (s, set))
         {
           l = s;
           break;
         }
   #endif

     *last = l;
   }


^ permalink raw reply	[relevance 0%]

* GNAT implementation of socket sets
@ 2018-01-19 17:29  6% Dmitry A. Kazakov
  2018-01-19 19:10  0% ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2018-01-19 17:29 UTC (permalink / raw)


GNAT.Sockets implementation of Socket_Set_Type has no operation to walk 
that set by position. It seemed not a big issue until I noticed that the 
implementation of

    procedure Get (Item : in out Socket_Set_Type; Socket : out Socket_Type);
    --  Extract a Socket from socket set Item. Socket is set to
    --  No_Socket when the set is empty.

seems to always return the last element of the set.

If so, it imposes a severe problem for an application that deals with 
multiple non-blocking sockets, because it prioritizes connections with 
sockets with greater file numbers. Under heavy load the application will 
serve only one connection.

Typically such issues are resolved by a round-robin schema to balance 
the load. But that requires walking the set and extracting an element at 
a position.

Can anybody confirm that and suggest a workaround?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 6%]

* Re: ANN: MAX! home automation v2.0
  @ 2017-12-19 14:00  5%       ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-12-19 14:00 UTC (permalink / raw)


On 2017-12-19 14:40, Brian Drummond wrote:
> On Sun, 17 Dec 2017 18:30:18 +0100, Dmitry A. Kazakov wrote:
> 
>> On 2017-12-17 17:10, Brian Drummond wrote:
> 
>>> You might be looking for https://www.sparforte.com/
>>
>> Thanks, it looks good.
>>
>> But I don't see crucial details:
>>
>> 1. Windows support
>>
>> 2. Embedding. The script must be run from an Ada program and the program
>> must extend the script's built-in operations.
> 
> I don't know about these; if it's buildable and runnable under cygwin for
> example, would that work, or do you need full native Windows?

I contacted Ken Burtch, Windows is not supported.

The sources use low-level Unix I/O. It would be difficult to port to 
Windows without an OS abstraction level.

> As it's written in Ada (as far as possible) it can presumably be built
> into another Ada program, or adapted to build as a library.

It could be 100% Ada if were not GNAT-agnostic.

AdaCore did a great work abstracting OS away and providing Ada project 
tool. To be AdaCore independent you lose a lot. It is worth considering 
some of GNAT libraries, e.g. GNAT.Sockets, becoming the standard as well 
as GPR projects. Seeing autoconf/configure/cmake mess near to Ada makes 
me ill...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 5%]

* ANN: Simple Components for Ada v4.25
@ 2017-11-26 13:00  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-11-26 13:00 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, multiple connections server/client designing 
tools. The library is kept conform to the Ada 95, Ada 2005, Ada 2012 
language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- The package 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client.Stream_IO now 
supports reading and writing wall thermostat settings.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 4%]

* Re: alternative for buggy accept_socket to create a non-blocking version
  2017-10-25 17:23  6% alternative for buggy accept_socket to create a non-blocking version Matt Borchers
  2017-10-25 19:14  5% ` Matt Borchers
  2017-10-27  9:14  5% ` Björn Lundin
@ 2017-10-27 16:26  0% ` Daniel Norte Moraes
  2 siblings, 0 replies; 200+ results
From: Daniel Norte Moraes @ 2017-10-27 16:26 UTC (permalink / raw)


Em quarta-feira, 25 de outubro de 2017 15:23:52 UTC-2, Matt Borchers  escreveu:
> I have no choice but to use an old GNAT compiler -- version 6.3.0.  In this version there is a confirmed bug (fixed in 6.3.2) that prevents the non-blocking version of accept_socket from working.  I want to call the version of accept_socket with the 'timeout' parameter, but it doesn't do what it should.
> 
> Basically, I've built a way to read data from a socket and all goes well when a response is made.  However, I need a way to abandon the accept call if a response is never sent within a small time window.
> 
> This is my foray into sockets programming and I don't fully understand all of the nuances yet.  I tried setting the Receive_Timeout socket option but it had no effect -- I don't think it does what I need anyway.  This all seems pretty straight-forward assuming there is no bug in the non-blocking version of accept_socket, but I don't know how to work-around this bug.
> 
> I can imagine a pair of tasks in which one does the blocking accept (A) and the other task (B) does the time-out.  If the time-out occurs first, B will abort the task A otherwise after A succeeds in accepting the message it will abort B.  This seems like it might not be the best work-around solution.
> 
> Does anybody know of a good way to create a type of non-blocking accept_socket?
> 
> My code basically is:
> 
> with GNAT.Sockets; use GNAT.Sockets;
> ...
> declare
>   sock,
>   socket   : SOCKET_TYPE;
>   address  : SOCK_ADDR_TYPE;
>   data     : STREAM_ELEMENT_ARRAY(1..256);
>   last     : STREAM_ELEMENT_OFFSET;
>   sel_stat : SELECTOR_STATUS;
> begin
>   create_socket( socket );
>   bind_socket( socket, address );
>   listen_socket( socket );
>   accept_socket( socket, sock, address );
>   --I wish I could do this
>   --accept_socket( socket, sock, address, timeout => 2.0, status => sel_stat );
>   ...
>   loop
>     receive_socket( sock, data, last );
>     ...
>   end loop;
>   close_socket( socket );
> end;
> 
> Thanks,
> Matt

Or you can use lib Anet.

[]'s Dani.

^ permalink raw reply	[relevance 0%]

* Re: alternative for buggy accept_socket to create a non-blocking version
  2017-10-25 17:23  6% alternative for buggy accept_socket to create a non-blocking version Matt Borchers
  2017-10-25 19:14  5% ` Matt Borchers
@ 2017-10-27  9:14  5% ` Björn Lundin
  2017-10-27 16:26  0% ` Daniel Norte Moraes
  2 siblings, 0 replies; 200+ results
From: Björn Lundin @ 2017-10-27  9:14 UTC (permalink / raw)


On 2017-10-25 19:23, Matt Borchers wrote:

> Does anybody know of a good way to create a type of non-blocking accept_socket?

put the socket in select (the socket function - not tasking) with a
timeout of 2 secs (in the readable set)
if select times out, you get 0 as retrun value,
 if select returns > 0 you have someone trying to connect.
You can then call accept and know it will not be blocking.

You may have to pragma import select
(And I hope it works with gnat.sockets)

looking into
<https://www2.adacore.com/gap-static/GNAT_Book/html/rts/g-socket__ads.htm>

  procedure Check_Selector

seem to be exactly this



> 
> My code basically is:
> 
> with GNAT.Sockets; use GNAT.Sockets;
> ...
> declare
>   sock,
>   socket   : SOCKET_TYPE;
>   address  : SOCK_ADDR_TYPE;
>   data     : STREAM_ELEMENT_ARRAY(1..256);
>   last     : STREAM_ELEMENT_OFFSET;
>   sel_stat : SELECTOR_STATUS;
> begin
>   create_socket( socket );
>   bind_socket( socket, address );
>   listen_socket( socket );
>   accept_socket( socket, sock, address );
>   --I wish I could do this
>   --accept_socket( socket, sock, address, timeout => 2.0, status => sel_stat );
>   ...
>   loop
>     receive_socket( sock, data, last );
>     ...
>   end loop;
>   close_socket( socket );
> end;
> 
> Thanks,
> Matt
> 


-- 
--
Björn

^ permalink raw reply	[relevance 5%]

* Re: alternative for buggy accept_socket to create a non-blocking version
  2017-10-25 19:14  5% ` Matt Borchers
@ 2017-10-26 13:43  0%   ` Shark8
  0 siblings, 0 replies; 200+ results
From: Shark8 @ 2017-10-26 13:43 UTC (permalink / raw)


On Wednesday, October 25, 2017 at 1:14:47 PM UTC-6, Matt Borchers wrote:
> Well, I should have thought of this solution sooner.  I downloaded the GNAT 6.3.2 version (where the bug is fixed) and I copied all of the execution path of the non-blocking accept_socket subprogram into a single subroutine in a new child package of GNAT.Sockets.
> 
> My first few tests are successful.

You could try using a Generic Package taking a TIMEOUT formal parameter (and if you're using task-interfaces, an interface to your socket-task) then simply have one task do your processing and the other send an abort to the other task if/when the timeout occurs.

^ permalink raw reply	[relevance 0%]

* Re: alternative for buggy accept_socket to create a non-blocking version
  2017-10-25 17:23  6% alternative for buggy accept_socket to create a non-blocking version Matt Borchers
@ 2017-10-25 19:14  5% ` Matt Borchers
  2017-10-26 13:43  0%   ` Shark8
  2017-10-27  9:14  5% ` Björn Lundin
  2017-10-27 16:26  0% ` Daniel Norte Moraes
  2 siblings, 1 reply; 200+ results
From: Matt Borchers @ 2017-10-25 19:14 UTC (permalink / raw)


Well, I should have thought of this solution sooner.  I downloaded the GNAT 6.3.2 version (where the bug is fixed) and I copied all of the execution path of the non-blocking accept_socket subprogram into a single subroutine in a new child package of GNAT.Sockets.

My first few tests are successful.

^ permalink raw reply	[relevance 5%]

* alternative for buggy accept_socket to create a non-blocking version
@ 2017-10-25 17:23  6% Matt Borchers
  2017-10-25 19:14  5% ` Matt Borchers
                   ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: Matt Borchers @ 2017-10-25 17:23 UTC (permalink / raw)


I have no choice but to use an old GNAT compiler -- version 6.3.0.  In this version there is a confirmed bug (fixed in 6.3.2) that prevents the non-blocking version of accept_socket from working.  I want to call the version of accept_socket with the 'timeout' parameter, but it doesn't do what it should.

Basically, I've built a way to read data from a socket and all goes well when a response is made.  However, I need a way to abandon the accept call if a response is never sent within a small time window.

This is my foray into sockets programming and I don't fully understand all of the nuances yet.  I tried setting the Receive_Timeout socket option but it had no effect -- I don't think it does what I need anyway.  This all seems pretty straight-forward assuming there is no bug in the non-blocking version of accept_socket, but I don't know how to work-around this bug.

I can imagine a pair of tasks in which one does the blocking accept (A) and the other task (B) does the time-out.  If the time-out occurs first, B will abort the task A otherwise after A succeeds in accepting the message it will abort B.  This seems like it might not be the best work-around solution.

Does anybody know of a good way to create a type of non-blocking accept_socket?

My code basically is:

with GNAT.Sockets; use GNAT.Sockets;
...
declare
  sock,
  socket   : SOCKET_TYPE;
  address  : SOCK_ADDR_TYPE;
  data     : STREAM_ELEMENT_ARRAY(1..256);
  last     : STREAM_ELEMENT_OFFSET;
  sel_stat : SELECTOR_STATUS;
begin
  create_socket( socket );
  bind_socket( socket, address );
  listen_socket( socket );
  accept_socket( socket, sock, address );
  --I wish I could do this
  --accept_socket( socket, sock, address, timeout => 2.0, status => sel_stat );
  ...
  loop
    receive_socket( sock, data, last );
    ...
  end loop;
  close_socket( socket );
end;

Thanks,
Matt

^ permalink raw reply	[relevance 6%]

* Re: Finding the end of a stream from a socket
  2017-10-22 12:26  0%         ` Andrew Shvets
@ 2017-10-22 12:28  0%           ` Andrew Shvets
  0 siblings, 0 replies; 200+ results
From: Andrew Shvets @ 2017-10-22 12:28 UTC (permalink / raw)


On Sunday, October 22, 2017 at 8:26:54 AM UTC-4, Andrew Shvets wrote:
> On Saturday, October 21, 2017 at 3:19:36 PM UTC-4, Dmitry A. Kazakov wrote:
> > On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> > > On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> > > <andr.....@gmail.com> declaimed the following:
> > > 
> > >>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
> > >>   GNAT.Sockets.Listen_Socket(Receiver);
> > >>
> > > 	From those statements I'm guessing you are trying to set this program
> > > up as a server, and have some other program which will connect to send data
> > > to this one.
> > > 
> > >>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
> > >>
> > >>   loop
> > >>     Ada.Text_IO.Put_Line(" FOO 1");
> > >>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> > > 
> > > 	But here you are saying /this/ program is going to connect to a server
> > > at (undefined) Client_Addr.
> > > 
> > > 	I suspect you really need to be using g.s.Accept_Socket() instead.
> > 
> > Also note that Accept_Socket will return another socket. This one you 
> > should use for communication.
> > 
> > A typical scenario for blocking sockets:
> > 
> >     loop -- Connection listening
> >        Accept_Socket -- Get communication socket
> >        Start a new session task with the communication socket
> >     end loop;
> > 
> > The session task deals with the connection using the socket returned by 
> > Accept_Socket. Once the session is complete it closes that socket and 
> > terminates.
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> One more question.  How do I convert a string to a Stream_Element?
> 
> 
> This is what I have:
> 
>   Out_String : constant String := "I like cake!";
>   Out_Data : Ada.Streams.Stream_Element_Array(1 .. 12);
> begin
> ...
>   for elem in 1 .. Out_Data'Length loop
>     Out_Data(Ada.Streams.Stream_Element_Offset(elem)) :=
>       Ada.Streams.Stream_Element(Character'Val(Out_String(elem)));
>   end loop;

I want to write this out to a receiver?

^ permalink raw reply	[relevance 0%]

* Re: Finding the end of a stream from a socket
  2017-10-21 19:19  0%       ` Dmitry A. Kazakov
  2017-10-21 19:46  0%         ` Andrew Shvets
@ 2017-10-22 12:26  0%         ` Andrew Shvets
  2017-10-22 12:28  0%           ` Andrew Shvets
  1 sibling, 1 reply; 200+ results
From: Andrew Shvets @ 2017-10-22 12:26 UTC (permalink / raw)


On Saturday, October 21, 2017 at 3:19:36 PM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> > On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> > <andr.....@gmail.com> declaimed the following:
> > 
> >>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
> >>   GNAT.Sockets.Listen_Socket(Receiver);
> >>
> > 	From those statements I'm guessing you are trying to set this program
> > up as a server, and have some other program which will connect to send data
> > to this one.
> > 
> >>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
> >>
> >>   loop
> >>     Ada.Text_IO.Put_Line(" FOO 1");
> >>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> > 
> > 	But here you are saying /this/ program is going to connect to a server
> > at (undefined) Client_Addr.
> > 
> > 	I suspect you really need to be using g.s.Accept_Socket() instead.
> 
> Also note that Accept_Socket will return another socket. This one you 
> should use for communication.
> 
> A typical scenario for blocking sockets:
> 
>     loop -- Connection listening
>        Accept_Socket -- Get communication socket
>        Start a new session task with the communication socket
>     end loop;
> 
> The session task deals with the connection using the socket returned by 
> Accept_Socket. Once the session is complete it closes that socket and 
> terminates.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

One more question.  How do I convert a string to a Stream_Element?


This is what I have:

  Out_String : constant String := "I like cake!";
  Out_Data : Ada.Streams.Stream_Element_Array(1 .. 12);
begin
...
  for elem in 1 .. Out_Data'Length loop
    Out_Data(Ada.Streams.Stream_Element_Offset(elem)) :=
      Ada.Streams.Stream_Element(Character'Val(Out_String(elem)));
  end loop;


^ permalink raw reply	[relevance 0%]

* Re: Finding the end of a stream from a socket
  2017-10-21 19:19  0%       ` Dmitry A. Kazakov
@ 2017-10-21 19:46  0%         ` Andrew Shvets
  2017-10-22 12:26  0%         ` Andrew Shvets
  1 sibling, 0 replies; 200+ results
From: Andrew Shvets @ 2017-10-21 19:46 UTC (permalink / raw)


On Saturday, October 21, 2017 at 3:19:36 PM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> > On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> > <and.....@gmail.com> declaimed the following:
> > 
> >>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
> >>   GNAT.Sockets.Listen_Socket(Receiver);
> >>
> > 	From those statements I'm guessing you are trying to set this program
> > up as a server, and have some other program which will connect to send data
> > to this one.
> > 
> >>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
> >>
> >>   loop
> >>     Ada.Text_IO.Put_Line(" FOO 1");
> >>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> > 
> > 	But here you are saying /this/ program is going to connect to a server
> > at (undefined) Client_Addr.
> > 
> > 	I suspect you really need to be using g.s.Accept_Socket() instead.
> 
> Also note that Accept_Socket will return another socket. This one you 
> should use for communication.
> 
> A typical scenario for blocking sockets:
> 
>     loop -- Connection listening
>        Accept_Socket -- Get communication socket
>        Start a new session task with the communication socket
>     end loop;
> 
> The session task deals with the connection using the socket returned by 
> Accept_Socket. Once the session is complete it closes that socket and 
> terminates.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de


Weird, I can't see Dennis' reply in this thread, but I see it in Dmitry's reply.


Anyway, thank you both for your help.  With your help, I figured out what my problem is and my example is working now.


^ permalink raw reply	[relevance 0%]

* Re: Finding the end of a stream from a socket
  2017-10-21 18:11  0%     ` Dennis Lee Bieber
@ 2017-10-21 19:19  0%       ` Dmitry A. Kazakov
  2017-10-21 19:46  0%         ` Andrew Shvets
  2017-10-22 12:26  0%         ` Andrew Shvets
  0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-10-21 19:19 UTC (permalink / raw)


On 2017-10-21 20:11, Dennis Lee Bieber wrote:
> On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
> <andrew.shvets@gmail.com> declaimed the following:
> 
>>   GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
>>   GNAT.Sockets.Listen_Socket(Receiver);
>>
> 	From those statements I'm guessing you are trying to set this program
> up as a server, and have some other program which will connect to send data
> to this one.
> 
>>   Ada.Text_IO.Put_Line(" !! TCP Server started !!");
>>
>>   loop
>>     Ada.Text_IO.Put_Line(" FOO 1");
>>     GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);
> 
> 	But here you are saying /this/ program is going to connect to a server
> at (undefined) Client_Addr.
> 
> 	I suspect you really need to be using g.s.Accept_Socket() instead.

Also note that Accept_Socket will return another socket. This one you 
should use for communication.

A typical scenario for blocking sockets:

    loop -- Connection listening
       Accept_Socket -- Get communication socket
       Start a new session task with the communication socket
    end loop;

The session task deals with the connection using the socket returned by 
Accept_Socket. Once the session is complete it closes that socket and 
terminates.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 0%]

* Re: Finding the end of a stream from a socket
  @ 2017-10-21 19:18  6%     ` Andrew Shvets
  0 siblings, 0 replies; 200+ results
From: Andrew Shvets @ 2017-10-21 19:18 UTC (permalink / raw)


On Saturday, October 21, 2017 at 1:34:15 PM UTC-4, Andrew Shvets wrote:
> On Saturday, October 21, 2017 at 4:44:42 AM UTC-4, Dmitry A. Kazakov wrote:
> > On 2017-10-21 04:05, Andrew Shvets wrote:
> > 
> > > I've been recently trying to make a small TCP server (a toy.) I have
> > > a channel that reads Characters and was trying to find the end of
> > > the stream. Reading the documentation, I came across the following
> > > in  g-socket.ads:
> > > 
> > > type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
> > > --  Same interface as Ada.Streams.Stream_IO
> > > 
> > > I was trying to have a way to find out when the last Character was 
> > > read from the stream. I could catch the Ada.IO_Exceptions.End_Error 
> > > exception, but I'm wondering if there is a better way.
> > 
> > End_Error is the best possible way, when applied. GNAT socket streams do 
> > not raise End_Error, AFAIK.
> > 
> > > while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
> > >    Character'Read(Channel, Received_Char);
> > >    Ada.Text_IO.Put(Received_Char);
> > > end loop;
> > 
> > This is a bad idea even when if it can work. In the case of sockets 
> > there is no file end. When the connection is closed by the peer the 
> > stream will stop both returning data and blocking. I suppose that will 
> > cause Constraint_Error in Character'Read.
> > 
> > In practice there is a higher level protocol on top of the socket 
> > stream, so that it is always known how many octets to read next.
> > 
> > Regarding your case, try this:
> > 
> >     Buffer : Stream_Element_Array (1..Buffer_Size);
> >     Last   : Stream_Element_Offset;
> > begin
> >     loop
> >        Receive_Socket (Socket, Buffer, Last);
> >        exit when Last < Buffer'First; -- Connection is closed by the peer
> >        for Octet in Buffer'First..Last loop -- Dump octets as-is
> >           Put (Character'Val (Buffer (Octet)));
> >        end loop;
> >     end loop;
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> Hi Dmitry,
> 
> This is my entire code.
> https://gist.github.com/anonymous/b7c3a5bdcd8c78453a643b6785573131

On this line:
GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);


I get the following exception:
!! TCP Server started !!
FOO 1

raised GNAT.SOCKETS.SOCKET_ERROR :[10022] Unknown system error


Weird, I thought, then I uncommented the Connect_Socket procedure call, since the socket is already being used to listen, it should be "connected".  When I did this, I got this error:

https://gist.github.com/anonymous/b79594f71309df87fc8fcc44bd6a28ee

What gets me, what is trying to connect from 0.0.0.0:0?  I have never seen or heard of this address being used.


^ permalink raw reply	[relevance 6%]

* Re: Finding the end of a stream from a socket
  2017-10-21 13:45  6%   ` Andrew Shvets
@ 2017-10-21 18:11  0%     ` Dennis Lee Bieber
  2017-10-21 19:19  0%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Dennis Lee Bieber @ 2017-10-21 18:11 UTC (permalink / raw)


On Sat, 21 Oct 2017 06:45:22 -0700 (PDT), Andrew Shvets
<andrew.shvets@gmail.com> declaimed the following:


>
>
>  loop
>    begin
>      GNAT.Sockets.Receive_Socket(Receiver, Buffer, Last);
>
>      -- the connection was reset by peer.
>      exit when Last < Buffer'First;
>
>      for Octet in Buffer'First .. Last loop
>        Ada.Text_IO.Put(Character'Val(Buffer(Octet)));
>      end loop;
>    exception
>      when Ada.IO_Exceptions.End_Error =>
>        Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, " ERROR: Issue encountered while receiving data from user.");
>    end;
>  end loop;
>
>
>I get the following error when I make the Receive_Socket procedure call:
>
>raised GNAT.SOCKETS.SOCKET_ERROR : [107] Transport endpoint is not connected


>  GNAT.Sockets.Bind_Socket(Receiver, (GNAT.Sockets.Family_Inet, GNAT.Sockets.Inet_Addr("127.0.0.1"), 50000));
>  GNAT.Sockets.Listen_Socket(Receiver);
>
	From those statements I'm guessing you are trying to set this program
up as a server, and have some other program which will connect to send data
to this one.


>  Ada.Text_IO.Put_Line(" !! TCP Server started !!");
>
>  loop
>    Ada.Text_IO.Put_Line(" FOO 1");
>    GNAT.Sockets.Connect_Socket(Receiver,  Client_Addr);

	But here you are saying /this/ program is going to connect to a server
at (undefined) Client_Addr.

	I suspect you really need to be using g.s.Accept_Socket() instead.

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

^ permalink raw reply	[relevance 0%]

* Re: Finding the end of a stream from a socket
  @ 2017-10-21 13:45  6%   ` Andrew Shvets
  2017-10-21 18:11  0%     ` Dennis Lee Bieber
    1 sibling, 1 reply; 200+ results
From: Andrew Shvets @ 2017-10-21 13:45 UTC (permalink / raw)


On Saturday, October 21, 2017 at 4:44:42 AM UTC-4, Dmitry A. Kazakov wrote:
> On 2017-10-21 04:05, Andrew Shvets wrote:
> 
> > I've been recently trying to make a small TCP server (a toy.) I have
> > a channel that reads Characters and was trying to find the end of
> > the stream. Reading the documentation, I came across the following
> > in  g-socket.ads:
> > 
> > type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class;
> > --  Same interface as Ada.Streams.Stream_IO
> > 
> > I was trying to have a way to find out when the last Character was 
> > read from the stream. I could catch the Ada.IO_Exceptions.End_Error 
> > exception, but I'm wondering if there is a better way.
> 
> End_Error is the best possible way, when applied. GNAT socket streams do 
> not raise End_Error, AFAIK.
> 
> > while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
> >    Character'Read(Channel, Received_Char);
> >    Ada.Text_IO.Put(Received_Char);
> > end loop;
> 
> This is a bad idea even when if it can work. In the case of sockets 
> there is no file end. When the connection is closed by the peer the 
> stream will stop both returning data and blocking. I suppose that will 
> cause Constraint_Error in Character'Read.
> 
> In practice there is a higher level protocol on top of the socket 
> stream, so that it is always known how many octets to read next.
> 
> Regarding your case, try this:
> 
>     Buffer : Stream_Element_Array (1..Buffer_Size);
>     Last   : Stream_Element_Offset;
> begin
>     loop
>        Receive_Socket (Socket, Buffer, Last);
>        exit when Last < Buffer'First; -- Connection is closed by the peer
>        for Octet in Buffer'First..Last loop -- Dump octets as-is
>           Put (Character'Val (Buffer (Octet)));
>        end loop;
>     end loop;
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Thanks for your reply.  I did what you recommended.


  loop
    begin
      GNAT.Sockets.Receive_Socket(Receiver, Buffer, Last);

      -- the connection was reset by peer.
      exit when Last < Buffer'First;

      for Octet in Buffer'First .. Last loop
        Ada.Text_IO.Put(Character'Val(Buffer(Octet)));
      end loop;
    exception
      when Ada.IO_Exceptions.End_Error =>
        Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error, " ERROR: Issue encountered while receiving data from user.");
    end;
  end loop;


I get the following error when I make the Receive_Socket procedure call:

raised GNAT.SOCKETS.SOCKET_ERROR : [107] Transport endpoint is not connected


^ permalink raw reply	[relevance 6%]

* Finding the end of a stream from a socket
@ 2017-10-21  2:05  4% Andrew Shvets
    0 siblings, 1 reply; 200+ results
From: Andrew Shvets @ 2017-10-21  2:05 UTC (permalink / raw)


Hello,

I've been recently trying to make a small TCP server (a toy.)  I have a channel that reads Characters and was trying to find the end of the stream.  Reading the documentation, I came across the following in g-socket.ads:


type Stream_Access is access all Ada.Streams.Root_Stream_Type'Class; 
--  Same interface as Ada.Streams.Stream_IO


I was trying to have a way to find out when the last Character was read from the stream.  I could catch the Ada.IO_Exceptions.End_Error exception, but I'm wondering if there is a better way.


Channel       : GNAT.Sockets.Stream_Access;

....

while not Ada.Streams.Stream_IO.End_Of_File(Channel) loop
  Character'Read(Channel, Received_Char);
  Ada.Text_IO.Put(Received_Char);
end loop;





Many thank yous in advance for your help!


^ permalink raw reply	[relevance 4%]

* ANN: Simple Components for Ada v4.24
@ 2017-10-01 13:44  6% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-10-01 13:44 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, multiple connections server/client designing 
tools. The library is kept conform to the Ada 95, Ada 2005, Ada 2012 
language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- The package Object.Archived.Handle now accepts unconstrained object types;
- Procedure Received added to the package GNAT.Sockets.Server;
- All registered to 2017-09-13 URI schemes added to the HTTP server 
implementation;
- Upgrade_Insecure_Requests response header was added to the HTTP server 
implementation;
- Package GNAT.Sockets.NTP added to support simple NTP time queries.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 6%]

* Re: NTP
  @ 2017-09-16  9:29  5% ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-09-16  9:29 UTC (permalink / raw)


On 2017-09-16 08:40, Anatoly Chernyshev wrote:

> Is there a way to get time via the Network Time Protocol in Ada? It
> doesn't look like AWS has it (or I've missed something).
> 
> Currently I'm getting around spawning the Cygwin "nc" command, but it hurts my feelings.

Do you mean send a single UDP request to an NTP server and convert the 
response to Ada time?

You can try this:
----------------------------------------------------------------------
with Ada.Text_IO;              use Ada.Text_IO;
with Ada.Calendar;             use Ada.Calendar;
with Ada.Calendar.Formatting;  use Ada.Calendar.Formatting;
with Ada.Exceptions;           use Ada.Exceptions;
with Ada.Streams;              use Ada.Streams;
with GNAT.Sockets;             use GNAT.Sockets;
with Interfaces;               use Interfaces;

procedure Test is

    function Get_NTP_Time
             (  Server  : String;
                Timeout : Timeval_Duration := 10.0
             )  return Time is
       NTP_Packet_Size : constant := 48;
          -- RFC 5905: Official NTP era begins at 1 Jan 1900. We cannot
          -- have it in Ada.Calendar.Time, so taking a later time. Note
          -- Time_Zone = 0 in order to have it UTC
       Era : constant Time := Time_Of (1999, 12, 31, Time_Zone => 0);
          -- RFC 5905: seconds since 1 Jan 1900 to 31 Dec 1999
       Era_Offset : constant := 3_155_587_200;

       Socket   : Socket_Type;
       Address  : Sock_Addr_Type;
       Seconds  : Unsigned_32;
       Fraction : Unsigned_32;
       Last     : Stream_Element_Offset;
       Data     : Stream_Element_Array (1..NTP_Packet_Size) :=
                     (  1  => 2#1110_0011#, -- LI, Version, Mode
                        2  => 0,            -- Stratum, or type of clock
                        3  => 0,            -- Polling Interval
                        4  => 16#EC#,       -- Peer Clock Precision
                        13 => 49,
                        14 => 16#4E#,
                        15 => 49,
                        16 => 52,
                        others => 0
                     );
    begin
       Address.Addr := Addresses (Get_Host_By_Name (Server), 1);
       Address.Port := 123; -- NTP port
       Create_Socket (Socket, Family_Inet, Socket_Datagram);
       Set_Socket_Option
       (  Socket,
          Socket_Level,
          (Receive_Timeout, Timeout)
       );
       Send_Socket (Socket, Data, Last, Address);
       Receive_Socket (Socket, Data, Last, Address);
       if Last /= Data'Last then
          Raise_Exception (Data_Error'Identity, "Mangled response");
       end if;
       Seconds := (  Unsigned_32 (Data (41)) * 2**24
                  +  Unsigned_32 (Data (42)) * 2**16
                  +  Unsigned_32 (Data (43)) * 2**8
                  +  Unsigned_32 (Data (44))
                  -  Era_OFfset
                  );
       Fraction := (  Unsigned_32 (Data (45)) * 2**24
                   +  Unsigned_32 (Data (46)) * 2**16
                   +  Unsigned_32 (Data (47)) * 2**8
                   +  Unsigned_32 (Data (48))
                   );
       return (  Era
              +  Duration (Seconds)
         --     +  Duration (Long_Float (Fraction) / 2.0**32)
              );
    end Get_NTP_Time;

    Stamp : Time;
begin
    Stamp := Get_NTP_Time ("time.nist.gov");
    Put_Line ("NTP time " & Image (Stamp));
exception
    when Error : others =>
       Put_Line ("Error: " & Exception_Information (Error));
end Test;
-------------------------------------------------------------------

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: HTTP with Simple Components: Status.Kind always File
  2017-07-19 16:09  0%   ` Felix Krause
@ 2017-07-19 16:33  0%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-07-19 16:33 UTC (permalink / raw)


On 2017-07-19 18:09, Felix Krause wrote:
> On 2017-07-17 20:59:32 +0000, Dmitry A. Kazakov said:
>>
>> If I correctly understand the issue, the HTTP request line must 
>> contain a schema.
>>
>> If you take a look into the source, parsing gets the method (e.g. GET) 
>> then it checks (gnat-sockets-connection_state_machine-http_server.adb, 
>> 1540):
>>
>>     if Request (Pointer) = '*' then
>>        ...
>>     elsif Request (Pointer) = '/' then
>>        ...
>>     else
>>        ...
>>     end if;
>>
>> The first does nothing, the second creates Kind => File, the third 
>> creates Kind => URI. So Kind = File should be when the request like 
>> looked like:
>>
>>     GET /something/somewhere...
>>
>> URI when:
>>
>>     GET http://www.something/somewhere...
> 
> Well, this is the behavior I expect, but I *am* querying the server with 
> an URI containing a schema.

How do you know? How exactly looks the request? If you don't trust the 
integrated trace you can use Wireshark to be sure.

> For example:
> 
>     curl http://localhost:8088/
> 
> This still yields a File as Status.Kind.

I must see what is sent from the client in order to tell if it is a bug 
or correct behavior. A command line tells nothing.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Re: HTTP with Simple Components: Status.Kind always File
  2017-07-17 20:59  5% ` Dmitry A. Kazakov
@ 2017-07-19 16:09  0%   ` Felix Krause
  2017-07-19 16:33  0%     ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Felix Krause @ 2017-07-19 16:09 UTC (permalink / raw)


On 2017-07-17 20:59:32 +0000, Dmitry A. Kazakov said:
> 
> If I correctly understand the issue, the HTTP request line must contain 
> a schema.
> 
> If you take a look into the source, parsing gets the method (e.g. GET) 
> then it checks (gnat-sockets-connection_state_machine-http_server.adb, 
> 1540):
> 
>     if Request (Pointer) = '*' then
>        ...
>     elsif Request (Pointer) = '/' then
>        ...
>     else
>        ...
>     end if;
> 
> The first does nothing, the second creates Kind => File, the third 
> creates Kind => URI. So Kind = File should be when the request like 
> looked like:
> 
>     GET /something/somewhere...
> 
> URI when:
> 
>     GET http://www.something/somewhere...

Well, this is the behavior I expect, but I *am* querying the server 
with an URI containing a schema. For example:

    curl http://localhost:8088/

This still yields a File as Status.Kind. This is what bothers me.


^ permalink raw reply	[relevance 0%]

* Re: send email
  @ 2017-07-18  7:48  4% ` Björn Lundin
  0 siblings, 0 replies; 200+ results
From: Björn Lundin @ 2017-07-18  7:48 UTC (permalink / raw)


On 2017-06-28 11:25, Distant Worlds wrote:

> 
> 
> /********************************************************************/
> 
> raised PROGRAM_ERROR : finalize/adjust raised exception
>    
> /********************************************************************/
>      
>      CentOS 6.9 Ada GNAT 2017
>        
>        
>>> :((
>        
> 

I got this running fine seding mails from Amazon.
I _think_ you need a Credential parameter in the Initialize if you say
Secure => True
And I could not point out the path to the cert, had to make that current
directory. But that may have changed now.


  procedure Mail_Saldo(Saldo, Old : Balances.Balance_Type) is
     T       : Calendar2.Time_Type := Calendar2.Clock;
     Subject : constant String             := "BetBot Saldo Report";
     use AWS;
     SMTP_Server_Name : constant String :=
     "email-smtp.eu-west-1.amazonaws.com";
     Status : SMTP.Status;
  begin

Ada.Directories.Set_Directory(Ada.Environment_Variables.Value("BOT_CONFIG")
& "/sslcert");
    declare
      Auth : aliased constant SMTP.Authentication.Plain.Credential :=
                                SMTP.Authentication.Plain.Initialize
("AKESJZDQQ2DDNB58SKQ",
                                              "SOME scrabled string");
      SMTP_Server : SMTP.Receiver := SMTP.Client.Initialize
                                  (SMTP_Server_Name,
                                   Port       => 2465,
                                   Secure     => True,
                                   Credential => Auth'Unchecked_Access);
      use Ada.Characters.Latin_1;
      Today     : Fixed_Type := Saldo.Balance + abs(Saldo.Exposure);
      Yesterday : Fixed_Type := Old.Balance + abs(Old.Exposure);
      Msg : constant String :=
          "some MSG sent from: " & GNAT.Sockets.Host_Name ;

      Receivers : constant SMTP.Recipients :=  (
                An array of the receivers
                );
    begin
      SMTP.Client.Send(Server  => SMTP_Server,
                       From    => SMTP.E_Mail ("someone",
"someone@someone.com"),
                       To      => Receivers,
                       Subject => Subject,
                       Message => Msg,
                       Status  => Status);
    end;
    if not SMTP.Is_Ok (Status) then
      Log (Me & "Mail_Saldo", "Can't send message: " &
SMTP.Status_Message (Status));
    end if;
  end Mail_Saldo;



-- 
--
Björn


^ permalink raw reply	[relevance 4%]

* Re: HTTP with Simple Components: Status.Kind always File
  2017-07-17 18:30  6% HTTP with Simple Components: Status.Kind always File Felix Krause
@ 2017-07-17 20:59  5% ` Dmitry A. Kazakov
  2017-07-19 16:09  0%   ` Felix Krause
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-07-17 20:59 UTC (permalink / raw)


On 2017-07-17 20:30, Felix Krause wrote:
> I am trying to implement an HTTP server with Simple Components. My 
> problem is that whenever I send a request to the server, in Do_Get, 
> Status.Kind is File instead of URI. Relevant parts of my code:
> 
>     package Yaml.Servers is
>        package HTTP renames 
> GNAT.Sockets.Connection_State_Machine.HTTP_Server;
>        package Server renames GNAT.Sockets.Server;
> 
>        type Yaml_Factory (Request_Length  : Positive;
>                           Input_Size      : Server.Buffer_Length;
>                           Output_Size     : Server.Buffer_Length;
>                           Max_Connections : Positive) is
>          new Server.Connections_Factory with null record;
> 
>        type Yaml_Client is new HTTP.HTTP_Client with null record;
> 
>        overriding function Create (Factory  : access Yaml_Factory;
>                                    Listener : access 
> Server.Connections_Server'Class;
>                                    From     : GNAT.Sockets.Sock_Addr_Type)
>                                    return Server.Connection_Ptr is
>           (new Yaml_Client (Listener       => 
> Listener.all'Unchecked_Access,
>                             Request_Length => Factory.Request_Length,
>                             Input_Size     => Factory.Input_Size,
>                             Output_Size    => Factory.Output_Size));
> 
>        overriding procedure Do_Get (Client : in out Yaml_Client);
>     end Yaml.Servers;
> 
>     package body Yaml.Servers is
>        procedure Do_Get (Client : in out Yaml_Client) is
>           Status : HTTP.Status_Line renames Get_Status_Line (Client);
>        begin
>           case Status.Kind is
>              when HTTP.None =>
>                 ...
>              when HTTP.File =>
>                 ...
>              when HTTP.URI =>
>                 ...
>           end case;
>        end Do_Get;
>     end Yaml.Servers;
> 
>     procedure Yaml.Server is
>        Factory : aliased Servers.Yaml_Factory (200, 80, 8192, 100);
>        Server  : Servers.Server.Connections_Server (Factory'Access, 8088);
>        pragma Unreferenced (Server);
>     begin
>        Ada.Text_IO.Put_Line ("HTTP server started.");
>        loop
>           delay 60.0;
>        end loop;
>     end Yaml.Server;
> 
> Now I run this server behind an nginx, and it responds as expected. 
> However, when I access it with an URI `http://ada.yaml.io/widget/`, 
> inside Do_Get, Status.Kind is File. Why is this? With the File kind, I 
> cannot possibly parse the query at this point, because I cannot 
> differentiate between `%26` and `&` (entities have already been resolved).
> 
> I also tested this locally with `http://localhost:8888/widget/`, and 
> that also yields a file.
> 
> How can I make the HTTP server to yield an URI instead of a File?

If I correctly understand the issue, the HTTP request line must contain 
a schema.

If you take a look into the source, parsing gets the method (e.g. GET) 
then it checks (gnat-sockets-connection_state_machine-http_server.adb, 
1540):

    if Request (Pointer) = '*' then
       ...
    elsif Request (Pointer) = '/' then
       ...
    else
       ...
    end if;

The first does nothing, the second creates Kind => File, the third 
creates Kind => URI. So Kind = File should be when the request like 
looked like:

    GET /something/somewhere...

URI when:

    GET http://www.something/somewhere...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* HTTP with Simple Components: Status.Kind always File
@ 2017-07-17 18:30  6% Felix Krause
  2017-07-17 20:59  5% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Felix Krause @ 2017-07-17 18:30 UTC (permalink / raw)


I am trying to implement an HTTP server with Simple Components. My 
problem is that whenever I send a request to the server, in Do_Get, 
Status.Kind is File instead of URI. Relevant parts of my code:

    package Yaml.Servers is
       package HTTP renames GNAT.Sockets.Connection_State_Machine.HTTP_Server;
       package Server renames GNAT.Sockets.Server;

       type Yaml_Factory (Request_Length  : Positive;
                          Input_Size      : Server.Buffer_Length;
                          Output_Size     : Server.Buffer_Length;
                          Max_Connections : Positive) is
         new Server.Connections_Factory with null record;

       type Yaml_Client is new HTTP.HTTP_Client with null record;

       overriding function Create (Factory  : access Yaml_Factory;
                                   Listener : access 
Server.Connections_Server'Class;
                                   From     : GNAT.Sockets.Sock_Addr_Type)
                                   return Server.Connection_Ptr is
          (new Yaml_Client (Listener       => Listener.all'Unchecked_Access,
                            Request_Length => Factory.Request_Length,
                            Input_Size     => Factory.Input_Size,
                            Output_Size    => Factory.Output_Size));

       overriding procedure Do_Get (Client : in out Yaml_Client);
    end Yaml.Servers;

    package body Yaml.Servers is
       procedure Do_Get (Client : in out Yaml_Client) is
          Status : HTTP.Status_Line renames Get_Status_Line (Client);
       begin
          case Status.Kind is
             when HTTP.None =>
                ...
             when HTTP.File =>
                ...
             when HTTP.URI =>
                ...
          end case;
       end Do_Get;
    end Yaml.Servers;

    procedure Yaml.Server is
       Factory : aliased Servers.Yaml_Factory (200, 80, 8192, 100);
       Server  : Servers.Server.Connections_Server (Factory'Access, 8088);
       pragma Unreferenced (Server);
    begin
       Ada.Text_IO.Put_Line ("HTTP server started.");
       loop
          delay 60.0;
       end loop;
    end Yaml.Server;

Now I run this server behind an nginx, and it responds as expected. 
However, when I access it with an URI `http://ada.yaml.io/widget/`, 
inside Do_Get, Status.Kind is File. Why is this? With the File kind, I 
cannot possibly parse the query at this point, because I cannot 
differentiate between `%26` and `&` (entities have already been 
resolved).

I also tested this locally with `http://localhost:8888/widget/`, and 
that also yields a file.

How can I make the HTTP server to yield an URI instead of a File?

Cheers,
Felix

^ permalink raw reply	[relevance 6%]

* Re: GNAT.Sockets Streaming inefficiency
  2017-06-09 15:24  5%   ` Dmitry A. Kazakov
@ 2017-06-19  9:22  6%     ` masterglob
  0 siblings, 0 replies; 200+ results
From: masterglob @ 2017-06-19  9:22 UTC (permalink / raw)


Le vendredi 9 juin 2017 17:24:24 UTC+2, Dmitry A. Kazakov a écrit :
> On 2017-06-09 15:30, gautier_niouzes@hotmail.com wrote:
> 
> > It could be related to a performance bottleneck in 'Read and 'Write,
> > perhaps more than to the nature of the stream (socket vs. file vs. ...).
> 
> 1. Without NODELAY. Writes are buffered and spilled out either when the 
> buffer is full or when the coalescing algorithm timeout expired. With 
> string length is not a multiply of the buffer and moderate output rate 
> or synchronized output, the last frame carrying the string will be 
> always delayed. So the observed latency will be more or less the 
> coalescing algorithm timeout.
> 
> 2. With NODELAY. Individual writes are sent in independent frames. If 
> 'Output or 'Write write individual characters separately, plus the 
> string bounds, then the network gets flooded with short frames and the 
> latency depends on how good the stack, the OS, the network 
> infrastructure are.
> 
> In either scenario there is nothing good to expect.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

I currently do not use "NO_DELAY", but the thing is that the "producer" process is 100%. This tends to indicate that it is not this kind of issue (I would have long execution time, but not a 100% CPU usage).

I have to try other implementations proposed (like using something else than Stream 'write & 'Read)


^ permalink raw reply	[relevance 6%]

* Re: GNAT.Sockets Streaming inefficiency
  2017-06-09 13:30  5% ` gautier_niouzes
@ 2017-06-09 15:24  5%   ` Dmitry A. Kazakov
  2017-06-19  9:22  6%     ` masterglob
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-06-09 15:24 UTC (permalink / raw)


On 2017-06-09 15:30, gautier_niouzes@hotmail.com wrote:

> It could be related to a performance bottleneck in 'Read and 'Write,
> perhaps more than to the nature of the stream (socket vs. file vs. ...).

1. Without NODELAY. Writes are buffered and spilled out either when the 
buffer is full or when the coalescing algorithm timeout expired. With 
string length is not a multiply of the buffer and moderate output rate 
or synchronized output, the last frame carrying the string will be 
always delayed. So the observed latency will be more or less the 
coalescing algorithm timeout.

2. With NODELAY. Individual writes are sent in independent frames. If 
'Output or 'Write write individual characters separately, plus the 
string bounds, then the network gets flooded with short frames and the 
latency depends on how good the stack, the OS, the network 
infrastructure are.

In either scenario there is nothing good to expect.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: GNAT.Sockets Streaming inefficiency
  2017-06-08 10:36 11% GNAT.Sockets Streaming inefficiency masterglob
  2017-06-08 14:46  6% ` Dmitry A. Kazakov
  2017-06-08 15:39  6% ` Robert Eachus
@ 2017-06-09 13:30  5% ` gautier_niouzes
  2017-06-09 15:24  5%   ` Dmitry A. Kazakov
  2 siblings, 1 reply; 200+ results
From: gautier_niouzes @ 2017-06-09 13:30 UTC (permalink / raw)


Hello,

It could be related to a performance bottleneck in 'Read and 'Write, perhaps more than to the nature of the stream (socket vs. file vs. ...).

For instance, copying a file with different methods leads to the following timings (here using a byte buffer of sizes 1KB, then 1MB):

xxx'Write / xxx'Read (Stream attributes)......... 0.247916104 seconds
Workarounds with Stream_Element_Array buffer:
  copy (byte buffer from/to SE buffer)........... 0.005628329 seconds
  overlay (read), unchecked_conversion (write)... 0.005184935 seconds
  overlay (read and write)....................... 0.005185743 seconds
Factor (Copy)    44.047905515
Factor (UC)      47.814698544
Factor (Overlay) 47.807248450
Buffer size in bytes..... 1024

xxx'Write / xxx'Read (Stream attributes)......... 0.326904305 seconds
Workarounds with Stream_Element_Array buffer:
  copy (byte buffer from/to SE buffer)........... 0.002427558 seconds
  overlay (read), unchecked_conversion (write)... 0.001585229 seconds
  overlay (read and write)....................... 0.001425978 seconds
Factor (Copy)    134.663849432
Factor (UC)      206.218978456
Factor (Overlay) 229.249192484
Buffer size in bytes..... 1048576

This is with GNAT GPL 2016 / Windows with full "fast mode" switches. There were similar factors when the issue was discoverd in ~2008.
The test procedure is test/test_stream_performance.adb in the Zip-Ada project.
HTH
_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 


^ permalink raw reply	[relevance 5%]

* Re: GNAT.Sockets Streaming inefficiency
  2017-06-08 10:36 11% GNAT.Sockets Streaming inefficiency masterglob
  2017-06-08 14:46  6% ` Dmitry A. Kazakov
@ 2017-06-08 15:39  6% ` Robert Eachus
  2017-06-09 13:30  5% ` gautier_niouzes
  2 siblings, 0 replies; 200+ results
From: Robert Eachus @ 2017-06-08 15:39 UTC (permalink / raw)


On Thursday, June 8, 2017 at 6:36:01 AM UTC-4, maste...@gmail.com wrote:
> Configuration: X64, Linux & Windows (GNATPRO 7.4.2)
> While using GNAT.Sockets.Stream_Access, there is a real performance issue while using String'Output(...).
> 
> My test sends 500 times a 1024-long String using String'Output(TCP_Stream on 127.0.0.1) and the result is:
> - Linux : average 'output duration = 3 us
> - Windows: average 'output duration = 250 us
> 
> From prior discussion with AdaCore, the "String" type is the only one for which this latency is NOT observed on Linux.
> 
> Any idea on:
> - is there a way to get similar performance on Windows (maybe using another type or method?)
> - is there any configuration that may solve this issue?

Have you tried declaring an array of bytes type, and doing an unchecked conversion? Remember that you need the two types to match exactly the descriptive information at the beginning of the objects.

^ permalink raw reply	[relevance 6%]

* Re: GNAT.Sockets Streaming inefficiency
  2017-06-08 10:36 11% GNAT.Sockets Streaming inefficiency masterglob
@ 2017-06-08 14:46  6% ` Dmitry A. Kazakov
  2017-06-08 15:39  6% ` Robert Eachus
  2017-06-09 13:30  5% ` gautier_niouzes
  2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-06-08 14:46 UTC (permalink / raw)


On 08/06/2017 12:36, masterglob@gmail.com wrote:
> Configuration: X64, Linux & Windows (GNATPRO 7.4.2)
> While using GNAT.Sockets.Stream_Access, there is a real performance issue while using String'Output(...).
> 
> My test sends 500 times a 1024-long String using String'Output(TCP_Stream on 127.0.0.1) and the result is:
> - Linux : average 'output duration = 3 us
> - Windows: average 'output duration = 250 us
> 
>  From prior discussion with AdaCore, the "String" type is the only one for which this latency is NOT observed on Linux.
> 
> Any idea on:
> - is there a way to get similar performance on Windows (maybe using another type or method?)
> - is there any configuration that may solve this issue?

As a rule you should never use socket stream, especially if you are 
concerned about latencies. Because then you should have used NO_DELAY 
option on the sockets at the both sides. You would send full protocol 
packets (which with NO_DELAY set become frames). Consequently you would 
use Send_Socket once the packet is in the output buffer 
(Stream_Element_Array).

P.S. If you use socket stream then do stream's Write operation.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 6%]

* GNAT.Sockets Streaming inefficiency
@ 2017-06-08 10:36 11% masterglob
  2017-06-08 14:46  6% ` Dmitry A. Kazakov
                   ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: masterglob @ 2017-06-08 10:36 UTC (permalink / raw)


Configuration: X64, Linux & Windows (GNATPRO 7.4.2)
While using GNAT.Sockets.Stream_Access, there is a real performance issue while using String'Output(...).

My test sends 500 times a 1024-long String using String'Output(TCP_Stream on 127.0.0.1) and the result is:
- Linux : average 'output duration = 3 us
- Windows: average 'output duration = 250 us

From prior discussion with AdaCore, the "String" type is the only one for which this latency is NOT observed on Linux.

Any idea on:
- is there a way to get similar performance on Windows (maybe using another type or method?)
- is there any configuration that may solve this issue?


=============
Result on W7/64
---------
OS=Windows_NT  cygwin
GNAT Pro 7.4.2 (20160527-49)
[SERVER] start...
[SERVER]:bind... 127.0.0.1:4264
[CLIENT] connected...
[SERVER]:connection from 127.0.0.1:56008
[SERVER] Sending 500 messages ...
[CLIENT] waiting for 500 messages ...
[CLIENT]:execution time:  0.000000000
[Server] execution time ( 500msg):  0.140400900 s
[Server] Output_Exec time (1 msg):  0.280801800 ms
[Server] Output_Duration time (1 msg):  0.263417164 ms

=============
Result on Ubuntu/64
---------
OS= 
GNAT Pro 7.4.2 (20160527-49)
[SERVER] start...
[SERVER]:bind... 127.0.0.1:4264
[SERVER]:connection from 127.0.0.1:52574
[CLIENT] connected...
[SERVER] Sending 500 messages ...
[CLIENT] waiting for 500 messages ...
[Server] execution time ( 500msg):  0.001783393 s
[Server] Output_Exec time (1 msg):  0.003072174 ms
[Server] Output_Duration time (1 msg):  0.003204778 ms
[CLIENT]:execution time:  0.001561405

=============
Makefile:
---------
all:build exec
build:
	@gprbuild -p -Ptest_stream_socket_string.gpr
exec: 
	@echo "OS=$$OS  $$OSTYPE"
	@echo $$(gnat --version|head -1)
	@obj/test_stream_socket_string



=============
test_stream_socket_string.gpr:
---------
project Test_Stream_Socket_String is

   for Object_Dir  use "obj";
   for Exec_Dir    use "obj";
   for Main        use ("test_stream_socket_string.adb");
   for Source_Dirs use (".");
   for Languages use ("Ada");

   package Builder is
      for Default_Switches ("Ada") use ("-g","-s","-j0");
   end Builder;

   package Compiler is
      Ada_Opt   := ("-O0");
      Ada_Comp    := ("-gnat12","-g","-gnatU","-gnato","-gnatVa","-fstack-check","-fstack-usage","-gnateE","-gnateF");
      Ada_Style   := ("-gnaty3aAbBCdefhiklL15M120nOprStux");
      Ada_Warning := ("-gnatwah.h.o.st.w");
      for Default_Switches ("Ada") use Ada_Opt & Ada_Comp & Ada_Warning & Ada_Style;
   end Compiler;

   package Binder is
      for Default_Switches ("Ada") use ("-v","-E","-R","-T0");
   end Binder;

   package Linker is
      for Default_Switches ("Ada") use ("-g","-v") ;
   end Linker;

end Test_Stream_Socket_String;



=============
test_stream_socket_string.adb
---------
with Ada.Execution_Time,
     Ada.Real_Time,
     Ada.Text_IO,
     Ada.Exceptions,

     GNAT.Sockets,
     GNAT.Traceback.Symbolic,
     GNAT.OS_Lib;
use GNAT,
    Ada;

use type GNAT.Sockets.Selector_Status,
         Ada.Real_Time.Time,
         Ada.Execution_Time.CPU_Time;

procedure Test_Stream_Socket_String is

   Port    : constant Sockets.Port_Type := 4264;
   Ip_Addr : constant String := "127.0.0.1";

   task type Client_Thread_T is
      entry Start;
      entry Synch;
      entry Wait;
   end Client_Thread_T;
   Client_Thread : Client_Thread_T;
   task type Server_Thread_T is
      entry Start;
      entry Wait;
   end Server_Thread_T;
   Server_Thread : Server_Thread_T;
   
   task body Client_Thread_T is
   
   task body Server_Thread_T is
      Nb_Loop         : constant := 500;
      Cpt             : Integer := Nb_Loop;
      Msg_Size        : constant :=  1024; -- 1 Ko
      Exec_Start_Time : Execution_Time.CPU_Time;
      Exec_Output1    : Execution_Time.CPU_Time;
      Exec_Output2    : Real_Time.Time;
      Output_Exec     : Duration := 0.0;
      Output_Duration : Duration := 0.0;
      Listen          : Sockets.Socket_Type;
      Client          : Sockets.Socket_Type;
      Address         : Sockets.Sock_Addr_Type := (Family => Sockets.Family_Inet,
                                                   Addr   => Sockets.Inet_Addr (Ip_Addr),
                                                   Port   => Port);
      Channel         : Sockets.Stream_Access;
   begin
      accept Start;
      Text_IO.Put_Line ("[SERVER] start...");

      Sockets.Create_Socket (Socket => Listen);
      Text_IO.Put_Line ("[SERVER]:bind... " & Sockets.Image (Address));
      Sockets.Bind_Socket (Socket  => Listen,
                           Address => Address);
      Sockets.Listen_Socket (Listen);

      Sockets.Accept_Socket (Listen, Client, Address);
      Text_IO.Put_Line ("[SERVER]:connection from " & Sockets.Image (Sockets.Get_Peer_Name (Client)));
      Channel := Sockets.Stream (Socket => Client);
      Exec_Start_Time := Execution_Time.Clock;

      Integer'Output (Channel, Cpt);
         Text_IO.Put_Line ("[SERVER] Sending" & Cpt'Img & " messages ...");
      
      while Cpt > 0 loop
         -- Text_IO.Put ('+');
         declare
            S : constant String (1 .. Msg_Size) := (others => '?');
         begin
            Exec_Output1 := Execution_Time.Clock;
            Exec_Output2 := Real_Time.Clock;
            String'Output (Channel, S);
            Output_Exec := Output_Exec + 
              Real_Time.To_Duration (Execution_Time.Clock - Exec_Output1);
            Output_Duration := Output_Duration + 
              Real_Time.To_Duration (Real_Time.Clock - Exec_Output2);
         end;

         Cpt := Cpt - 1;

      end loop;

      Text_IO.Put_Line ("[Server] execution time (" & Nb_Loop'Img & "msg): " &
                          Real_Time.To_Duration (Execution_Time.Clock - Exec_Start_Time)'Img & " s");

      Text_IO.Put_Line ("[Server] Output_Exec time (1 msg): " &
                          Duration'Image (1000.0 * Output_Exec / (Nb_Loop - Cpt)) & " ms");
      Text_IO.Put_Line ("[Server] Output_Duration time (1 msg): " &
                          Duration'Image (1000.0 * Output_Duration / (Nb_Loop - Cpt)) & " ms");

      Sockets.Close_Socket (Socket => Listen);

      accept Wait;
      -- Text_IO.New_Line;
   exception
      when E : others =>
         Text_IO.New_Line;
         Text_IO.Put_Line ("[Server] Exception: " & Exceptions.Exception_Information (E));
         Text_IO.Put_Line (Exceptions.Exception_Message (E));
         Text_IO.Put_Line (Traceback.Symbolic.Symbolic_Traceback (E));
         if Cpt /= Nb_Loop then
            Text_IO.Put_Line ("[Server] Output_Duration time: " &
                                Duration'Image (1000.0 * Output_Duration / (Nb_Loop - Cpt)) & " ms");
         end if;
         GNAT.OS_Lib.OS_Abort;
   end Server_Thread_T;
   
begin
   Server_Thread.Start;
   Client_Thread.Start;
   Client_Thread.Synch;
   Server_Thread.Wait;
   
   Client_Thread.Wait;
   -- Text_IO.New_Line;
exception
   when E : others =>
      Text_IO.Put_Line (Exceptions.Exception_Information (E));
      Text_IO.Put_Line (Exceptions.Exception_Message (E));
      Text_IO.Put_Line (Traceback.Symbolic.Symbolic_Traceback (E));
end Test_Stream_Socket_String;

^ permalink raw reply	[relevance 11%]

* Re: Microsoft UWP/WinRt
  2017-06-02 14:53  0%       ` gautier_niouzes
  2017-06-02 14:56  0%         ` Dmitry A. Kazakov
@ 2017-06-02 21:11  0%         ` Randy Brukardt
  1 sibling, 0 replies; 200+ results
From: Randy Brukardt @ 2017-06-02 21:11 UTC (permalink / raw)


<gautier_niouzes@hotmail.com> wrote in message 
news:6726e56e-6c49-433e-ac4e-0d31d287c822@googlegroups.com...
>> Win32Ada is used less frequently because GNAT provides a nice set of
>> OS-abstraction packages (GNAT sockets, serial COMM etc) and because for
>> GUI design Gtk, Qt, Gnoga are more attractive.
>
> Not forgetting GWindows (for Windows only) !...

And of course Claw (which GWindows was a knock-off of).

                  Randy.


^ permalink raw reply	[relevance 0%]

* Re: Microsoft UWP/WinRt
  2017-06-02 14:53  0%       ` gautier_niouzes
@ 2017-06-02 14:56  0%         ` Dmitry A. Kazakov
  2017-06-02 21:11  0%         ` Randy Brukardt
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-06-02 14:56 UTC (permalink / raw)


On 2017-06-02 16:53, gautier_niouzes@hotmail.com wrote:
>> Win32Ada is used less frequently because GNAT provides a nice set of
>> OS-abstraction packages (GNAT sockets, serial COMM etc) and because for
>> GUI design Gtk, Qt, Gnoga are more attractive.
> 
> Not forgetting GWindows (for Windows only) !...

Well, IMO if Windows only then Windows bindings only.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 0%]

* Re: Microsoft UWP/WinRt
  2017-06-02 13:28  5%     ` Dmitry A. Kazakov
@ 2017-06-02 14:53  0%       ` gautier_niouzes
  2017-06-02 14:56  0%         ` Dmitry A. Kazakov
  2017-06-02 21:11  0%         ` Randy Brukardt
  0 siblings, 2 replies; 200+ results
From: gautier_niouzes @ 2017-06-02 14:53 UTC (permalink / raw)


> Win32Ada is used less frequently because GNAT provides a nice set of 
> OS-abstraction packages (GNAT sockets, serial COMM etc) and because for 
> GUI design Gtk, Qt, Gnoga are more attractive.

Not forgetting GWindows (for Windows only) !...

Gautier
___________________________________________________
A free online game in Ada: http://pasta.phyrama.com


^ permalink raw reply	[relevance 0%]

* Re: Microsoft UWP/WinRt
  @ 2017-06-02 13:28  5%     ` Dmitry A. Kazakov
  2017-06-02 14:53  0%       ` gautier_niouzes
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2017-06-02 13:28 UTC (permalink / raw)


On 02/06/2017 14:27, Lucretia wrote:

> Never heard of Win32Ada, where's this then?

It comes with GNAT GPL and Pro for Windows.

It is [necessarily] never complete, yet contains all essential Windows 
API parts (def, crt, ole, base etc). It is thin bindings and quite easy 
to extend if something is amiss.

Win32Ada is used less frequently because GNAT provides a nice set of 
OS-abstraction packages (GNAT sockets, serial COMM etc) and because for 
GUI design Gtk, Qt, Gnoga are more attractive.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* ANN: Simple Components for Ada v4.19
@ 2017-02-20 17:53  6% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2017-02-20 17:53 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, multiple connections server/client designing 
tools. The library is kept conform to the Ada 95, Ada 2005, Ada 2012 
language standards.

    http://www.dmitry-kazakov.de/ada/components.htm

Changes to the previous version:

- Set_Thermostat_Temperature and Set_Thermostat_Automatic procedures of 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client allow 
specifying the temperature even if the thermostat is in the automatic mode;
- Downed primitive operations were added to GNAT.Sockets.Server package.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 6%]

* ANN: Simple Components v4.17 released
@ 2016-11-19 12:06  6% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2016-11-19 12:06 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, multiple connections server/client designing tools.

http://www.dmitry-kazakov.de/ada/components.htm

Changes the previous version:

- Bug fix in GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client 
related to decoding valve position;
- Set_Thermostat_Valve procedures were added to 
GNAT.Sockets.Connection_State_Machine.ELV_MAX_Cube_Client;
- Set_Thermostat_Parameters and Set_Thermostat_Schedule have the mode 
parameter added.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Gnat Sockets - UDP timeout too short.
  2016-10-12 14:23  9% Gnat Sockets - UDP timeout too short ahlan
@ 2016-11-04  8:48 11% ` ahlan.marriott
  0 siblings, 0 replies; 200+ results
From: ahlan.marriott @ 2016-11-04  8:48 UTC (permalink / raw)


On Wednesday, 12 October 2016 16:23:39 UTC+2, ah...@marriott.org  wrote:
> Under Microsoft Windows 8.1 (and later) Gnat.Sockets.Receive_Socket returns too early whilst waiting for a UDP datagram.
> In our test program (below) we create a UDP socket, set the timeout for one second, bind it to a port and then call receive on the socket.
> We catch and resolve the Socket_Error exception and process the expected Connection_Timed_Out.
> We note the time before issuing Receive_Socket and the time when we catch the exception and then compare the elapsed time with the receive timeout.
> On Window systems prior to Win8.1 this seems to work as expected, the elapsed time is always greater than the receive timeout.
> However under Win8.1 (and later) the call to Receive_Socket returns approximately half a second too early!
> 
> Curiously, if I write the same thing using the Win32.WinSock API then it works as expected. Which I find odd because I would have thought that Gnat.Sockets would simply be a series of wrappers around a few WinApi calls. But then what do I know?
> 
> The effect of this bug is that programs using UDP protocols timeout earlier than they should do - which often leads to curious behaviour.
> 
> We have tested this on a couple of PCs running a variety of flavours of Ms-Windows. So far it seems that XP & Win7 work as expected whereas Win8 and Win10 fail.
> 
> Has anyone any idea what might cause this problem and how we might go about fixing it?
> 
> Best wishes,
> MfG
> Ahlan
> 
> ------------------------------
> with Ada.Text_IO;
> with Ada.Exceptions;
> with Ada.Real_Time;
> with Ada.Streams;
> with GNAT.Sockets;
> 
> package body Test is
> 
>   package Io  renames Ada.Text_IO;
>   package Net renames GNAT.Sockets;
> 
>   Receive_Timeout : constant Duration := 1.0;
> 
>   Receive_Timeout_Span : constant Ada.Real_Time.Time_Span := Ada.Real_Time.To_Time_Span (Receive_Timeout);
> 
>   procedure Work is
>     The_Datagram : Ada.Streams.Stream_Element_Array (1..20);
>     The_Last     : Ada.Streams.Stream_Element_Offset;
>     The_Socket   : Net.Socket_Type;
>     Start_Time   : Ada.Real_Time.Time;
>     End_Time     : Ada.Real_Time.Time;
>     use type Ada.Real_Time.Time;
>   begin
>     Net.Create_Socket (Socket => The_Socket,
>                        Family => Net.Family_Inet,
>                        Mode   => Net.Socket_Datagram);
>     Net.Set_Socket_Option (Socket => The_Socket,
>                            Option => (Net.Receive_Timeout, Timeout => Receive_Timeout));
>     Net.Bind_Socket (The_Socket, (Family => Net.Family_Inet,
>                                   Addr   => Net.Any_Inet_Addr,
>                                   Port   => 11154));
>     loop
>       begin
>         Start_Time := Ada.Real_Time.Clock;
>         Net.Receive_Socket (Socket => The_Socket,
>                             Item   => The_Datagram,
>                             Last   => The_Last);
>         Io.New_Line;
>         Io.Put_Line ("Unexpected reply!");
>         exit;
>       exception
>       when Occurrence: Net.Socket_Error =>
>         End_Time := Ada.Real_Time.Clock;
>         declare
>           Error : constant Net.Error_Type := Net.Resolve_Exception (Occurrence);
>           use type Net.Error_Type;
>         begin
>           if Error = Net.Connection_Timed_Out then
>             if End_Time >= (Start_Time + Receive_Timeout_Span) then
>               Io.Put (".");
>             else
>               Io.New_Line;
>               declare
>                 use type Ada.Real_Time.Time_Span;
>                 Shortfall : constant Ada.Real_Time.Time_Span := Receive_Timeout_Span - (End_Time - Start_Time);
>               begin
>                 Io.Put_Line ("Timeout too short by" & Ada.Real_Time.To_Duration (Shortfall)'img & "seconds");
>               end;
>             end if;
>           else
>             Io.Put_Line ("Socket_Error : Unexpected error=" & Error'img);
>             exit;
>           end if;
>         end;
>       when Event : others =>
>         Io.Put_Line ("Unexpected exception: " & Ada.Exceptions.Exception_Name (Event));
>       end;
>     end loop;
>   exception
>   when Event : others =>
>     Io.Put_Line ("Internal Error: " & Ada.Exceptions.Exception_Name (Event));
>   end Work;
To answer my own question...
Gnat sockets uses the Winsock function Recv and sets the timeout DWORD SO_RCVTIMEO in Milliseconds.
However according to the Microsoft Developers Network in Feb 2014 (and others articles) there was an undocumented minimum limit of 500ms which seems to have been implemented by Microsoft simply adding 500ms to whatever non-zero value was placed in SO_RECVTIMEO.
The consensus workaround was simply to deduct 500ms from the desired timeout.
This is indeed what Gnat.Sockets seems to have implemented at line 2297 in g-socket.adb
if V4 > 500 then V4 := V4 - 500; elsif v4 > 0 then V4 := 1 endif;
At line 1249 in g-socket.adb the 500 is added again if the timeout is retrieved.

It seems to me that recent versions of Windows no longer adds 500ms to the Recv timeout.
This would explain why under Win8 and Win10 our receive of UDP datagrams timeout half a second too soon.

Gnat.Sockets needs to determine the version of windows and only apply the correction if necessary.

The fun of course is going to be finding our which versions of Windows need the correction and which don’t. ;-)
Win8.1 and Win10 don't, Win7 and WinXp do.
Can anyone add to this list?

Best wishes
MfG
Ahlan


^ permalink raw reply	[relevance 11%]

* ANN: Simple Components for Ada v 4.16
@ 2016-10-13 16:54  5% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2016-10-13 16:54 UTC (permalink / raw)


The current version provides implementations of smart pointers, directed 
graphs, sets, maps, B-trees, stacks, tables, string editing, unbounded 
arrays, expression analyzers, lock-free data structures, synchronization 
primitives (events, race condition free pulse events, arrays of events, 
reentrant mutexes, deadlock-free arrays of mutexes), pseudo-random 
non-repeating numbers, symmetric encoding and decoding, IEEE 754 
representations support, multiple connections server/client designing tools.

http://www.dmitry-kazakov.de/ada/components.htm

This version fixes a bug in GNAT.Sockets.Server. The bug caused 
Constraint_Error in upon stopping a client after it failed to connect.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Gnat Sockets - UDP timeout too short.
@ 2016-10-12 14:23  9% ahlan
  2016-11-04  8:48 11% ` ahlan.marriott
  0 siblings, 1 reply; 200+ results
From: ahlan @ 2016-10-12 14:23 UTC (permalink / raw)


Under Microsoft Windows 8.1 (and later) Gnat.Sockets.Receive_Socket returns too early whilst waiting for a UDP datagram.
In our test program (below) we create a UDP socket, set the timeout for one second, bind it to a port and then call receive on the socket.
We catch and resolve the Socket_Error exception and process the expected Connection_Timed_Out.
We note the time before issuing Receive_Socket and the time when we catch the exception and then compare the elapsed time with the receive timeout.
On Window systems prior to Win8.1 this seems to work as expected, the elapsed time is always greater than the receive timeout.
However under Win8.1 (and later) the call to Receive_Socket returns approximately half a second too early!

Curiously, if I write the same thing using the Win32.WinSock API then it works as expected. Which I find odd because I would have thought that Gnat.Sockets would simply be a series of wrappers around a few WinApi calls. But then what do I know?

The effect of this bug is that programs using UDP protocols timeout earlier than they should do - which often leads to curious behaviour.

We have tested this on a couple of PCs running a variety of flavours of Ms-Windows. So far it seems that XP & Win7 work as expected whereas Win8 and Win10 fail.

Has anyone any idea what might cause this problem and how we might go about fixing it?

Best wishes,
MfG
Ahlan

------------------------------
with Ada.Text_IO;
with Ada.Exceptions;
with Ada.Real_Time;
with Ada.Streams;
with GNAT.Sockets;

package body Test is

  package Io  renames Ada.Text_IO;
  package Net renames GNAT.Sockets;

  Receive_Timeout : constant Duration := 1.0;

  Receive_Timeout_Span : constant Ada.Real_Time.Time_Span := Ada.Real_Time.To_Time_Span (Receive_Timeout);

  procedure Work is
    The_Datagram : Ada.Streams.Stream_Element_Array (1..20);
    The_Last     : Ada.Streams.Stream_Element_Offset;
    The_Socket   : Net.Socket_Type;
    Start_Time   : Ada.Real_Time.Time;
    End_Time     : Ada.Real_Time.Time;
    use type Ada.Real_Time.Time;
  begin
    Net.Create_Socket (Socket => The_Socket,
                       Family => Net.Family_Inet,
                       Mode   => Net.Socket_Datagram);
    Net.Set_Socket_Option (Socket => The_Socket,
                           Option => (Net.Receive_Timeout, Timeout => Receive_Timeout));
    Net.Bind_Socket (The_Socket, (Family => Net.Family_Inet,
                                  Addr   => Net.Any_Inet_Addr,
                                  Port   => 11154));
    loop
      begin
        Start_Time := Ada.Real_Time.Clock;
        Net.Receive_Socket (Socket => The_Socket,
                            Item   => The_Datagram,
                            Last   => The_Last);
        Io.New_Line;
        Io.Put_Line ("Unexpected reply!");
        exit;
      exception
      when Occurrence: Net.Socket_Error =>
        End_Time := Ada.Real_Time.Clock;
        declare
          Error : constant Net.Error_Type := Net.Resolve_Exception (Occurrence);
          use type Net.Error_Type;
        begin
          if Error = Net.Connection_Timed_Out then
            if End_Time >= (Start_Time + Receive_Timeout_Span) then
              Io.Put (".");
            else
              Io.New_Line;
              declare
                use type Ada.Real_Time.Time_Span;
                Shortfall : constant Ada.Real_Time.Time_Span := Receive_Timeout_Span - (End_Time - Start_Time);
              begin
                Io.Put_Line ("Timeout too short by" & Ada.Real_Time.To_Duration (Shortfall)'img & "seconds");
              end;
            end if;
          else
            Io.Put_Line ("Socket_Error : Unexpected error=" & Error'img);
            exit;
          end if;
        end;
      when Event : others =>
        Io.Put_Line ("Unexpected exception: " & Ada.Exceptions.Exception_Name (Event));
      end;
    end loop;
  exception
  when Event : others =>
    Io.Put_Line ("Internal Error: " & Ada.Exceptions.Exception_Name (Event));
  end Work;


^ permalink raw reply	[relevance 9%]

* Re: Question on bounded / unbounded strings
  2016-09-24 17:44  3%             ` Dmitry A. Kazakov
  2016-09-24 18:37  0%               ` John Smith
@ 2016-09-24 18:59  0%               ` John Smith
  1 sibling, 0 replies; 200+ results
From: John Smith @ 2016-09-24 18:59 UTC (permalink / raw)


On Saturday, September 24, 2016 at 1:45:14 PM UTC-4, Dmitry A. Kazakov wrote:
> >>> If you need to separate a large string into a bunch smaller ones
> >>> that  do not have a pre-determined size, using a fixed string does not make
> >>> any sense.
> >>
> >> I *never* need that. It was discussed already.
> >
> > If a file is read in (the format is non-standard) and you now need
> > to  sift through the details of the file, you will need this.
> 
> Searching for a pattern / skipping irrelevant parts of the input do not 
> require that. No need to split anything.
> 

Then how would you accomplish this?

> >>> When you do need to build a string, it is far easier to have one
> >>> unbounded string that is added on to and then written out.
> >>
> >> No, it is easier with fixed strings.
> >
> > How?
> >
> > I've tried going to the example on your website, but it seems that that is down.
> 
> Hmm, it is not down:
> 
> http://www.dmitry-kazakov.de/ada/strings_edit.htm
> http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc
> 

I'll have a look when I get home.

> >>> Having a
> >>> fixed string means that I woul need something along the lines of a
> >>> recursive solution, since I can't extent the size of the string after
> >>> it's been instantiated.
> >>
> >> The output length for formatted output is always known. Normally the
> >> parts of a composite string are statically known, that precludes
> >> iteration or recursion. In other cases, like building a directory path
> >> from some structure, I first calculate the length and then declare the
> >> result string.
> >
> > No, it is almost always unknown in my experience :-). If I'm putting
> > together a report that needs to be e-mailed out, I have no idea how long
> > it will be. I would first need to do my thing, get the string returned
> > from it, append it to an accumulator string and after all of that was
> > done, I can now know its length.
> 
> But a mail body is not a string! If you send a MIME attachment the 
> natural way to do it is to use a stream as the source. String can be 
> used, but for short text mails only.
> 
> I believe AWS takes streams for attachment. My implementation of SMTP 
> certainly does:
> 
> http://www.dmitry-kazakov.de/ada/components.htm#GNAT.Sockets.SMTP.Client.Attach_Stream
> 

Sure it is.  This is especially true when it comes to sending out a string e-mail (and a bunch of HTML can be put on a single line.)  But the e-mail example is just one that I could think of on a dime.

I'll have a look at what you did when I get home.

> > If I were to first run my analysis, get the length of the string
> > (which is the result that will go out), then keep doing this until I'm
> > finished (at which point I will be able to figure out how big my
> > accumulator is supposed to be.) Now, I would have to re-run my analysis
> > again and then copy in the results into the my newly allocated
> > accumulator string. That would make for some needlessly complex logic in
> > my application (as opposed to just dump everything to an unbounded string.)
> 
> I would use a stream on top of a segmented buffer, e.g.
> 
> http://www.dmitry-kazakov.de/ada/components.htm#Storage_Streams
> 
> Or a FIFO if the producer of the content and the SMTP client are run by 
> different tasks.
> 
> You don't need to build all attachment in the memory in order to be able 
> to send it.
> 

I disagree.  If I write out the attachment to disk and then e-mail it, that's even more overhead.  Why do this?  Create a neat package in memory, e-mail it out and then forget about it.  Doing this operation in memory would be easier and faster.  And I don't have to worry about temporary files or any other files (as well as deleting the files, testing this additional logic, etc.)

> > However, if I ever need string functionality that I'm used to in
> > Python or C++, Unbounded strings are the only reasonable solution.
> 
> You used to use dynamic strings. But there is no evidence they really 
> simpler to use. In my code which varies from network protocols to 
> compiler developing tools and AI you will find almost no 
> Unbounded_Strings. Would it be simpler with Unbounded_Strings? I doubt it.
> 

When I get home, I'll have a look at what you've written.

^ permalink raw reply	[relevance 0%]

* Re: Question on bounded / unbounded strings
  2016-09-24 17:44  3%             ` Dmitry A. Kazakov
@ 2016-09-24 18:37  0%               ` John Smith
  2016-09-24 18:59  0%               ` John Smith
  1 sibling, 0 replies; 200+ results
From: John Smith @ 2016-09-24 18:37 UTC (permalink / raw)


On Saturday, September 24, 2016 at 1:45:14 PM UTC-4, Dmitry A. Kazakov wrote:
> On 2016-09-24 18:25, John Smith wrote:
> > On Saturday, September 24, 2016 at 3:52:54 AM UTC-4, Dmitry A. Kazakov wrote:
> >> On 2016-09-24 01:58, John Smith wrote:
> >>> On Thursday, September 22, 2016 at 3:25:18 AM UTC-4, Dmitry A. Kazakov wrote:
> >>>> On 22/09/2016 04:10, John Smith wrote:
> >>>>
> >>>>> I've found the ease with which you can append or manipulate unbounded
> >>>>> strings to be very convenient.
> >>>>
> >>>> 1. There is no need to append to a string in no less than 90% of cases.
> >>>
> >>> The percentage in this case depends on what application you are
> >>> developing. Sometimes you will need to do this more often, sometimes
> >>> less often.
> >>
> >> Yes, this "sometimes" is 10% of all "sometimes", or less.
> >
> > 10 percent of all string operations?
> 
> 10% of *applications*.
> 
> The type String does not have operation "append". There is only 
> concatenation operation "&".
> 
> > Again, I stand by what I said
> > about this being dependent on the application that is being developed.
> 
> Yes. In all applications I developed Unbounded_String was used in far 
> less than 10% of the cases when strings were involved.
> 
> >>> If anything, a fixed string is less convenient since you need to
> >>> walk  on eggshells and cannot simply assign a new value to the existing string.
> >>
> >> Which I never have to. If you assign strings reconsider the algorithm,
> >> there is certainly something wrong with it. Strings may be rearranged,
> >> never assigned.
> >
> > Again, this depends on the application being developed and how the
> > information is flowing inside it.
> 
> Sure. I never assign strings as a whole except for initialization purpose.
> 
> >>> If you need to separate a large string into a bunch smaller ones
> >>> that  do not have a pre-determined size, using a fixed string does not make
> >>> any sense.
> >>
> >> I *never* need that. It was discussed already.
> >
> > If a file is read in (the format is non-standard) and you now need
> > to  sift through the details of the file, you will need this.
> 
> Searching for a pattern / skipping irrelevant parts of the input do not 
> require that. No need to split anything.
> 
> >>> When you do need to build a string, it is far easier to have one
> >>> unbounded string that is added on to and then written out.
> >>
> >> No, it is easier with fixed strings.
> >
> > How?
> >
> > I've tried going to the example on your website, but it seems that that is down.
> 
> Hmm, it is not down:
> 
> http://www.dmitry-kazakov.de/ada/strings_edit.htm
> http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc
> 
> >>> Having a
> >>> fixed string means that I woul need something along the lines of a
> >>> recursive solution, since I can't extent the size of the string after
> >>> it's been instantiated.
> >>
> >> The output length for formatted output is always known. Normally the
> >> parts of a composite string are statically known, that precludes
> >> iteration or recursion. In other cases, like building a directory path
> >> from some structure, I first calculate the length and then declare the
> >> result string.
> >
> > No, it is almost always unknown in my experience :-). If I'm putting
> > together a report that needs to be e-mailed out, I have no idea how long
> > it will be. I would first need to do my thing, get the string returned
> > from it, append it to an accumulator string and after all of that was
> > done, I can now know its length.
> 
> But a mail body is not a string! If you send a MIME attachment the 
> natural way to do it is to use a stream as the source. String can be 
> used, but for short text mails only.
> 
> I believe AWS takes streams for attachment. My implementation of SMTP 
> certainly does:
> 
> http://www.dmitry-kazakov.de/ada/components.htm#GNAT.Sockets.SMTP.Client.Attach_Stream
> 
> > If I were to first run my analysis, get the length of the string
> > (which is the result that will go out), then keep doing this until I'm
> > finished (at which point I will be able to figure out how big my
> > accumulator is supposed to be.) Now, I would have to re-run my analysis
> > again and then copy in the results into the my newly allocated
> > accumulator string. That would make for some needlessly complex logic in
> > my application (as opposed to just dump everything to an unbounded string.)
> 
> I would use a stream on top of a segmented buffer, e.g.
> 
> http://www.dmitry-kazakov.de/ada/components.htm#Storage_Streams
> 
> Or a FIFO if the producer of the content and the SMTP client are run by 
> different tasks.
> 
> You don't need to build all attachment in the memory in order to be able 
> to send it.
> 
> It is a pity that nobody cares about proper organization of text 
> processing in these days, even here in c.l.a.
> 
> If you like me have 2GB+ of text trace and text editors written by 
> people believing in "splitting strings", then you have to wait 20 
> minutes before the editor shows the file contents, 40 first lines. If it 
> does not crash before and take the OS with. Guess why?
> 
> > However, if I ever need string functionality that I'm used to in
> > Python or C++, Unbounded strings are the only reasonable solution.
> 
> You used to use dynamic strings. But there is no evidence they really 
> simpler to use. In my code which varies from network protocols to 
> compiler developing tools and AI you will find almost no 
> Unbounded_Strings. Would it be simpler with Unbounded_Strings? I doubt it.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

It seems that the wifi that I'm on is timing out the connection to your entire domain.  Yay for parental controls...

Very annoying.


^ permalink raw reply	[relevance 0%]

* Re: Question on bounded / unbounded strings
  @ 2016-09-24 17:44  3%             ` Dmitry A. Kazakov
  2016-09-24 18:37  0%               ` John Smith
  2016-09-24 18:59  0%               ` John Smith
  0 siblings, 2 replies; 200+ results
From: Dmitry A. Kazakov @ 2016-09-24 17:44 UTC (permalink / raw)


On 2016-09-24 18:25, John Smith wrote:
> On Saturday, September 24, 2016 at 3:52:54 AM UTC-4, Dmitry A. Kazakov wrote:
>> On 2016-09-24 01:58, John Smith wrote:
>>> On Thursday, September 22, 2016 at 3:25:18 AM UTC-4, Dmitry A. Kazakov wrote:
>>>> On 22/09/2016 04:10, John Smith wrote:
>>>>
>>>>> I've found the ease with which you can append or manipulate unbounded
>>>>> strings to be very convenient.
>>>>
>>>> 1. There is no need to append to a string in no less than 90% of cases.
>>>
>>> The percentage in this case depends on what application you are
>>> developing. Sometimes you will need to do this more often, sometimes
>>> less often.
>>
>> Yes, this "sometimes" is 10% of all "sometimes", or less.
>
> 10 percent of all string operations?

10% of *applications*.

The type String does not have operation "append". There is only 
concatenation operation "&".

> Again, I stand by what I said
> about this being dependent on the application that is being developed.

Yes. In all applications I developed Unbounded_String was used in far 
less than 10% of the cases when strings were involved.

>>> If anything, a fixed string is less convenient since you need to
>>> walk  on eggshells and cannot simply assign a new value to the existing string.
>>
>> Which I never have to. If you assign strings reconsider the algorithm,
>> there is certainly something wrong with it. Strings may be rearranged,
>> never assigned.
>
> Again, this depends on the application being developed and how the
> information is flowing inside it.

Sure. I never assign strings as a whole except for initialization purpose.

>>> If you need to separate a large string into a bunch smaller ones
>>> that  do not have a pre-determined size, using a fixed string does not make
>>> any sense.
>>
>> I *never* need that. It was discussed already.
>
> If a file is read in (the format is non-standard) and you now need
> to  sift through the details of the file, you will need this.

Searching for a pattern / skipping irrelevant parts of the input do not 
require that. No need to split anything.

>>> When you do need to build a string, it is far easier to have one
>>> unbounded string that is added on to and then written out.
>>
>> No, it is easier with fixed strings.
>
> How?
>
> I've tried going to the example on your website, but it seems that that is down.

Hmm, it is not down:

http://www.dmitry-kazakov.de/ada/strings_edit.htm
http://www.dmitry-kazakov.de/ada/components.htm#Parsers_etc

>>> Having a
>>> fixed string means that I woul need something along the lines of a
>>> recursive solution, since I can't extent the size of the string after
>>> it's been instantiated.
>>
>> The output length for formatted output is always known. Normally the
>> parts of a composite string are statically known, that precludes
>> iteration or recursion. In other cases, like building a directory path
>> from some structure, I first calculate the length and then declare the
>> result string.
>
> No, it is almost always unknown in my experience :-). If I'm putting
> together a report that needs to be e-mailed out, I have no idea how long
> it will be. I would first need to do my thing, get the string returned
> from it, append it to an accumulator string and after all of that was
> done, I can now know its length.

But a mail body is not a string! If you send a MIME attachment the 
natural way to do it is to use a stream as the source. String can be 
used, but for short text mails only.

I believe AWS takes streams for attachment. My implementation of SMTP 
certainly does:

http://www.dmitry-kazakov.de/ada/components.htm#GNAT.Sockets.SMTP.Client.Attach_Stream

> If I were to first run my analysis, get the length of the string
> (which is the result that will go out), then keep doing this until I'm
> finished (at which point I will be able to figure out how big my
> accumulator is supposed to be.) Now, I would have to re-run my analysis
> again and then copy in the results into the my newly allocated
> accumulator string. That would make for some needlessly complex logic in
> my application (as opposed to just dump everything to an unbounded string.)

I would use a stream on top of a segmented buffer, e.g.

http://www.dmitry-kazakov.de/ada/components.htm#Storage_Streams

Or a FIFO if the producer of the content and the SMTP client are run by 
different tasks.

You don't need to build all attachment in the memory in order to be able 
to send it.

It is a pity that nobody cares about proper organization of text 
processing in these days, even here in c.l.a.

If you like me have 2GB+ of text trace and text editors written by 
people believing in "splitting strings", then you have to wait 20 
minutes before the editor shows the file contents, 40 first lines. If it 
does not crash before and take the OS with. Guess why?

> However, if I ever need string functionality that I'm used to in
> Python or C++, Unbounded strings are the only reasonable solution.

You used to use dynamic strings. But there is no evidence they really 
simpler to use. In my code which varies from network protocols to 
compiler developing tools and AI you will find almost no 
Unbounded_Strings. Would it be simpler with Unbounded_Strings? I doubt it.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 3%]

* Re: IPv6 + UDP  alternative to Gnat.Sockets ?
  2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
                   ` (4 preceding siblings ...)
  2016-09-19 22:36  6% ` Daniel Norte Moraes
@ 2016-09-20 23:51  6% ` Daniel Norte Moraes
  5 siblings, 0 replies; 200+ results
From: Daniel Norte Moraes @ 2016-09-20 23:51 UTC (permalink / raw)


sexta-feira, 16 de Setembro de 2016 às 17:58:49 UTC-3, Daniel Norte Moraes escreveu:
> Hi!
> 
>    Are There alternatives to gnat.sockets ( with ipv6 and udp ) ?
> 
>    Thanks in Advance!
> 
>    []'s Dani.

   Hi! Jrmarino, Stephen. Per Sandberg!

   Libanet fulfills my need.
   
   Thanks !!!!!!!!!!!! :-)

^ permalink raw reply	[relevance 6%]

* Re: IPv6 + UDP  alternative to Gnat.Sockets ?
  2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
                   ` (3 preceding siblings ...)
  2016-09-19 17:04  6% ` jrmarino
@ 2016-09-19 22:36  6% ` Daniel Norte Moraes
  2016-09-20 23:51  6% ` Daniel Norte Moraes
  5 siblings, 0 replies; 200+ results
From: Daniel Norte Moraes @ 2016-09-19 22:36 UTC (permalink / raw)


sexta-feira, 16 de Setembro de 2016 às 17:58:49 UTC-3, Daniel Norte Moraes escreveu:
> Hi!
> 
>    Are There alternatives to gnat.sockets ( with ipv6 and udp ) ?
> 
>    Thanks in Advance!
> 
>    []'s Dani.

Very Very Thanks Jrmarino!
I'll try it. 

[]'s Dani.

p.s.: in this meantime, I'll like others suggestions.

Thanks All for all in Advance.

[]'s Dani.

^ permalink raw reply	[relevance 6%]

* Re: IPv6 + UDP  alternative to Gnat.Sockets ?
  2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
                   ` (2 preceding siblings ...)
  2016-09-18 21:56 13% ` Daniel Norte Moraes
@ 2016-09-19 17:04  6% ` jrmarino
  2016-09-19 22:36  6% ` Daniel Norte Moraes
  2016-09-20 23:51  6% ` Daniel Norte Moraes
  5 siblings, 0 replies; 200+ results
From: jrmarino @ 2016-09-19 17:04 UTC (permalink / raw)


Have you seen ANet ?

https://codelabs.ch/anet/index.html


^ permalink raw reply	[relevance 6%]

* Re: IPv6 + UDP  alternative to Gnat.Sockets ?
  2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
  2016-09-17 14:12  6% ` Per Sandberg
  2016-09-17 18:08  6% ` Daniel Norte Moraes
@ 2016-09-18 21:56 13% ` Daniel Norte Moraes
  2016-09-19 17:04  6% ` jrmarino
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 200+ results
From: Daniel Norte Moraes @ 2016-09-18 21:56 UTC (permalink / raw)


  Hi! 

 Gnat gpl 2016 gnat.sockets have ipv6 But only for 'connect'. I printed all sources and related sources  just to discover =>  'bind()' have a big 'raise exception' if the address is in ipv6. this was a unpleasant surprise.

  my system use a ipv6+ipv4(in same network port, using ipv4 coded in ipv6[eg: ::ffff:1.2.3.4 ]).   Without this, gnat.sockets ( a great initial promise) become useless to me. Well... Patience. :-)

[]'s Dani




^ permalink raw reply	[relevance 13%]

* Re: IPv6 + UDP  alternative to Gnat.Sockets ?
  2016-09-17 18:08  6% ` Daniel Norte Moraes
@ 2016-09-18 20:33 12%   ` Stephen Leake
  0 siblings, 0 replies; 200+ results
From: Stephen Leake @ 2016-09-18 20:33 UTC (permalink / raw)


On Saturday, September 17, 2016 at 1:09:00 PM UTC-5, Daniel Norte Moraes wrote:
> sexta-feira, 16 de Setembro de 2016 às 17:58:49 UTC-3, Daniel Norte Moraes escreveu:
> > Hi!
> > 
> >    Are There alternatives to gnat.sockets ( with ipv6 and udp ) ?
> > 
> >    Thanks in Advance!
> > 
> >    []'s Dani.
> 
> yes. ada.sockets dont permit 'bind' with ipv6. 
> 
> Thanks in Advance!

GNAT GPL 2016 GNAT.Sockets has support for ipv6 addresses.

So perhaps you need to upgrade.

^ permalink raw reply	[relevance 12%]

* Re: IPv6 + UDP  alternative to Gnat.Sockets ?
  2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
  2016-09-17 14:12  6% ` Per Sandberg
@ 2016-09-17 18:08  6% ` Daniel Norte Moraes
  2016-09-18 20:33 12%   ` Stephen Leake
  2016-09-18 21:56 13% ` Daniel Norte Moraes
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 200+ results
From: Daniel Norte Moraes @ 2016-09-17 18:08 UTC (permalink / raw)


sexta-feira, 16 de Setembro de 2016 às 17:58:49 UTC-3, Daniel Norte Moraes escreveu:
> Hi!
> 
>    Are There alternatives to gnat.sockets ( with ipv6 and udp ) ?
> 
>    Thanks in Advance!
> 
>    []'s Dani.

yes. ada.sockets dont permit 'bind' with ipv6. 

Thanks in Advance!


^ permalink raw reply	[relevance 6%]

* Re: IPv6 + UDP alternative to Gnat.Sockets ?
  2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
@ 2016-09-17 14:12  6% ` Per Sandberg
  2016-09-17 18:08  6% ` Daniel Norte Moraes
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 200+ results
From: Per Sandberg @ 2016-09-17 14:12 UTC (permalink / raw)



Why do you need another socket binding ????



Den 2016-09-16 kl. 22:58, skrev Daniel Norte Moraes:
>    Hi!
>
>    Are There alternatives to gnat.sockets ( with ipv6 and udp ) ?
>
>    Thanks in Advance!
>
>    []'s Dani.
>


^ permalink raw reply	[relevance 6%]

* IPv6 + UDP  alternative to Gnat.Sockets ?
@ 2016-09-16 20:58 11% Daniel Norte Moraes
  2016-09-17 14:12  6% ` Per Sandberg
                   ` (5 more replies)
  0 siblings, 6 replies; 200+ results
From: Daniel Norte Moraes @ 2016-09-16 20:58 UTC (permalink / raw)


   Hi!

   Are There alternatives to gnat.sockets ( with ipv6 and udp ) ?

   Thanks in Advance!

   []'s Dani.

^ permalink raw reply	[relevance 11%]

* Re: is type String from Ada Binary-Safe ?
    2016-09-14 13:12  5% ` Dmitry A. Kazakov
@ 2016-09-15 13:21  5% ` Daniel Norte Moraes
  1 sibling, 0 replies; 200+ results
From: Daniel Norte Moraes @ 2016-09-15 13:21 UTC (permalink / raw)


quarta-feira, 14 de Setembro de 2016 às 09:51:53 UTC-3, Daniel Norte Moraes escreveu:
> Hi, All!
> 
> Type String from Ada is Binary-Safe ?
> 
> I want use it with a 'recfrom()' from C with udp . 
> 
> Thanks in Advance,
> 
> []'s Dani.

Very Very Thanks Dmitry, Jeffrey and AdaMagica

I'll try with char_array and chars_ptr mas before this I'll will look at Gnat.Sockets.

Thanks A Lot!!

[]'s Dani.


^ permalink raw reply	[relevance 5%]

* Re: is type String from Ada Binary-Safe ?
  @ 2016-09-14 13:12  5% ` Dmitry A. Kazakov
  2016-09-15 13:21  5% ` Daniel Norte Moraes
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2016-09-14 13:12 UTC (permalink / raw)


On 14/09/2016 14:51, Daniel Norte Moraes wrote:

> Type String from Ada is Binary-Safe ?
>
> I want use it with a 'recfrom()' from C with udp .

1. No array with dynamic bounds is. You need a flat array without 
bounds, e.g. a string subtype or object.

2. Whether Character'Size = 8, AFAIK there is no requirement for that in 
Ada.

3. Whether String is packed is not mandated either.

For recfrom the safe choice is to use flat char_array or chars_ptr, see 
the package Interfaces.C.

BTW, Why don't you use GNAT.Sockets?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task?
  2016-09-01 15:43  3% Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task? Some Dude
  2016-09-01 16:05  4% ` J-P. Rosen
@ 2016-09-01 16:10  0% ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2016-09-01 16:10 UTC (permalink / raw)


On 2016-09-01 17:43, Some Dude wrote:
> I have a task with entries Start, Stop, Send, Close and an else
> clause  that does some main processing when none of the entries are processed.
> So the structure is (very simplified):
>
> task body Connection_Handler is
>       Done : Boolean := False;
>    begin
>       accept Start (Socket : Socket_Type) do
>         -- do this first
>       end Start;
>       loop
>          select when not Done =>
>             accept Stop do
>                Done := True;
>             end Stop;
>          or when not Done =>
>             accept Send (Socket : Socket_Type; Command : Command_Type) do
>                -- do something
>             end Send;
>          or when not Done =>
>             accept Close (Socket : Socket_Type) do
>                -- do something
>                end Close;
>          else
>             if not Done then
>                -- receive data if necessary using GNAT.sockets.Check_Selector
>                -- while no data is sent
>             end if;
>          end select;
>          exit when Done;
>       end loop;
>    end Connection_Handler;
>
> However, when Stop is called and Done set to True, I get
>
>   raised TASKING_ERROR : s-tasren.adb:445

Because the task is terminated Done = True, obviously.

The design is flawed. You cannot accept anything when sitting in 
Check_Selector.

An alternative design is (very simplified):

    loop
       -- fill socket sets, checking selector ruins them
       Check_Selector (...); -- with some reasonable timeout
       case Status is
          when Completed =>
             -- Service read/write sockets
          when Aborted | Timeout =>
             -- service task messages queue
          ...
       end case;
    end loop;

No rendezvous, you push a message into a queue and then abort selector 
which falls into Status Aborted which gives the task an opportunity to 
inspect the queue.

Then you need not Send entry/message. Sending is driven by write socket 
events. So when the socket is ready to be written Status = Completed and 
the socket is in the write set, you send another portion of data from 
the output ring buffer. Note that you need the buffer in any case 
because you don't know how much the socket is ready to accept.

You don't interrupt the task for writing the buffer. It can be done 
asynchronously.

P.S. You can find an example of working design in Simple Components:

http://www.dmitry-kazakov.de/ada/components.htm#multiple_GNAT.Sockets.Servers

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Re: Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task?
  2016-09-01 15:43  3% Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task? Some Dude
@ 2016-09-01 16:05  4% ` J-P. Rosen
  2016-09-01 16:10  0% ` Dmitry A. Kazakov
  1 sibling, 0 replies; 200+ results
From: J-P. Rosen @ 2016-09-01 16:05 UTC (permalink / raw)


Le 01/09/2016 à 17:43, Some Dude a écrit :

Small remark: you can get rid of "Done":

task body Connection_Handler is
begin
      accept Start (Socket : Socket_Type) do
        -- do this first
      end Start;
      loop
         select
            accept Stop;
            exit;
         or
            accept Send (Socket : Socket_Type; Command : Command_Type) do
               -- do something
            end Send;
         or
            accept Close (Socket : Socket_Type) do
               -- do something
             end Close;
         else
             -- receive data if necessary using GNAT.sockets.Check_Selector
             -- while no data is sent
         end select;
      end loop;
end Connection_Handler;

> However, when Stop is called and Done set to True, I get 
> 
>   raised TASKING_ERROR : s-tasren.adb:445
Presumably, this is due to some other task trying to rendezvous with
Connection_Handler after it has completed.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[relevance 4%]

* Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task?
@ 2016-09-01 15:43  3% Some Dude
  2016-09-01 16:05  4% ` J-P. Rosen
  2016-09-01 16:10  0% ` Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Some Dude @ 2016-09-01 15:43 UTC (permalink / raw)


I have a task with entries Start, Stop, Send, Close and an else clause that does some main processing when none of the entries are processed. So the structure is (very simplified):

task body Connection_Handler is
      Done : Boolean := False;
   begin
      accept Start (Socket : Socket_Type) do
        -- do this first 
      end Start;
      loop
         select when not Done =>
            accept Stop do
               Done := True;
            end Stop;
         or when not Done =>
            accept Send (Socket : Socket_Type; Command : Command_Type) do
               -- do something
            end Send;
         or when not Done =>
            accept Close (Socket : Socket_Type) do
               -- do something
               end Close;
         else
            if not Done then
               -- receive data if necessary using GNAT.sockets.Check_Selector
               -- while no data is sent
            end if;
         end select;
         exit when Done;
      end loop;
   end Connection_Handler;

However, when Stop is called and Done set to True, I get 

  raised TASKING_ERROR : s-tasren.adb:445

as an exception in my AUnit test harness and the test ends prematurely with an error code. This occurs in the main program task, or at least if I add a catch-all exception handler in the above task body, it is *not* triggered there.

I thought this occurs perhaps because there is no terminate alternative, but if I add:
 
   or terminate;

before the else part, I get the error message "else part not allowed with other alternatives". So this is not possible.

Is there a way to stop the task gracefully (without abort) but also do some continuous processing like in the else part? Does anybody have an idea what might cause this error?


^ permalink raw reply	[relevance 3%]

* Re: A few questions on parsing, sockets, UTF-8 strings
  2016-08-11 14:39  4% A few questions on parsing, sockets, UTF-8 strings john
@ 2016-08-11 16:23  0% ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2016-08-11 16:23 UTC (permalink / raw)


On 2016-08-11 16:39, john@peppermind.com wrote:
> Hi! For some non-standard interprocess communication, I need to:
>
> 1. Listen with a TCP socket to the local loopback interface and
> obtain  the PORT suggested by the OS, i.e. like with bind() to port 0 and
> getsockname() in C. Is this possible with GNAT.sockets?

Why not?

> 2. Connect to the incoming host and parse input and send output
> delimited by LF line-by-line. What about buffering, can it be switched
> off or is there a line buffer mode already? (It needs to be compatible
> with LF instead of CR+LF as delimiter, though.)

The user input buffer is the buffer you provide. TCP/IP stream ignores 
whatever line terminators. They are just bytes as anything else. You 
read until a complete line is in the buffer then do whatever you have to 
with the line.

> 3. Convert back and forth between Base64-encoded UTF-8 strings and
> UTF-8 strings (which may also be represented in the source text). How do
> I do this?
>
> Especially the last point is a bit mysterious to me. I cannot use
> UCS-2, it needs to be full UTF-8. Should I use a library for UTF-8
> strings? Which one?

I have one:

http://dmitry-kazakov.de/ada/strings_edit.htm#12

There must be others surely.

P.S. There is no point using Base64 encoding over TCP/IP unless a 
specific protocol requires it.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* A few questions on parsing, sockets, UTF-8 strings
@ 2016-08-11 14:39  4% john
  2016-08-11 16:23  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: john @ 2016-08-11 14:39 UTC (permalink / raw)


Hi! For some non-standard interprocess communication, I need to:

1. Listen with a TCP socket to the local loopback interface and obtain the PORT suggested by the OS, i.e. like with bind() to port 0 and getsockname() in C. Is this possible with GNAT.sockets?

2. Connect to the incoming host and parse input and send output delimited by LF line-by-line. What about buffering, can it be switched off or is there a line buffer mode already? (It needs to be compatible with LF instead of CR+LF as delimiter, though.) 

3. Convert back and forth between Base64-encoded UTF-8 strings and UTF-8 strings (which may also be represented in the source text). How do I do this?

Especially the last point is a bit mysterious to me. I cannot use UCS-2, it needs to be full UTF-8. Should I use a library for UTF-8 strings? Which one? 

Speed is not very important, but I'd like to avoid unnecessary conversions.


^ permalink raw reply	[relevance 4%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-28  5:59  4%                           ` Jeffrey R. Carter
@ 2016-05-09 22:32  5%                             ` David Thompson
  0 siblings, 0 replies; 200+ results
From: David Thompson @ 2016-05-09 22:32 UTC (permalink / raw)


On Wed, 27 Apr 2016 22:59:01 -0700, "Jeffrey R. Carter"
<spam.jrcarter.not@spam.not.acm.org> wrote:

> On 04/27/2016 10:18 PM, J-P. Rosen wrote:
> >
> > loop
> >    loop
> >       {some code}
> >       if Found then
> >          goto Contine;
> >       end if;
> >       {some code}
> >     end loop;
> >     {some code}
> > <<Continue>>
> > end loop;
> 
> People ask for features like a continue statement because they're used to it in 
> some other language. I'm not aware of any language that has such a statement 
> that exits an inner loop and skips to the end of an outer loop. <snip>

Fortran >= 90.

PL/I at least IBM dialect since IDK when; I don't recall it there in
the '70s when I used OS/360, but it is in a recent z/OS manual.

perl -- if you accept perl as a programming language; personally I say
it is but not a very good one and certainly not an example to follow.

And I think LISP has it, but LISP has almost everything good AND bad.

^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-28 20:23  4%                         ` Randy Brukardt
@ 2016-04-28 21:47  5%                           ` Jeffrey R. Carter
  0 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2016-04-28 21:47 UTC (permalink / raw)


On 04/28/2016 01:23 PM, Randy Brukardt wrote:
>
> A typical case would be a lexer for numeric literals, where one wants to
> discard the underscores and keep the other characters. That would look
> something like:
>
>     while not End_of_File loop
>          case Next_Char is
>                when '0'..'9' =>
>                      null;
>                when '+' | '-' =>
>                      {some code}
>                when 'E' | 'e' =>
>                      {some code}
>                when '_' =>
>                      if Last_Char = '_' then
>                            Error (...);
>                      else
>                            goto Continue; -- Skip further processing.
>                      end if;
>               when others =>
>                      exit; -- We've reached the end of the number.
>          end case;
>          {Store the Next_Char into the literal token}
>       <<Continue>>
>     end loop;
>
> To avoid the goto/continue, you'd have to introduce a Boolean, or duplicate
> the "Store" code, or make the "Store" code into a subprogram, and make
> duplicate calls on that. None of which is clearer, or faster, than the above
> code. (Faster matters here as this loop is the third most used of the inner
> lexer loops, behind comments and identifiers. And a lexer is one of the top
> CPU users in a typical compiler.)

Or do

               when '_' =>
                  if Last_Char = '_' then
                     Error (...);
                  end if;
               when others =>
                  exit; -- We've reached the end of the number.
          end case;
          if Next_Char /= '_' then
             {Store Next_Char into the literal token}
          end if;
     end loop;

which is still clearer than the goto.

Maybe you have some more complex, more deeply nested, real-world example where 
this kind of alternative isn't possible. I've never encountered one.

-- 
Jeff Carter
"[T]he Musgroves had had the ill fortune
of a very troublesome, hopeless son, and
the good fortune to lose him before he
reached his twentieth year ..."
Persuasion
154

^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-27 23:43  5%                       ` Jeffrey R. Carter
  2016-04-28  5:18  6%                         ` J-P. Rosen
@ 2016-04-28 20:23  4%                         ` Randy Brukardt
  2016-04-28 21:47  5%                           ` Jeffrey R. Carter
  1 sibling, 1 reply; 200+ results
From: Randy Brukardt @ 2016-04-28 20:23 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org> wrote in message 
news:nfrijv$k74$1@dont-email.me...
> On 04/27/2016 03:16 PM, Randy Brukardt wrote:
>>
>>      loop
>>           {some code}
>>           if something then
>>               goto Continue;
>>           end if;
>>           {more code}
>>      <<Continue>> -- Ada 95 requires "null;" here, Ada 2012 does not.
>>      end loop;
>>
>> To completely eliminate the goto, one has to use a Boolean variable 
>> instead,
>> or duplicate parts of the loop; both of those obscure what is going on 
>> more
>> than the goto.
>
> This claim is completely untrue.
[Followed by a bunch of true, but irrelevant discussion.]

It's completely true, because, of course, the if is likely to be deeply 
nested inside of other if and case statements. I should probably have said 
that, but it is so plainly obvious I didn't think anyone would be so silly 
as to ignore and beat up on a straw man. But of course this is the Internet, 
where even usually reasonable people enjoy beating straw men...

A typical case would be a lexer for numeric literals, where one wants to 
discard the underscores and keep the other characters. That would look 
something like:

    while not End_of_File loop
         case Next_Char is
               when '0'..'9' =>
                     null;
               when '+' | '-' =>
                     {some code}
               when 'E' | 'e' =>
                     {some code}
               when '_' =>
                     if Last_Char = '_' then
                           Error (...);
                     else
                           goto Continue; -- Skip further processing.
                     end if;
              when others =>
                     exit; -- We've reached the end of the number.
         end case;
         {Store the Next_Char into the literal token}
      <<Continue>>
    end loop;

To avoid the goto/continue, you'd have to introduce a Boolean, or duplicate 
the "Store" code, or make the "Store" code into a subprogram, and make 
duplicate calls on that. None of which is clearer, or faster, than the above 
code. (Faster matters here as this loop is the third most used of the inner 
lexer loops, behind comments and identifiers. And a lexer is one of the top 
CPU users in a typical compiler.)

                                                     Randy.




^ permalink raw reply	[relevance 4%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-28  5:18  6%                         ` J-P. Rosen
@ 2016-04-28  5:59  4%                           ` Jeffrey R. Carter
  2016-05-09 22:32  5%                             ` David Thompson
  0 siblings, 1 reply; 200+ results
From: Jeffrey R. Carter @ 2016-04-28  5:59 UTC (permalink / raw)


On 04/27/2016 10:18 PM, J-P. Rosen wrote:
>
> loop
>    loop
>       {some code}
>       if Found then
>          goto Contine;
>       end if;
>       {some code}
>     end loop;
>     {some code}
> <<Continue>>
> end loop;

People ask for features like a continue statement because they're used to it in 
some other language. I'm not aware of any language that has such a statement 
that exits an inner loop and skips to the end of an outer loop. So I think this 
is a contrived example to try to justify such a statement given that the actual 
uses of the statement in other languages don't justify it. (I hope that makes 
sense.)

Anyway, this can be written as

Outer : loop
    Inner : loop
       {code 1}
       exit Inner when Found;
       {code 2}
    end loop Inner;
    if not Found then
       {code 3}
    end if;
end loop Outer;

I think that is clearer than the goto, and no doubt any efficiency difference 
due to the double evaluation of the condition will be too small to measure. More 
complex cases become

Outer : loop
    Middle : loop
       Inner : loop
          {code 1}
          exit Middle when Found;
          {code 2}
       end loop Inner;
       {code 3}
    end loop Middle;
    if not Found then
       {code 4}
    end if;
end loop Outer;

(I think every loop should have a good name that describes why the loop exists. 
Outer, Middle, and Inner are not such names.)

-- 
Jeff Carter
"We'll make Rock Ridge think it's a chicken
that got caught in a tractor's nuts!"
Blazing Saddles
87


^ permalink raw reply	[relevance 4%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-27 23:43  5%                       ` Jeffrey R. Carter
@ 2016-04-28  5:18  6%                         ` J-P. Rosen
  2016-04-28  5:59  4%                           ` Jeffrey R. Carter
  2016-04-28 20:23  4%                         ` Randy Brukardt
  1 sibling, 1 reply; 200+ results
From: J-P. Rosen @ 2016-04-28  5:18 UTC (permalink / raw)


Le 28/04/2016 à 01:43, Jeffrey R. Carter a écrit :
> This claim is completely untrue. The example loop is equivalent to
> 
> loop
>    {some code}
>    if not something then
>       {more code}
>    end if;
> end loop;

In simple cases, yes. But what if the "continue" is nested?

loop
   loop
      {some code}
      if Found then
         goto Contine;
      end if;
      {some code}
    end loop;
    {some code}
<<Continue>>
end loop;

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-27 22:16  5%                     ` Randy Brukardt
  2016-04-27 23:43  5%                       ` Jeffrey R. Carter
@ 2016-04-28  5:13  6%                       ` J-P. Rosen
  1 sibling, 0 replies; 200+ results
From: J-P. Rosen @ 2016-04-28  5:13 UTC (permalink / raw)


Le 28/04/2016 à 00:16, Randy Brukardt a écrit :
> Moral: all gotos aren't bad. Coding standards that reject them out of hand 
> are just like coding standards that reject exception handling or 
> finalization out of hand -- deeply flawed.
Right, but remember:

when a coding standard says "X is forbidden", it really means "X shall
not be used, unless proper justification is given and approved by QA".

Or so should the coding standard say...

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr


^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-27 22:16  5%                     ` Randy Brukardt
@ 2016-04-27 23:43  5%                       ` Jeffrey R. Carter
  2016-04-28  5:18  6%                         ` J-P. Rosen
  2016-04-28 20:23  4%                         ` Randy Brukardt
  2016-04-28  5:13  6%                       ` J-P. Rosen
  1 sibling, 2 replies; 200+ results
From: Jeffrey R. Carter @ 2016-04-27 23:43 UTC (permalink / raw)


On 04/27/2016 03:16 PM, Randy Brukardt wrote:
>
>      loop
>           {some code}
>           if something then
>               goto Continue;
>           end if;
>           {more code}
>      <<Continue>> -- Ada 95 requires "null;" here, Ada 2012 does not.
>      end loop;
>
> To completely eliminate the goto, one has to use a Boolean variable instead,
> or duplicate parts of the loop; both of those obscure what is going on more
> than the goto.

This claim is completely untrue. The example loop is equivalent to

loop
    {some code}
    if not something then
       {more code}
    end if;
end loop;

No Boolean variable (not already present), no duplication of parts of the loop, 
and less obscuration that the goto, which could go almost anywhere, while the if 
must terminate within the loop. It's easier to find the end of the if than it is 
to find the target of the goto. A conditional continue statement is always 
equivalent to such an if.

-- 
Jeff Carter
"We'll make Rock Ridge think it's a chicken
that got caught in a tractor's nuts!"
Blazing Saddles
87

^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-26 19:43  5%                   ` ahlan.marriott
  2016-04-26 20:24  6%                     ` Simon Wright
  2016-04-26 22:32  6%                     ` Jeffrey R. Carter
@ 2016-04-27 22:16  5%                     ` Randy Brukardt
  2016-04-27 23:43  5%                       ` Jeffrey R. Carter
  2016-04-28  5:13  6%                       ` J-P. Rosen
  2 siblings, 2 replies; 200+ results
From: Randy Brukardt @ 2016-04-27 22:16 UTC (permalink / raw)


<ahlan.marriott@gmail.com> wrote in message 
news:cf442cc4-8123-4815-8b49-ce1411ff4ed0@googlegroups.com...
...
> In the late seventies we were taught that gotos were evil and never
> to be used yet here they are, three and a half decades later, still using
> them - what a disgrace - have people no shame? ;-)

I hope the smiley face applies to the entire rant about Gotos.

When we discussed whether Ada should have a loop continue statement, the 
conclusion was that goto is good enough for such cases. They aren't common 
enough to justify adding a new kind of statement, especially one that can 
get lost (some people dislike deeply nested return statements, and 
"continue" would be worse). We even changed the syntax slightly to make it 
legal for a label to be the last thing in a sequence of statements.

That is:

     loop
          {some code}
          if something then
              goto Continue;
          end if;
          {more code}
     <<Continue>> -- Ada 95 requires "null;" here, Ada 2012 does not.
     end loop;

See AI05-0179-1 for details.

To completely eliminate the goto, one has to use a Boolean variable instead, 
or duplicate parts of the loop; both of those obscure what is going on more 
than the goto.

Moral: all gotos aren't bad. Coding standards that reject them out of hand 
are just like coding standards that reject exception handling or 
finalization out of hand -- deeply flawed.

                                      Randy.



^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-27  8:27  5%                   ` Dmitry A. Kazakov
@ 2016-04-27  9:59  6%                     ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2016-04-27  9:59 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> It is still deeply confusing to me. Does it mean that Interfaces must
> be the list of all source file from all projects?
>
> The case is:
>
> with "A.gpr";
> with "B.gpr";
> ...
> with "Z.gpr";
>
> library project Foo is
>    for Source_Files use (); -- No own sources, to stress the point
>    for Library_Kind use "static";
>    for Library_Standalone use "encapsulated"; -- ??
>    for Library_Auto_Init use "true"; -- ??
>    for Library_Interface use (<things-to-be-visible-are-outside>);
>    for Interface use (<what?>);
> end Foo;

I'm sorry, I really don't understand this either.

Tool documentation really needs to have use cases and the solutions that
the tool offers.

Or perhaps "It looks as though you're trying to build a standalone
library ..." :-)

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-26 21:23  4%                 ` Simon Wright
  2016-04-27  6:53  6%                   ` Simon Wright
@ 2016-04-27  8:27  5%                   ` Dmitry A. Kazakov
  2016-04-27  9:59  6%                     ` Simon Wright
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-27  8:27 UTC (permalink / raw)


On 26/04/2016 23:23, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> On 2016-04-23 23:16, Simon Wright wrote:
>>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>>
>>>> Can [gprlib] build a static equivalent too? I.e. a static library
>>>> containing a closure of all referenced objects plus initialization
>>>> code.
>>>
>>> I'm not sure it's relevant, but I posted a bug[1] on gnatmake &
>>> static standalone libraries; I sent AdaCore a similar report on
>>> gprbuild, no reply.
>>>
>>> The problem was, for a static SAL, the using Ada main program needs
>>> to see all the ALIs for it to be sure to call in all the dylibs
>>> required by the library; so if e.g. libgnarl was only called by
>>> non-interface units it would get linked but not elaborated.
>>>
>>> I wanted to use SALs because they automatically populate the include
>>> directory with relevant source.
>>
>> How do you build a static stand-alone library? In my case gprbuild
>> wants it dynamic.
>
> I see what you mean, I've been calling it the wrong thing all these
> years.
>
> If you provide a Library_Interface and you're building a dynamic
> library, gprbuild populates the include Library_Src_Dir directory with
> the library interface units and builds a dynamic library with
> auto-initialization.
>
> If you provide a Library_Interface and you're building a static library,
> gprbuild uses the same rule to populate the include directory; but this
> mey be wrong if the non-visible units require elaboration (e.g. they
> call in the tasking runtime).
>
> The patch I provided meant that if you provided a Library_Interface for
> a static library, the include directory would be populated with all the
> units regardless of whether they were actually listed; I now see that
> using Interfaces and naming all the source files achieves the same
> effect! so no need for a patch (but maybe a blog posting?)
>
> For the BCs this would mean
>
>    case Library_Type is
>       when "relocatable" =>
>          for Library_Src_Dir use "./include";
>          for Library_Interface use Source_Units;
>       when "static" =>
>          for Library_Src_Dir use "./include";
>          for Interfaces use Sources;
>    end case;
>
> where I already have
>
>    Source_Units :=
>      (
>       "BC.Containers.Bags.Bounded",
>       "BC.Containers.Bags.Dynamic",
>       ...
>
> and
>
>    Sources :=
>      (
>       "bc-containers-bags-bounded.adb",
>       "bc-containers-bags-bounded.ads",
>       "bc-containers-bags-dynamic.adb",
>       "bc-containers-bags-dynamic.ads",
>       ...

It is still deeply confusing to me. Does it mean that Interfaces must be 
the list of all source file from all projects?

The case is:

with "A.gpr";
with "B.gpr";
...
with "Z.gpr";

library project Foo is
    for Source_Files use (); -- No own sources, to stress the point
    for Library_Kind use "static";
    for Library_Standalone use "encapsulated"; -- ??
    for Library_Auto_Init use "true"; -- ??
    for Library_Interface use (<things-to-be-visible-are-outside>);
    for Interface use (<what?>);
end Foo;

> I don't really like the idea of using Library_Interface (what units
> should be visible) to indicate that auto-initialization is required;
> especially because there are already Library_Standalone and
> Library_Auto_Init. Perhaps they weren't available at the time.
>
>> Another question is regarding the library interface. gprbuild rejects
>> interface units from other projects. But usually the library is just a
>> combination of many projects some of which providing interface units.
>
> You would only need to know about the interface units of other libraries
> if you were going to call them yourself directly.

But there is no other libraries after libFoo.a is built. The whole 
purpose of the exercise to have libFoo a closure containing all static 
libraries it depends on and GNAT RTL too.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-27  6:53  6%                   ` Simon Wright
@ 2016-04-27  7:25  5%                     ` ahlan
  0 siblings, 0 replies; 200+ results
From: ahlan @ 2016-04-27  7:25 UTC (permalink / raw)


On Wednesday, April 27, 2016 at 8:53:17 AM UTC+2, Simon Wright wrote:
> Simon Wright <simon@pushface.org> writes:
> 
> >    case Library_Type is
> >       when "relocatable" =>
> >          for Library_Src_Dir use "./include";
> >          for Library_Interface use Source_Units;
> >       when "static" =>
> >          for Library_Src_Dir use "./include";
> >          for Interfaces use Sources;
> >    end case;
> 
> Actually, the Library_Src_Dir won't normally have the same content in
> the two cases, so they should be different (./include-relocatable,
> ./include-static for example).
> 
> Or
> 
>    for Library_Src_Dir use "./include-" & Library_Type;
>    case Library_Type is
>       when "relocatable" =>
>          for Library_Interface use Source_Units;
>       when "static" =>
>          for Interfaces use Sources;
>    end case;

I have one last question concerning the build of gprlib.
When I use gprbuild to build applications that do not require a console I add "-mwindows" to the default_switches in package Linker within the gpr file.
However when I do this for Gprlib and then replace the AdaCore Gprlib with my version subsequent use of Gprbuild results in three console windows being momentarily displayed.
However if I omit the "-mwindows" then all is well and these consoles do not appear.
What confuses my small brain is that this is the opposite of what I expected.
Normally if I don't specify -mwindows I get a console application.
Does anyone have an explanation of why gprlib appears special in this regard?
What am I misunderstanding?

Confused,
Ahlan


^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-26 21:23  4%                 ` Simon Wright
@ 2016-04-27  6:53  6%                   ` Simon Wright
  2016-04-27  7:25  5%                     ` ahlan
  2016-04-27  8:27  5%                   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: Simon Wright @ 2016-04-27  6:53 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

>    case Library_Type is
>       when "relocatable" =>
>          for Library_Src_Dir use "./include";
>          for Library_Interface use Source_Units;
>       when "static" =>
>          for Library_Src_Dir use "./include";
>          for Interfaces use Sources;
>    end case;

Actually, the Library_Src_Dir won't normally have the same content in
the two cases, so they should be different (./include-relocatable,
./include-static for example).

Or

   for Library_Src_Dir use "./include-" & Library_Type;
   case Library_Type is
      when "relocatable" =>
         for Library_Interface use Source_Units;
      when "static" =>
         for Interfaces use Sources;
   end case;


^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-26 19:43  5%                   ` ahlan.marriott
  2016-04-26 20:24  6%                     ` Simon Wright
@ 2016-04-26 22:32  6%                     ` Jeffrey R. Carter
  2016-04-27 22:16  5%                     ` Randy Brukardt
  2 siblings, 0 replies; 200+ results
From: Jeffrey R. Carter @ 2016-04-26 22:32 UTC (permalink / raw)


On 04/26/2016 12:43 PM, ahlan.marriott@gmail.com wrote:
>
> At the same time you might like to suggest that they remove the gotos from the code!
> These caused me lots of problems because our IDE prohibits gotos.
> Who in their right mind uses gotos?
> In the late seventies we were taught that gotos were evil and never to be used yet here they are, three and a half decades later, still using them - what a disgrace - have people no shame? ;-)

Goto is sometimes a good idea; for example, when translating STDs, using goto 
for the transitions is often advocated to encode the state in the program counter.

In most other cases, though, goto is usually not needed and less clear than the 
alternatives.

-- 
Jeff Carter
"Of course, one couldn't think properly in Paris--
it was so uncomfortable and the houses were
central heated."
Clouds of Witness
153

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-26 20:20  6%               ` Dmitry A. Kazakov
@ 2016-04-26 21:23  4%                 ` Simon Wright
  2016-04-27  6:53  6%                   ` Simon Wright
  2016-04-27  8:27  5%                   ` Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Simon Wright @ 2016-04-26 21:23 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> On 2016-04-23 23:16, Simon Wright wrote:
>> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>>
>>> Can [gprlib] build a static equivalent too? I.e. a static library
>>> containing a closure of all referenced objects plus initialization
>>> code.
>>
>> I'm not sure it's relevant, but I posted a bug[1] on gnatmake &
>> static standalone libraries; I sent AdaCore a similar report on
>> gprbuild, no reply.
>>
>> The problem was, for a static SAL, the using Ada main program needs
>> to see all the ALIs for it to be sure to call in all the dylibs
>> required by the library; so if e.g. libgnarl was only called by
>> non-interface units it would get linked but not elaborated.
>>
>> I wanted to use SALs because they automatically populate the include
>> directory with relevant source.
>
> How do you build a static stand-alone library? In my case gprbuild
> wants it dynamic.

I see what you mean, I've been calling it the wrong thing all these
years.

If you provide a Library_Interface and you're building a dynamic
library, gprbuild populates the include Library_Src_Dir directory with
the library interface units and builds a dynamic library with
auto-initialization.

If you provide a Library_Interface and you're building a static library,
gprbuild uses the same rule to populate the include directory; but this
mey be wrong if the non-visible units require elaboration (e.g. they
call in the tasking runtime).

The patch I provided meant that if you provided a Library_Interface for
a static library, the include directory would be populated with all the
units regardless of whether they were actually listed; I now see that
using Interfaces and naming all the source files achieves the same
effect! so no need for a patch (but maybe a blog posting?)

For the BCs this would mean

   case Library_Type is
      when "relocatable" =>
         for Library_Src_Dir use "./include";
         for Library_Interface use Source_Units;
      when "static" =>
         for Library_Src_Dir use "./include";
         for Interfaces use Sources;
   end case;

where I already have

   Source_Units :=
     (
      "BC.Containers.Bags.Bounded",
      "BC.Containers.Bags.Dynamic",
      ...

and

   Sources :=
     (
      "bc-containers-bags-bounded.adb",
      "bc-containers-bags-bounded.ads",
      "bc-containers-bags-dynamic.adb",
      "bc-containers-bags-dynamic.ads",
      ...

I don't really like the idea of using Library_Interface (what units
should be visible) to indicate that auto-initialization is required;
especially because there are already Library_Standalone and
Library_Auto_Init. Perhaps they weren't available at the time.

> Another question is regarding the library interface. gprbuild rejects
> interface units from other projects. But usually the library is just a
> combination of many projects some of which providing interface units.

You would only need to know about the interface units of other libraries
if you were going to call them yourself directly.

^ permalink raw reply	[relevance 4%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-26 19:43  5%                   ` ahlan.marriott
@ 2016-04-26 20:24  6%                     ` Simon Wright
  2016-04-26 22:32  6%                     ` Jeffrey R. Carter
  2016-04-27 22:16  5%                     ` Randy Brukardt
  2 siblings, 0 replies; 200+ results
From: Simon Wright @ 2016-04-26 20:24 UTC (permalink / raw)


ahlan.marriott@gmail.com writes:

> On Sunday, 24 April 2016 10:31:12 UTC+2, Simon Wright  wrote:
>> ahlan@marriott.org writes:
>> 
>> > On Saturday, April 23, 2016 at 11:16:53 PM UTC+2, Simon Wright wrote:
>> 
>> >> I'm not sure it's relevant, but I posted a bug[1] on gnatmake & static
>> >> standalone libraries; I sent AdaCore a similar report on gprbuild, no
>> >> reply.
>> 
>> > Unfortunately your bug fix isn't included in the sources maintained by
>> > AdaCore at GitHub.
>> > So thank you for the improvement :-)
>> 
>> I guess I should post an issue there, then! Thanks for the nudge.
>
> At the same time you might like to suggest that they remove the gotos
> from the code!

I could only see one (in gprbuild-link.adb). I'd be a lot more worried
about the general complexity of that code than one poor little goto.

You could raise your own issue.

> These caused me lots of problems because our IDE prohibits gotos.
> Who in their right mind uses gotos?

Who in their right mind prohibits code structures that are sometimes,
albeit rarely, the Right Way to do the job? (though I can't actually
remember the last time I used a goto).


^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-23 21:16  5%             ` Simon Wright
  2016-04-24  8:13  6%               ` ahlan
@ 2016-04-26 20:20  6%               ` Dmitry A. Kazakov
  2016-04-26 21:23  4%                 ` Simon Wright
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-26 20:20 UTC (permalink / raw)


On 2016-04-23 23:16, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>
>> Can [gprlib] build a static equivalent too? I.e. a static library
>> containing a closure of all referenced objects plus initialization
>> code.
>
> I'm not sure it's relevant, but I posted a bug[1] on gnatmake & static
> standalone libraries; I sent AdaCore a similar report on gprbuild, no
> reply.
>
> The problem was, for a static SAL, the using Ada main program needs to
> see all the ALIs for it to be sure to call in all the dylibs required by
> the library; so if e.g. libgnarl was only called by  non-interface units
> it would get linked but not elaborated.
>
> I wanted to use SALs because they automatically populate the include
> directory with relevant source.

How do you build a static stand-alone library? In my case gprbuild wants 
it dynamic.

Another question is regarding the library interface. gprbuild rejects 
interface units from other projects. But usually the library is just a 
combination of many projects some of which providing interface units.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-24  8:31  6%                 ` Simon Wright
@ 2016-04-26 19:43  5%                   ` ahlan.marriott
  2016-04-26 20:24  6%                     ` Simon Wright
                                       ` (2 more replies)
  0 siblings, 3 replies; 200+ results
From: ahlan.marriott @ 2016-04-26 19:43 UTC (permalink / raw)


On Sunday, 24 April 2016 10:31:12 UTC+2, Simon Wright  wrote:
> ahlan@marriott.org writes:
> 
> > On Saturday, April 23, 2016 at 11:16:53 PM UTC+2, Simon Wright wrote:
> 
> >> I'm not sure it's relevant, but I posted a bug[1] on gnatmake & static
> >> standalone libraries; I sent AdaCore a similar report on gprbuild, no
> >> reply.
> 
> > Unfortunately your bug fix isn't included in the sources maintained by
> > AdaCore at GitHub.
> > So thank you for the improvement :-)
> 
> I guess I should post an issue there, then! Thanks for the nudge.

At the same time you might like to suggest that they remove the gotos from the code!
These caused me lots of problems because our IDE prohibits gotos.
Who in their right mind uses gotos?
In the late seventies we were taught that gotos were evil and never to be used yet here they are, three and a half decades later, still using them - what a disgrace - have people no shame? ;-)

MfG
Ahlan


^ permalink raw reply	[relevance 5%]

* Re: Broadcasting UDP
  2016-04-24 17:22  0% ` Dmitry A. Kazakov
@ 2016-04-25 14:18  0%   ` ahlan
  0 siblings, 0 replies; 200+ results
From: ahlan @ 2016-04-25 14:18 UTC (permalink / raw)


On Sunday, April 24, 2016 at 7:22:45 PM UTC+2, Dmitry A. Kazakov wrote:
> On 2016-04-24 18:31, ahlan.marriott@gmail.com wrote:
> > I asked this question sometime ago but I can no longer find the post.
> > In any case it was never really resolved so let me try again.
> > I am looking for a platform independent Ada solution on how to broadcast a UDP packet.
> > I would be satisfied with a GNAT only solution, i.e. one that uses Gnat.Sockets and/or Gnat specific libraries.
> > Attempting to broadcast to the limited broadcast address 255.255.255.255 has no effect (under Windows at least)
> > To successfully broadcast one needs to use the subnet directed broadcast address.
> > As I want to support PCs that have multiple ethernet adapters this
> > means that I must iterate over the ethernet adapters, discover my
> > ethernet address and subnet for each adapter, calculate the broadcast
> > address and then send the UDP packet to that address.
> > So far so good.
> > My problem is that I don't know how to iterate over my adapters and
> > obtain the address and subnet mask for each adapter using just Ada.
> > Can anyone tell me how I can do this using Ada?
> 
> declare
>     Host    : Host_Entry_Type := Get_Host_By_Name (Host_Name);
>     Address : aliased Sock_Addr_Type;
> begin
>     for Index in 1..Addresses_Length (Host) loop
>        Address.Addr := Addresses (Host, Index)));
>        Address.Port := <port>;
>        declare
>           Socket : Socket_Type := No_Socket;
>           Pier   : Sock_Addr_Type;
>        begin
>           Create_Socket (Socket, Family_Inet, Socket_Datagram);
>           Set_Socket_Option
>           (  Socket,
>              Socket_Level,
>              (Reuse_Address, True)
>           );
>           Set_Socket_Option
>           (  Socket,
>              Socket_Level,
>              (Broadcast, True)
>           );
>           Set_Socket_Option
>           (  Socket,
>              Socket_Level,
>              (Receive_Timeout, <timeout>)
>           );
>           Bind_Socket (Socket, Address);
>           Address.Addr := Broadcast_Inet_Addr;
>           Send_Socket (Socket, <request-packet>, Last, Address'Access);
>           loop -- Collecting responses, time-limited <timeout>
>              ...
>              Receive_Socket (Socket, <response-packet>, Last, Pier);
>              ...
>           end loop;
>           Close_Socket (Socket);
>        end;
>     end loop;
> end;
> 
> > In which case I would be grateful if anyone could tell me how I can iterate my adapters under Linux
> 
> Under Linux it is through the proc file system, if I correctly remember. 
> I don't have it in the head right now.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Dear Dmitry,

This of course works but by using Broadcast_Inet_Addr (255.255.255.255) then we actually transmit more UDP messages than is strictly necessary.

For example if I have two adapters one with 100.13.5.200 and the other 169.254.7.7 and I send a UDP broadcast on each adapter then four UDP messages are actually transmitted.
1) Src=100.13.5.200 Dest=255.255.255.255 on adapter 1
2) Src=100.13.5.200 Dest=255.255.255.255 on adapter 2
3) Src=169.254.7.7 Dest=255.255.255.255 on adapter 1
4) Src=169.254.7.7 Dest=255.255.255.255 on adapter 2

This is because the destination address 255.255.255.255 is for all adapters.
Whereas if I could somehow find out the subnet mask for the adapter I could refine the destination address to be a subnet directed broadcast address and thereby could prevent the unnecessary traffic.
In my example if the subnet for both adapters was 255.255.0.0 then the broadcast address for adapter 1 would be 100.13.255.255 and for adapter 2 169.254.255.255.

If I use subnet directed broadcast addresses then on my test PCs running Ms-Windows messages are only sent on the adapter if the subnet matches.
Ie only two messages are transmitted, one per adapter.

This is what I was aiming for.
However, although I can find out the host address for each adapter, I haven't been able to find out how I can determine out their subnet masks.

If I could find out the subnet masks I could derive the subnet directed broadcast addresses and use these as the destination addresses and thereby reduce the traffic.

Not by much I grant you but every little helps and besides it would be a little more elegant than using the crude broadcast to all on all adapters approach.

Any ideas?
MfG
Ahlan

^ permalink raw reply	[relevance 0%]

* Re: Broadcasting UDP
  2016-04-24 16:31  4% Broadcasting UDP ahlan.marriott
@ 2016-04-24 17:22  0% ` Dmitry A. Kazakov
  2016-04-25 14:18  0%   ` ahlan
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-24 17:22 UTC (permalink / raw)


On 2016-04-24 18:31, ahlan.marriott@gmail.com wrote:
> I asked this question sometime ago but I can no longer find the post.
> In any case it was never really resolved so let me try again.
> I am looking for a platform independent Ada solution on how to broadcast a UDP packet.
> I would be satisfied with a GNAT only solution, i.e. one that uses Gnat.Sockets and/or Gnat specific libraries.
> Attempting to broadcast to the limited broadcast address 255.255.255.255 has no effect (under Windows at least)
> To successfully broadcast one needs to use the subnet directed broadcast address.
> As I want to support PCs that have multiple ethernet adapters this
> means that I must iterate over the ethernet adapters, discover my
> ethernet address and subnet for each adapter, calculate the broadcast
> address and then send the UDP packet to that address.
> So far so good.
> My problem is that I don't know how to iterate over my adapters and
> obtain the address and subnet mask for each adapter using just Ada.
> Can anyone tell me how I can do this using Ada?

declare
    Host    : Host_Entry_Type := Get_Host_By_Name (Host_Name);
    Address : aliased Sock_Addr_Type;
begin
    for Index in 1..Addresses_Length (Host) loop
       Address.Addr := Addresses (Host, Index)));
       Address.Port := <port>;
       declare
          Socket : Socket_Type := No_Socket;
          Pier   : Sock_Addr_Type;
       begin
          Create_Socket (Socket, Family_Inet, Socket_Datagram);
          Set_Socket_Option
          (  Socket,
             Socket_Level,
             (Reuse_Address, True)
          );
          Set_Socket_Option
          (  Socket,
             Socket_Level,
             (Broadcast, True)
          );
          Set_Socket_Option
          (  Socket,
             Socket_Level,
             (Receive_Timeout, <timeout>)
          );
          Bind_Socket (Socket, Address);
          Address.Addr := Broadcast_Inet_Addr;
          Send_Socket (Socket, <request-packet>, Last, Address'Access);
          loop -- Collecting responses, time-limited <timeout>
             ...
             Receive_Socket (Socket, <response-packet>, Last, Pier);
             ...
          end loop;
          Close_Socket (Socket);
       end;
    end loop;
end;

> In which case I would be grateful if anyone could tell me how I can iterate my adapters under Linux

Under Linux it is through the proc file system, if I correctly remember. 
I don't have it in the head right now.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Broadcasting UDP
@ 2016-04-24 16:31  4% ahlan.marriott
  2016-04-24 17:22  0% ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: ahlan.marriott @ 2016-04-24 16:31 UTC (permalink / raw)


I asked this question sometime ago but I can no longer find the post.
In any case it was never really resolved so let me try again.
I am looking for a platform independent Ada solution on how to broadcast a UDP packet.
I would be satisfied with a GNAT only solution, i.e. one that uses Gnat.Sockets and/or Gnat specific libraries.
Attempting to broadcast to the limited broadcast address 255.255.255.255 has no effect (under Windows at least)
To successfully broadcast one needs to use the subnet directed broadcast address.
As I want to support PCs that have multiple ethernet adapters this means that I must iterate over the ethernet adapters, discover my ethernet address and subnet for each adapter, calculate the broadcast address and then send the UDP packet to that address.
So far so good.
My problem is that I don't know how to iterate over my adapters and obtain the address and subnet mask for each adapter using just Ada.
Can anyone tell me how I can do this using Ada?

The solution I currently employ is to bind to a windows API.
However this is obviously not target independent.

If there is no Ada way of iterating over the ethernet adapters then I will have to do a separate implementation for each platform.
In which case I would be grateful if anyone could tell me how I can iterate my adapters under Linux and OSX.

Best wishes,
Ahlan

^ permalink raw reply	[relevance 4%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-24  8:13  6%               ` ahlan
@ 2016-04-24  8:31  6%                 ` Simon Wright
  2016-04-26 19:43  5%                   ` ahlan.marriott
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2016-04-24  8:31 UTC (permalink / raw)


ahlan@marriott.org writes:

> On Saturday, April 23, 2016 at 11:16:53 PM UTC+2, Simon Wright wrote:

>> I'm not sure it's relevant, but I posted a bug[1] on gnatmake & static
>> standalone libraries; I sent AdaCore a similar report on gprbuild, no
>> reply.

> Unfortunately your bug fix isn't included in the sources maintained by
> AdaCore at GitHub.
> So thank you for the improvement :-)

I guess I should post an issue there, then! Thanks for the nudge.


^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-23 21:16  5%             ` Simon Wright
@ 2016-04-24  8:13  6%               ` ahlan
  2016-04-24  8:31  6%                 ` Simon Wright
  2016-04-26 20:20  6%               ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: ahlan @ 2016-04-24  8:13 UTC (permalink / raw)


On Saturday, April 23, 2016 at 11:16:53 PM UTC+2, Simon Wright wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> 
> > Can [gprlib] build a static equivalent too? I.e. a static library
> > containing a closure of all referenced objects plus initialization
> > code.
> 
> I'm not sure it's relevant, but I posted a bug[1] on gnatmake & static
> standalone libraries; I sent AdaCore a similar report on gprbuild, no
> reply.
> 
> The problem was, for a static SAL, the using Ada main program needs to
> see all the ALIs for it to be sure to call in all the dylibs required by
> the library; so if e.g. libgnarl was only called by  non-interface units
> it would get linked but not elaborated.
> 
> I wanted to use SALs because they automatically populate the include
> directory with relevant source.
> 
> The GNAT GPL 2015 version of the patch is
> 
> diff --git a/src/gprlib.adb b/src/gprlib.adb
> --- a/src/gprlib.adb
> +++ b/src/gprlib.adb
> @@ -555,7 +555,7 @@
>        Status       : Boolean;
>  
>     begin
> -      if Standalone = No then
> +      if Standalone = No or Static then
>           for Index in 1 .. ALIs.Last loop
>              declare
>                 Destination : constant String :=
> 
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56616

Dear Simon,

Unfortunately your bug fix isn't included in the sources maintained by AdaCore at GitHub.
So thank you for the improvement :-)

Regards,
Ahlan


^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-23 19:56  6%           ` Dmitry A. Kazakov
@ 2016-04-23 21:16  5%             ` Simon Wright
  2016-04-24  8:13  6%               ` ahlan
  2016-04-26 20:20  6%               ` Dmitry A. Kazakov
  0 siblings, 2 replies; 200+ results
From: Simon Wright @ 2016-04-23 21:16 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:

> Can [gprlib] build a static equivalent too? I.e. a static library
> containing a closure of all referenced objects plus initialization
> code.

I'm not sure it's relevant, but I posted a bug[1] on gnatmake & static
standalone libraries; I sent AdaCore a similar report on gprbuild, no
reply.

The problem was, for a static SAL, the using Ada main program needs to
see all the ALIs for it to be sure to call in all the dylibs required by
the library; so if e.g. libgnarl was only called by  non-interface units
it would get linked but not elaborated.

I wanted to use SALs because they automatically populate the include
directory with relevant source.

The GNAT GPL 2015 version of the patch is

diff --git a/src/gprlib.adb b/src/gprlib.adb
--- a/src/gprlib.adb
+++ b/src/gprlib.adb
@@ -555,7 +555,7 @@
       Status       : Boolean;
 
    begin
-      if Standalone = No then
+      if Standalone = No or Static then
          for Index in 1 .. ALIs.Last loop
             declare
                Destination : constant String :=

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56616


^ permalink raw reply	[relevance 5%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-23 14:45 10%         ` ahlan.marriott
@ 2016-04-23 19:56  6%           ` Dmitry A. Kazakov
  2016-04-23 21:16  5%             ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-23 19:56 UTC (permalink / raw)


On 2016-04-23 16:45, ahlan.marriott@gmail.com wrote:
> On Saturday, 23 April 2016 11:49:13 UTC+2, Dmitry A. Kazakov  wrote:

> I downloaded the sources from Git using the link you supplied and built Gprlib.exe
> I could build this without the problems you mentioned.
> I guess these problem occur when you try and build the other utilities that GprBuild builds.
> However as I was only interested in Gprlib I only built that.
>
> I then copied this into the /libexe/gprbuild directory of my GNAT release
> and this then solved the problem. :-)
>
> Ie Using Gprlib.exe built from the latest git sources I was able to
> build a Windows encapsulated library (DLL) that uses Gnat.Sockets
> without have to use your Gcc_Wrapper workaround.

Great! Will test that next week.

Can it build a static equivalent too? I.e. a static library containing a 
closure of all referenced objects plus initialization code.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-23  9:48  5%       ` Dmitry A. Kazakov
@ 2016-04-23 14:45 10%         ` ahlan.marriott
  2016-04-23 19:56  6%           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: ahlan.marriott @ 2016-04-23 14:45 UTC (permalink / raw)


On Saturday, 23 April 2016 11:49:13 UTC+2, Dmitry A. Kazakov  wrote:
> On 2016-04-23 11:20, Ahlan wrote:
> 
> > The problem is not in Gprbuild.exe but in libexe/gprbuild/gprlib.exe
> > Have you tried building Gprlib from the git sources? - that might be a more elegant solution.
> 
> Yes I did. When you build gprbuild, it also builds all other utilities 
> including gprlib.exe.
> 
> You can try it yourself. It is here:
> 
>     https://github.com/AdaCore/gprbuild
> 
> There are two problems to fix to be able to do so:
> 
> 1. OS_Lib does not contain Kill and Kill_Process_Tree gprclear requires. 
> You can comment them out. Kill is relatively easy, you must add win32ada 
> to the project and do:
> 
>     procedure Kill (Pid : Process_Id; Hard_Kill : Boolean) is
>        use Win32.Winbase;
>        use Win32.Winnt;
>        Process : HANDLE;
>        Result  : Win32.BOOL;
>     begin
>        Process := OpenProcess
>                   (  PROCESS_ALL_ACCESS,
>                      1,
>                      Win32.DWORD (Pid_To_Integer (Pid))
>                   );
>        Result  := TerminateProcess (Process, 1);
>     end Kill;
> 
> Kill_Process_Tree is more complicated, but could be just Kill (:-))
> 
> 2. There is a dynamic_constraint somewhere put on a type, that promptly 
> crashes the compiler. I removed it.
> 
> However I was not aware of the directory ...\libexec\gprbuild. I 
> replaced only the executables in ...\bin. Thank you for the hint. Maybe 
> that would do the trick. I will try it next week and report back.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Dear Dmitry,
I downloaded the sources from Git using the link you supplied and built Gprlib.exe
I could build this without the problems you mentioned.
I guess these problem occur when you try and build the other utilities that GprBuild builds.
However as I was only interested in Gprlib I only built that.

I then copied this into the /libexe/gprbuild directory of my GNAT release
and this then solved the problem. :-)

Ie Using Gprlib.exe built from the latest git sources I was able to build a Windows encapsulated library (DLL) that uses Gnat.Sockets without have to use your Gcc_Wrapper workaround.

Best wishes,
Ahlan

^ permalink raw reply	[relevance 10%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-23  9:20  6%     ` Ahlan
@ 2016-04-23  9:48  5%       ` Dmitry A. Kazakov
  2016-04-23 14:45 10%         ` ahlan.marriott
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-23  9:48 UTC (permalink / raw)


On 2016-04-23 11:20, Ahlan wrote:

> The problem is not in Gprbuild.exe but in libexe/gprbuild/gprlib.exe
> Have you tried building Gprlib from the git sources? - that might be a more elegant solution.

Yes I did. When you build gprbuild, it also builds all other utilities 
including gprlib.exe.

You can try it yourself. It is here:

    https://github.com/AdaCore/gprbuild

There are two problems to fix to be able to do so:

1. OS_Lib does not contain Kill and Kill_Process_Tree gprclear requires. 
You can comment them out. Kill is relatively easy, you must add win32ada 
to the project and do:

    procedure Kill (Pid : Process_Id; Hard_Kill : Boolean) is
       use Win32.Winbase;
       use Win32.Winnt;
       Process : HANDLE;
       Result  : Win32.BOOL;
    begin
       Process := OpenProcess
                  (  PROCESS_ALL_ACCESS,
                     1,
                     Win32.DWORD (Pid_To_Integer (Pid))
                  );
       Result  := TerminateProcess (Process, 1);
    end Kill;

Kill_Process_Tree is more complicated, but could be just Kill (:-))

2. There is a dynamic_constraint somewhere put on a type, that promptly 
crashes the compiler. I removed it.

However I was not aware of the directory ...\libexec\gprbuild. I 
replaced only the executables in ...\bin. Thank you for the hint. Maybe 
that would do the trick. I will try it next week and report back.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2016-04-20 17:10  5%   ` Dmitry A. Kazakov
@ 2016-04-23  9:24  6%     ` ahlan.marriott
  0 siblings, 0 replies; 200+ results
From: ahlan.marriott @ 2016-04-23  9:24 UTC (permalink / raw)


On Wednesday, 20 April 2016 19:11:09 UTC+2, Dmitry A. Kazakov  wrote:
> On 2016-01-13 21:25, ahlan.marriott@gmail.com wrote:
> > On Thursday, 26 November 2015 08:57:02 UTC+1, ah...@marriott.org  wrote:
> >> We have windows programs and DLLs that use the Windows WinSock API directly.
> >> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> >> This is relatively trivial.
> >> Or at least it is for programs.
> >> When we try to convert our DLLs we run into a linker problem.
> >> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> >> See below.
> >> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> >> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> >> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> >>
> >> Best wishes,
> >> Ahlan
> >> -----------
> >>
> >> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> >> gprlib.exe Cal_Dll.lexch
> >> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> >> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> >> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> >> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> >> collect2.exe: error: ld returned 1 exit status
> >> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> >> gprbuild: could not build library for project cal_dll
> >> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s
> >
> > Dear all,
> >
> > It seems that this is an known problem.
> > At least to AdaCore.
> > They document it as KP-22-O331-001
> > The problem is fixed in GprBuild v2.2.2 that is part of Gnat Pro 7.3.2
> > Otherwise the workaround is not to produce an encapsulated DLL but
> > to  produce a standard DLL and link in the static version of the Gnat
> > runtime using Library_options.
> > A standard DLL will link WS2_32 and linking in the static runtime will produce a standalone DLL.
> 
> I built the latest grpbuild from Git sources (not easy under Windows). 
> The problem with encapsulated library projects persists.
> 
> Presently I believe it is related to the order in which libraries 
> wsock32 and ws2_32 appear in the linker's command like. From what I read 
> researching the issue, for some mysterious reasons, -lws2_32 -lwsock32 
> must appear *before* -shared -static-libgcc. So the linker line must 
> look like:
> 
> gcc.exe -lws2_32 -lwsock32 -shared -static-libgcc -o W:\product...
> 
> There is "Leading_Library_Option" project attribute, but it is no help 
> because it does not bring its content right after gcc.exe.
> 
> Any ideas how to do it otherwise?
> 
> For example, a very crude way would to write an application 
> my_gcc_wrapper that calls gcc with -lws2_32 -lwsock32 preceding all 
> other switches and replace
> 
> package Linker is
>     for Driver ("Ada") use "my_gcc_wrapper.exe";
> end Linker;
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Dear Dmitry,
This does indeed solve the problem.
However the problem is not in Gprbuild.exe but in libexec/gprbuild/gprlib.exe
Have you tried building that from the latest git sources?

MfG
Ahlan

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-22  8:23  6%   ` Dmitry A. Kazakov
@ 2016-04-23  9:20  6%     ` Ahlan
  2016-04-23  9:48  5%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: Ahlan @ 2016-04-23  9:20 UTC (permalink / raw)


On Friday, 22 April 2016 10:23:31 UTC+2, Dmitry A. Kazakov  wrote:
> On 22/04/2016 09:58, ahlan@marriott.org wrote:
> > On Thursday, 21 April 2016 15:00:04 UTC+2, Dmitry A. Kazakov  wrote:
> >> It seems I finally found a way to build it. The solution is quite
> >> perplexing. I would be glad if anybody could shed some light on it.
> >>
> >> An encapsulated library requires that -lws2_32 -lwsock32 appeared *both*
> >> at the beginning and the end of the linker command line. Only then no
> >> "undefined reference" messages appear.
> >>
> >> For this build this program:
> >> --------------------------------------- gcc_wrapper.adb ---
> >> with Ada.Command_Line;  use Ada.Command_Line;
> >> with Ada.Exceptions;    use Ada.Exceptions;
> >> with Ada.Text_IO;       use Ada.Text_IO;
> >> with GNAT.OS_Lib;       use GNAT.OS_Lib;
> >>
> >> procedure GCC_Wrapper is
> >>      Prefix : String_List :=
> >>               (  new String'("-lwsock32"),
> >>                  new String'("-lws2_32")
> >>               );
> >>      Options : String_List (1..Argument_Count);
> >> begin
> >>      for No in 1..Argument_Count loop
> >>         Options (No) := new String'(Argument (No));
> >>      end loop;
> >>      declare
> >>         List : String_List := Prefix & Options & Prefix;
> >>      begin
> >>         Put ("gcc.exe");
> >>         for No in List'Range loop
> >>            Put (" " & List (No).all);
> >>         end loop;
> >>         New_Line;
> >>         Set_Exit_Status (Exit_Status (Spawn ("gcc.exe", List)));
> >>      end;
> >> exception
> >>      when Error : others =>
> >>         Put_Line
> >>         (  Standard_Error,
> >>            "Fault: " & Exception_Information (Error)
> >>         );
> >>         Set_Exit_Status (2);
> >> end GCC_Wrapper;
> >> --------------------------------------- gcc_wrapper.adb ---
> >>
> >> The project file must contain:
> >>
> >>      package Linker is
> >>         for Driver use "<absolute-path-to>/gcc_wrapper.exe";
> >>      end Linker;
> >>
> >> --
> >> Regards,
> >> Dmitry A. Kazakov
> >> http://www.dmitry-kazakov.de
> >
> > Dear Dmitry,
> >
> > Is this perhaps the solution to my question "Using Gnat.Sockets in a Windows DLL" that I posted on 8-Dec-2015?
> 
> Yes, I think it is the same problem you reported. BTW, I built gprbuild 
> from the latest Git sources. That did not fix the problem.
> 
> It looks really weird how GCC linker searches libraries under Windows. 
> Not to mention its abysmal performance. It takes literally an hour to 
> link an executable against 20-30 libraries.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Dear Dmitry,
The problem is not in Gprbuild.exe but in libexe/gprbuild/gprlib.exe
Have you tried building Gprlib from the git sources? - that might be a more elegant solution.

MfG
Ahlan

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-22  7:58 11% ` ahlan.marriott
@ 2016-04-22  8:23  6%   ` Dmitry A. Kazakov
  2016-04-23  9:20  6%     ` Ahlan
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-22  8:23 UTC (permalink / raw)


On 22/04/2016 09:58, ahlan.marriott@gmail.com wrote:
> On Thursday, 21 April 2016 15:00:04 UTC+2, Dmitry A. Kazakov  wrote:
>> It seems I finally found a way to build it. The solution is quite
>> perplexing. I would be glad if anybody could shed some light on it.
>>
>> An encapsulated library requires that -lws2_32 -lwsock32 appeared *both*
>> at the beginning and the end of the linker command line. Only then no
>> "undefined reference" messages appear.
>>
>> For this build this program:
>> --------------------------------------- gcc_wrapper.adb ---
>> with Ada.Command_Line;  use Ada.Command_Line;
>> with Ada.Exceptions;    use Ada.Exceptions;
>> with Ada.Text_IO;       use Ada.Text_IO;
>> with GNAT.OS_Lib;       use GNAT.OS_Lib;
>>
>> procedure GCC_Wrapper is
>>      Prefix : String_List :=
>>               (  new String'("-lwsock32"),
>>                  new String'("-lws2_32")
>>               );
>>      Options : String_List (1..Argument_Count);
>> begin
>>      for No in 1..Argument_Count loop
>>         Options (No) := new String'(Argument (No));
>>      end loop;
>>      declare
>>         List : String_List := Prefix & Options & Prefix;
>>      begin
>>         Put ("gcc.exe");
>>         for No in List'Range loop
>>            Put (" " & List (No).all);
>>         end loop;
>>         New_Line;
>>         Set_Exit_Status (Exit_Status (Spawn ("gcc.exe", List)));
>>      end;
>> exception
>>      when Error : others =>
>>         Put_Line
>>         (  Standard_Error,
>>            "Fault: " & Exception_Information (Error)
>>         );
>>         Set_Exit_Status (2);
>> end GCC_Wrapper;
>> --------------------------------------- gcc_wrapper.adb ---
>>
>> The project file must contain:
>>
>>      package Linker is
>>         for Driver use "<absolute-path-to>/gcc_wrapper.exe";
>>      end Linker;
>>
>> --
>> Regards,
>> Dmitry A. Kazakov
>> http://www.dmitry-kazakov.de
>
> Dear Dmitry,
>
> Is this perhaps the solution to my question "Using Gnat.Sockets in a Windows DLL" that I posted on 8-Dec-2015?

Yes, I think it is the same problem you reported. BTW, I built gprbuild 
from the latest Git sources. That did not fix the problem.

It looks really weird how GCC linker searches libraries under Windows. 
Not to mention its abysmal performance. It takes literally an hour to 
link an executable against 20-30 libraries.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Building an encapsulated library that uses GNAT sockets under Windows
  2016-04-21 12:59  5% Building an encapsulated library that uses GNAT sockets under Windows Dmitry A. Kazakov
@ 2016-04-22  7:58 11% ` ahlan.marriott
  2016-04-22  8:23  6%   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: ahlan.marriott @ 2016-04-22  7:58 UTC (permalink / raw)


On Thursday, 21 April 2016 15:00:04 UTC+2, Dmitry A. Kazakov  wrote:
> It seems I finally found a way to build it. The solution is quite 
> perplexing. I would be glad if anybody could shed some light on it.
> 
> An encapsulated library requires that -lws2_32 -lwsock32 appeared *both* 
> at the beginning and the end of the linker command line. Only then no 
> "undefined reference" messages appear.
> 
> For this build this program:
> --------------------------------------- gcc_wrapper.adb ---
> with Ada.Command_Line;  use Ada.Command_Line;
> with Ada.Exceptions;    use Ada.Exceptions;
> with Ada.Text_IO;       use Ada.Text_IO;
> with GNAT.OS_Lib;       use GNAT.OS_Lib;
> 
> procedure GCC_Wrapper is
>     Prefix : String_List :=
>              (  new String'("-lwsock32"),
>                 new String'("-lws2_32")
>              );
>     Options : String_List (1..Argument_Count);
> begin
>     for No in 1..Argument_Count loop
>        Options (No) := new String'(Argument (No));
>     end loop;
>     declare
>        List : String_List := Prefix & Options & Prefix;
>     begin
>        Put ("gcc.exe");
>        for No in List'Range loop
>           Put (" " & List (No).all);
>        end loop;
>        New_Line;
>        Set_Exit_Status (Exit_Status (Spawn ("gcc.exe", List)));
>     end;
> exception
>     when Error : others =>
>        Put_Line
>        (  Standard_Error,
>           "Fault: " & Exception_Information (Error)
>        );
>        Set_Exit_Status (2);
> end GCC_Wrapper;
> --------------------------------------- gcc_wrapper.adb ---
> 
> The project file must contain:
> 
>     package Linker is
>        for Driver use "<absolute-path-to>/gcc_wrapper.exe";
>     end Linker;
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Dear Dmitry,

Is this perhaps the solution to my question "Using Gnat.Sockets in a Windows DLL" that I posted on 8-Dec-2015?

Regards,
Ahlan


^ permalink raw reply	[relevance 11%]

* Building an encapsulated library that uses GNAT sockets under Windows
@ 2016-04-21 12:59  5% Dmitry A. Kazakov
  2016-04-22  7:58 11% ` ahlan.marriott
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-21 12:59 UTC (permalink / raw)


It seems I finally found a way to build it. The solution is quite 
perplexing. I would be glad if anybody could shed some light on it.

An encapsulated library requires that -lws2_32 -lwsock32 appeared *both* 
at the beginning and the end of the linker command line. Only then no 
"undefined reference" messages appear.

For this build this program:
--------------------------------------- gcc_wrapper.adb ---
with Ada.Command_Line;  use Ada.Command_Line;
with Ada.Exceptions;    use Ada.Exceptions;
with Ada.Text_IO;       use Ada.Text_IO;
with GNAT.OS_Lib;       use GNAT.OS_Lib;

procedure GCC_Wrapper is
    Prefix : String_List :=
             (  new String'("-lwsock32"),
                new String'("-lws2_32")
             );
    Options : String_List (1..Argument_Count);
begin
    for No in 1..Argument_Count loop
       Options (No) := new String'(Argument (No));
    end loop;
    declare
       List : String_List := Prefix & Options & Prefix;
    begin
       Put ("gcc.exe");
       for No in List'Range loop
          Put (" " & List (No).all);
       end loop;
       New_Line;
       Set_Exit_Status (Exit_Status (Spawn ("gcc.exe", List)));
    end;
exception
    when Error : others =>
       Put_Line
       (  Standard_Error,
          "Fault: " & Exception_Information (Error)
       );
       Set_Exit_Status (2);
end GCC_Wrapper;
--------------------------------------- gcc_wrapper.adb ---

The project file must contain:

    package Linker is
       for Driver use "<absolute-path-to>/gcc_wrapper.exe";
    end Linker;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2016-01-13 20:25  5% ` ahlan.marriott
@ 2016-04-20 17:10  5%   ` Dmitry A. Kazakov
  2016-04-23  9:24  6%     ` ahlan.marriott
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2016-04-20 17:10 UTC (permalink / raw)


On 2016-01-13 21:25, ahlan.marriott@gmail.com wrote:
> On Thursday, 26 November 2015 08:57:02 UTC+1, ah...@marriott.org  wrote:
>> We have windows programs and DLLs that use the Windows WinSock API directly.
>> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
>> This is relatively trivial.
>> Or at least it is for programs.
>> When we try to convert our DLLs we run into a linker problem.
>> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
>> See below.
>> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
>> Except that the names are not quite right so I suspect that this is the root cause of the problem.
>> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
>>
>> Best wishes,
>> Ahlan
>> -----------
>>
>> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
>> gprlib.exe Cal_Dll.lexch
>> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
>> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
>> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
>> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
>> collect2.exe: error: ld returned 1 exit status
>> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
>> gprbuild: could not build library for project cal_dll
>> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s
>
> Dear all,
>
> It seems that this is an known problem.
> At least to AdaCore.
> They document it as KP-22-O331-001
> The problem is fixed in GprBuild v2.2.2 that is part of Gnat Pro 7.3.2
> Otherwise the workaround is not to produce an encapsulated DLL but
> to  produce a standard DLL and link in the static version of the Gnat
> runtime using Library_options.
> A standard DLL will link WS2_32 and linking in the static runtime will produce a standalone DLL.

I built the latest grpbuild from Git sources (not easy under Windows). 
The problem with encapsulated library projects persists.

Presently I believe it is related to the order in which libraries 
wsock32 and ws2_32 appear in the linker's command like. From what I read 
researching the issue, for some mysterious reasons, -lws2_32 -lwsock32 
must appear *before* -shared -static-libgcc. So the linker line must 
look like:

gcc.exe -lws2_32 -lwsock32 -shared -static-libgcc -o W:\product...

There is "Leading_Library_Option" project attribute, but it is no help 
because it does not bring its content right after gcc.exe.

Any ideas how to do it otherwise?

For example, a very crude way would to write an application 
my_gcc_wrapper that calls gcc with -lws2_32 -lwsock32 preceding all 
other switches and replace

package Linker is
    for Driver ("Ada") use "my_gcc_wrapper.exe";
end Linker;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
                   ` (6 preceding siblings ...)
  2015-12-24 14:46  9% ` ahlan
@ 2016-01-13 20:25  5% ` ahlan.marriott
  2016-04-20 17:10  5%   ` Dmitry A. Kazakov
  7 siblings, 1 reply; 200+ results
From: ahlan.marriott @ 2016-01-13 20:25 UTC (permalink / raw)


On Thursday, 26 November 2015 08:57:02 UTC+1, ah...@marriott.org  wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s

Dear all,

It seems that this is an known problem.
At least to AdaCore.
They document it as KP-22-O331-001
The problem is fixed in GprBuild v2.2.2 that is part of Gnat Pro 7.3.2
Otherwise the workaround is not to produce an encapsulated DLL but to produce a standard DLL and link in the static version of the Gnat runtime using Library_options.
A standard DLL will link WS2_32 and linking in the static runtime will produce a standalone DLL.

MfG
Ahlan

^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-24 14:46  9% ` ahlan
@ 2015-12-25 11:09  5%   ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2015-12-25 11:09 UTC (permalink / raw)


ahlan@marriott.org writes:

> To summarise: We want to build an encapsulated DLL so that we don't
> have to distribute the Ada Runtime etc. AdaCore define an encapsulated
> library as only depending on system libraries.
> However I wonder what is meant by system libraries.

From the sources of GPRBUILD GPL 2015, at gprlib.adb:2213,

    Library_Options_Table.Append (Libgnat);

    --  ?? The proper implementation for the following code is to
    --  add only the libraries that libgnat is using. This information
    --  is not readily available but we should be able to compute
    --  this from the ALI files.

    declare
       I : constant Natural := Object_Files.Last;
    begin
       --  Then adds back all libraries already on the command-line
       --  after libgnat to fulfill dependencies on OS libraries
       --  that may be used by the GNAT runtime. These are libraries
       --  added with a pragma Linker_Options in sources.

Not much help, I konw.

^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
                   ` (5 preceding siblings ...)
  2015-12-11 17:53 12% ` ahlan
@ 2015-12-24 14:46  9% ` ahlan
  2015-12-25 11:09  5%   ` Simon Wright
  2016-01-13 20:25  5% ` ahlan.marriott
  7 siblings, 1 reply; 200+ results
From: ahlan @ 2015-12-24 14:46 UTC (permalink / raw)


On Thursday, November 26, 2015 at 8:57:02 AM UTC+1, ah...@marriott.org wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s


To summarise: We want to build an encapsulated DLL so that we don't have to distribute the Ada Runtime etc. AdaCore define an encapsulated library as only depending on system libraries.
However I wonder what is meant by system libraries.
We can successfully link if we restrict ourselves coroutines defined in Win32
In our gpr we "with Win32ada;" and can link Winsock routines
however if we try to use Gnat.Sockets the link fails to find entry points such as gethostname@8
this entry point is defined in libws2_32.a but all our attempts to provide this static library seem to be ignored.
We have tried pragma linker_options and specifying the file using "for linker_Options use" in the project gpr.
I have even tried making a library project gpr file with the sole purpose of defining where libws2_32.a can be found.
I suspect therefore that encapsulated libraries somehow "know" what libraries are "system libraries" and ignores all attempts to include others.
Which therefore begs the question as to how I can add Ws2_32 to this list of known libraries.
Surely Ws2_32 is as much a system library as WinSock?
so why should encapsulated libraries be able to use Winsock and not Ws2_32?
Any ideas anyone?


^ permalink raw reply	[relevance 9%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-12 19:44  6%     ` ahlan
@ 2015-12-12 20:38  6%       ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2015-12-12 20:38 UTC (permalink / raw)


On Saturday, 12 December 2015 19:44:07 UTC, ah...@marriott.org  wrote:
> On Saturday, December 12, 2015 at 1:47:58 PM UTC+1, Simon Wright wrote:
> > ahlan@marriott.org writes:

> > > Is this post better?
> > 
> > It has many fewer lines, but it's still a reply to your original post,
> > which means that I can't go to the post it's actually a reply to.
> > 
> > On the other hand, I think you may be using Google Groups?, and I see
> > that GG has no threading capability at all! (or perhaps it's very well
> > hidden).
> 
> Yes I am using Google groups using Safari as web browser - is there another way?

Same here, this time (normally I use Emacs Gnus).

This post of yours appeared as a follow-up to my post, which is the way it should be; I used the double-headed arrow at top right of your post to follow-up.

^ permalink raw reply	[relevance 6%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-12 12:47  6%   ` Simon Wright
@ 2015-12-12 19:44  6%     ` ahlan
  2015-12-12 20:38  6%       ` Simon Wright
  0 siblings, 1 reply; 200+ results
From: ahlan @ 2015-12-12 19:44 UTC (permalink / raw)


On Saturday, December 12, 2015 at 1:47:58 PM UTC+1, Simon Wright wrote:
> ahlan@marriott.org writes:
> 
> > Dear Simon,
> > The Monitor DLL is a deliverable that is used by non-Ada programs.
> > It uses code that is used by other projects that I would like to
> > execute on platforms other than Windows
> > Hence the interest in using Gnat Sockets.
> > However we want the DLL to be self contained (other than for the
> > Windows DLL that all Windows systems have) so that we don't have to
> > ship Gnat DLLs etc along with our DLL.
> 
> I see, thanks for the clarification. I thought the suggestion might
> help, clearly not! Sorry.
> 
> > Is this post better?
> 
> It has many fewer lines, but it's still a reply to your original post,
> which means that I can't go to the post it's actually a reply to.
> 
> On the other hand, I think you may be using Google Groups?, and I see
> that GG has no threading capability at all! (or perhaps it's very well
> hidden).

Dear Simon,
Yes I am using Google groups using Safari as web browser - is there another way?
Regards,
Ahlan

^ permalink raw reply	[relevance 6%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-11 17:53 12% ` ahlan
@ 2015-12-12 12:47  6%   ` Simon Wright
  2015-12-12 19:44  6%     ` ahlan
  0 siblings, 1 reply; 200+ results
From: Simon Wright @ 2015-12-12 12:47 UTC (permalink / raw)


ahlan@marriott.org writes:

> Dear Simon,
> The Monitor DLL is a deliverable that is used by non-Ada programs.
> It uses code that is used by other projects that I would like to
> execute on platforms other than Windows
> Hence the interest in using Gnat Sockets.
> However we want the DLL to be self contained (other than for the
> Windows DLL that all Windows systems have) so that we don't have to
> ship Gnat DLLs etc along with our DLL.

I see, thanks for the clarification. I thought the suggestion might
help, clearly not! Sorry.

> Is this post better?

It has many fewer lines, but it's still a reply to your original post,
which means that I can't go to the post it's actually a reply to.

On the other hand, I think you may be using Google Groups?, and I see
that GG has no threading capability at all! (or perhaps it's very well
hidden).

^ permalink raw reply	[relevance 6%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
                   ` (4 preceding siblings ...)
  2015-12-09 15:06 12% ` ahlan
@ 2015-12-11 17:53 12% ` ahlan
  2015-12-12 12:47  6%   ` Simon Wright
  2015-12-24 14:46  9% ` ahlan
  2016-01-13 20:25  5% ` ahlan.marriott
  7 siblings, 1 reply; 200+ results
From: ahlan @ 2015-12-11 17:53 UTC (permalink / raw)


Dear Dmitry,

We currently use Winsock2 but I would like to use Gnat Sockets so that our code can run on platforms other than Windows.
The DLL will be Windows only but it shares code that we use with executables that I would like to run on Linux and OSX. For this reason I would like this shared code to use Gnat Sockets.

Dear Simon,
The Monitor DLL is a deliverable that is used by non-Ada programs.
It uses code that is used by other projects that I would like to execute on platforms other than Windows
Hence the interest in using Gnat Sockets.
However we want the DLL to be self contained (other than for the Windows DLL that all Windows systems have) so that we don't have to ship Gnat DLLs etc along with our DLL.

Is this post better?

Best regards,
Ahlan


^ permalink raw reply	[relevance 12%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-09 15:06 12% ` ahlan
  2015-12-09 15:58 13%   ` Dmitry A. Kazakov
@ 2015-12-09 19:11  6%   ` Simon Wright
  1 sibling, 0 replies; 200+ results
From: Simon Wright @ 2015-12-09 19:11 UTC (permalink / raw)


ahlan@marriott.org writes:

> We didn't forget, we want to use a static build so that our DLLs are
> self contained so that, with the exception of Window System DLLs, we
> don't have to distribute lots of DLLs. Eg Gnat runtime.
>
> Is there a way that we can make encapsulated DLLs that use Gnat.sockets?
> It should be possible because, at the end of the day, Gnat Sockets is
> using the same Windows API that Win32 uses.

Looking at the AdaCore documentation, it's far from clear what the use
case for 'encapsulated' is.

You said above that you were having trouble with a shared library
'monitor', I don't understand why you don't build the whole project with
static libraries?

(BTW, could you look at how you're posting? I see 64 lines quoting your
original post - not even the one you're replying to - before I get to
the new material)


^ permalink raw reply	[relevance 6%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-09 15:06 12% ` ahlan
@ 2015-12-09 15:58 13%   ` Dmitry A. Kazakov
  2015-12-09 19:11  6%   ` Simon Wright
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2015-12-09 15:58 UTC (permalink / raw)


On Wed, 9 Dec 2015 07:06:37 -0800 (PST), ahlan@marriott.org wrote:

> Is there a way that we can make encapsulated DLLs that use Gnat.sockets?

You could copy GNAT.Sockets source files into your project and patch them a
bit.

> It should be possible because, at the end of the day, Gnat Sockets is
> using the same Windows API that Win32 uses.

Maybe yes, maybe no. There might be some initialization required and/or
conflicts when statically linked.

But if you are going to use Windows API, then your library would not be
portable. Thus there is not much sense to use GNAT.Sockets. The beauty of
GNAT.Sockets is that it is same under Windows, Linux, VxWorks.

Use Winsock2 straight away. There is no much difference to GNAT.Sockets
anyway (except for socket selector).

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 13%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
                   ` (3 preceding siblings ...)
  2015-12-09 12:02  6% ` ahlan
@ 2015-12-09 15:06 12% ` ahlan
  2015-12-09 15:58 13%   ` Dmitry A. Kazakov
  2015-12-09 19:11  6%   ` Simon Wright
  2015-12-11 17:53 12% ` ahlan
                   ` (2 subsequent siblings)
  7 siblings, 2 replies; 200+ results
From: ahlan @ 2015-12-09 15:06 UTC (permalink / raw)


On Thursday, November 26, 2015 at 8:57:02 AM UTC+1, ah...@marriott.org wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s

Dear Dmitry,

We didn't forget, we want to use a static build so that our DLLs are self contained so that, with the exception of Window System DLLs, we don't have to distribute lots of DLLs. Eg Gnat runtime.

Is there a way that we can make encapsulated DLLs that use Gnat.sockets?
It should be possible because, at the end of the day, Gnat Sockets is using the same Windows API that Win32 uses.

MfG
Ahlan


^ permalink raw reply	[relevance 12%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-09 12:02  6% ` ahlan
@ 2015-12-09 12:33 11%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2015-12-09 12:33 UTC (permalink / raw)


On Wed, 9 Dec 2015 04:02:13 -0800 (PST), ahlan@marriott.org wrote:

> We have to set encapsulated otherwise GprBuild complains
> shared library project "monitor" cannot import static library project "win32ada"

This is because you forgot to select the "relocatable" scenario for
win32ada. E.g. when using gprbuild:

   grpbuild -P... -XWIN32ADA_BUILD=relocatable

There is a static build of win32ada which is the default scenario.

 E.g.
----- test.gpr >>>>>>>>>>>
with "win32Ada.gpr";
library project Test is
   for Library_Name use "test";
   for Library_Kind use "dynamic";
   for Library_Dir  use "c:/temp";
   for Library_Interface use ("test"); 
   for Library_Standalone use "standard";
end Test;
----- test.gpr <<<<<<<<<<<

---- test.adb >>>>>>>>>>>
with GNAT.Sockets;  use GNAT.Sockets;
with Win32;         use Win32;
with Win32.WinBase; use Win32.WinBase;
with Win32.WinNT;   use Win32.WinNT;

function Test return String is
   Self : HANDLE;
begin
   Self := GetCurrentProcess; -- Windows API call
   return Host_Name; -- GNAT.Sockets call
end Test;
---- test.adb <<<<<<<<<<<

gprbuild -d -PC:\Temp\Z\test.gpr -XWIN32ADA_BUILD=relocatable
gcc -c test.adb
gprlib.exe test.lexch
gnatbind -n -o b__test.adb -Ltest -a C:\Temp\Z\test.ali
gcc.exe -c -x ada -gnatA -gnatws b__test.adb -o b__test.o ...
gcc.exe -shared -shared-libgcc -o C:\temp\libtest.dll ... C:\Temp\Z\test.o
...

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 11%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
                   ` (2 preceding siblings ...)
  2015-12-09  7:20  5% ` ahlan
@ 2015-12-09 12:02  6% ` ahlan
  2015-12-09 12:33 11%   ` Dmitry A. Kazakov
  2015-12-09 15:06 12% ` ahlan
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 200+ results
From: ahlan @ 2015-12-09 12:02 UTC (permalink / raw)


On Thursday, November 26, 2015 at 8:57:02 AM UTC+1, ah...@marriott.org wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s

Dear Dmitry,
We have to set encapsulated otherwise GprBuild complains
shared library project "monitor" cannot import static library project "win32ada"
because we with Win32Ada in order that we can make calls to the Windows API
Does this mean that the solution is to write a Gnat_Sockets.gpr?
If so what would look like - or does it already exist?


^ permalink raw reply	[relevance 6%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-09  7:20  5% ` ahlan
@ 2015-12-09  9:20 11%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2015-12-09  9:20 UTC (permalink / raw)


On Tue, 8 Dec 2015 23:20:03 -0800 (PST), ahlan@marriott.org wrote:

> Can you reproduce this problem on your system?

Ah, I overlooked that you did this:

   for Library_Standalone use "encapsulated";

An encapsulated project cannot depend on any dynamic libraries.

Since WS2_32 is a DLL, you cannot use it and thus GNAT.Sockets as well
because Windows does not provide static versions of system libraries.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 11%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
  2015-11-26  8:39  6% ` Dmitry A. Kazakov
  2015-12-08  7:43 11% ` ahlan
@ 2015-12-09  7:20  5% ` ahlan
  2015-12-09  9:20 11%   ` Dmitry A. Kazakov
  2015-12-09 12:02  6% ` ahlan
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 200+ results
From: ahlan @ 2015-12-09  7:20 UTC (permalink / raw)


On Thursday, November 26, 2015 at 8:57:02 AM UTC+1, ah...@marriott.org wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s

Dear Dmitry,
Adding
package Linker is
   for Linker_Options use ("-lws2_32");
end Linker; 
to my Gpr file made absolutely no difference.
Can you reproduce this problem on your system?
If so and if your solution works what version of Gnat are you using?
I am using GPL 2015

All you have to do is create a socket in an exist DLL product.
Ie a three line change.

To be honest I didn't expect your solution to work because surely this is equivalent to my adding pragma Linker_Options into the source, which, as I wrote did not help.


^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-12-08  7:43 11% ` ahlan
@ 2015-12-08  9:52  5%   ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2015-12-08  9:52 UTC (permalink / raw)


On Mon, 7 Dec 2015 23:43:18 -0800 (PST), ahlan@marriott.org wrote:

> If I have a one line test program that merely initialises a socket, ie
> 
>   My_Socket : GNAT.Sockets.Socket_Type;
> begin
>   GNAT.Sockets.Create_Socket (My_Socket);
> 
> then we have no problems building an executable but if we try and use the same
> lines in a DLL we fail to find the external references.
> Even if I explicitly put "Pragma Linker_Options ("-lws2_32");
> and place libws2_32.a in the Library_Dir Gnat still fails to satisfy the references.
> 
> I am at a loss as to what I might be doing wrong and what I could try next.
> This should be easy to solve, it probably has nothing to do with Gnat Sockets
> but more to do with building DLLs using a GPR file.
> 
> The following is our Gpr file
> with "gtkada";
> with "win32ada";
> 
> project Monitor is
> 
>    package Naming is
>       for Casing use "mixedcase";
>    end Naming;
> 
>    for Library_Name use "Monitor";
>    for Shared_Library_Prefix use "";
> 
>    for Source_Dirs use ("w:\source\ada\interfaces\monitor",
>                         "w:\source\ada\interfaces",
>                         "w:\source\ada\shared",
>                         "w:\source\ada\open\shared");
> 
>    for Library_Interface use ("Monitor_Interface");
> 
>    for Object_Dir use "objects";
> 
>    for Library_Options use ("-Lw:\product\windows", "resources.o");
>    for Library_Dir use "w:\product\windows";
>    for Library_Ali_Dir use "d:\binary\ada\interfaces\monitor";
>    for Library_Kind use "dynamic";
>    for Library_Standalone use "encapsulated";
> 
>    package Pretty_Printer is
>       for Default_Switches ("ada") use ("-i2", "-M120", "-aL", "-A1", "-A4");
>    end Pretty_Printer;
> 
>    package Builder is
>       for Default_Switches ("ada") use ("-s", "-g");
>    end Builder;
> 
>    package Compiler is
>       for Default_Switches ("ada") use ("-O1", "-gnatQ", "-gnato", "-g", "-gnat12",
>                                         "-gnatwcehijkmopruvz.c.n.p.t.w.x", "-gnatykmpM120");
>    end Compiler;
> 
>    package Binder is
>       for Default_Switches ("ada") use ("-E");
>    end Binder;

How about:

package Linker is
   for Linker_Options use ("-lws2_32");
end Linker;

P.S. You also can create projects for the external DLLs (like Windows DLL)
you wanted to use. E.g.

project w32n55 is
   for Externally_Built use "true";
   for Source_Files use ();
   for Library_Dir use "where the DLL resides";
   for Library_Name use "w32n55";
   for Library_Kind use "dynamic";
end w32n55;

Then you "with" this project in your project.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 5%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
  2015-11-26  8:39  6% ` Dmitry A. Kazakov
@ 2015-12-08  7:43 11% ` ahlan
  2015-12-08  9:52  5%   ` Dmitry A. Kazakov
  2015-12-09  7:20  5% ` ahlan
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 200+ results
From: ahlan @ 2015-12-08  7:43 UTC (permalink / raw)


On Thursday, November 26, 2015 at 8:57:02 AM UTC+1, ah...@marriott.org wrote:
> We have windows programs and DLLs that use the Windows WinSock API directly.
> In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
> This is relatively trivial.
> Or at least it is for programs.
> When we try to convert our DLLs we run into a linker problem.
> If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
> See below.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
> Except that the names are not quite right so I suspect that this is the root cause of the problem.
> Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?
> 
> Best wishes,
> Ahlan
> -----------
> 
> gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
> gprlib.exe Cal_Dll.lexch
> gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
> gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
> gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
> C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
> collect2.exe: error: ld returned 1 exit status
> gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
> gprbuild: could not build library for project cal_dll
> [2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s

If I have a one line test program that merely initialises a socket, ie

  My_Socket : GNAT.Sockets.Socket_Type;
begin
  GNAT.Sockets.Create_Socket (My_Socket);

then we have no problems building an executable but if we try and use the same
lines in a DLL we fail to find the external references.
Even if I explicitly put "Pragma Linker_Options ("-lws2_32");
and place libws2_32.a in the Library_Dir Gnat still fails to satisfy the references.

I am at a loss as to what I might be doing wrong and what I could try next.
This should be easy to solve, it probably has nothing to do with Gnat Sockets
but more to do with building DLLs using a GPR file.

The following is our Gpr file
with "gtkada";
with "win32ada";

project Monitor is

   package Naming is
      for Casing use "mixedcase";
   end Naming;

   for Library_Name use "Monitor";
   for Shared_Library_Prefix use "";

   for Source_Dirs use ("w:\source\ada\interfaces\monitor",
                        "w:\source\ada\interfaces",
                        "w:\source\ada\shared",
                        "w:\source\ada\open\shared");

   for Library_Interface use ("Monitor_Interface");

   for Object_Dir use "objects";

   for Library_Options use ("-Lw:\product\windows", "resources.o");
   for Library_Dir use "w:\product\windows";
   for Library_Ali_Dir use "d:\binary\ada\interfaces\monitor";
   for Library_Kind use "dynamic";
   for Library_Standalone use "encapsulated";

   package Pretty_Printer is
      for Default_Switches ("ada") use ("-i2", "-M120", "-aL", "-A1", "-A4");
   end Pretty_Printer;

   package Builder is
      for Default_Switches ("ada") use ("-s", "-g");
   end Builder;

   package Compiler is
      for Default_Switches ("ada") use ("-O1", "-gnatQ", "-gnato", "-g", "-gnat12",
                                        "-gnatwcehijkmopruvz.c.n.p.t.w.x", "-gnatykmpM120");
   end Compiler;

   package Binder is
      for Default_Switches ("ada") use ("-E");
   end Binder;




We build are DLLs using Gprbuild.
I


^ permalink raw reply	[relevance 11%]

* Re: Using Gnat.Sockets in a Windows DLL
  2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
@ 2015-11-26  8:39  6% ` Dmitry A. Kazakov
  2015-12-08  7:43 11% ` ahlan
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2015-11-26  8:39 UTC (permalink / raw)


On Wed, 25 Nov 2015 23:56:55 -0800 (PST), ahlan@marriott.org wrote:

> We have windows programs and DLLs that use the Windows WinSock API directly.
> I recognize many of them as being in WS2_32.dll - which GprBuild finds
> when we build our programs (its in Windows/System32)

Yes

> Except that the names are not quite right so I suspect that this is the
> root cause of the problem.

The names are right, WinSock2 has stdcall conventions and names.

> Has anyone any idea why a build of a DLL should behave differently to a
> build of a program with respect to name mangling?

It should not. You link to libws2_32.a import library, which comes with
GNAT distribution.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Using Gnat.Sockets in a Windows DLL
@ 2015-11-26  7:56  8% ahlan
  2015-11-26  8:39  6% ` Dmitry A. Kazakov
                   ` (7 more replies)
  0 siblings, 8 replies; 200+ results
From: ahlan @ 2015-11-26  7:56 UTC (permalink / raw)


We have windows programs and DLLs that use the Windows WinSock API directly.
In order to make this code target independent (at least for Linux & OSX) we thought we should convert the code to use Gnat.Sockets.
This is relatively trivial.
Or at least it is for programs.
When we try to convert our DLLs we run into a linker problem.
If all we do is a "with Gnat.Sockets" then using GprBuild produces lots of messages saying that various entry points could not be found.
See below.
I recognize many of them as being in WS2_32.dll - which GprBuild finds when we build our programs (its in Windows/System32)
Except that the names are not quite right so I suspect that this is the root cause of the problem.
Has anyone any idea why a build of a DLL should behave differently to a build of a program with respect to name mangling?

Best wishes,
Ahlan
-----------

gprbuild -d -PD:\Binary\Ada\tools\cal_dll\Cal_Dll.gpr -XWIN32ADA_BUILD=default -XLIBRARY_TYPE=static
gprlib.exe Cal_Dll.lexch
gnatbind -n -o b__Cal_Dll.adb -LCal_Dll -a -E D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.ali
gcc.exe -c -x ada -gnatA -gnatws b__cal_dll.adb -o b__cal_dll.o ...
gcc.exe -shared -static-libgcc -o W:\product\windows\Cal_Dll.dll D:\Binary\Ada\tools\cal_dll\objects\cal_dll_interface.o ...
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1b46): undefined reference to `gethostname@8'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x1c9c): undefined reference to `getpeername@12'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x2323): undefined reference to `getsockopt@20'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socket.o):g-socket.adb:(.text+0x3518): undefined reference to `getsockopt@20'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x1c): undefined reference to `WSASetLastError@4'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x246): undefined reference to `WSASetLastError@4'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(g-socthi.o):g-socthi.adb:(.text+0x27f): undefined reference to `WSASetLastError@4'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x109): undefined reference to `_imp__getservbyname@8'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x159): undefined reference to `_imp__getservbyport@8'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x2a4): undefined reference to `__WSAFDIsSet@8'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x34c): undefined reference to `_imp__ioctlsocket@12'
C:\gnatpro\7.3.1\lib\gcc\i686-pc-mingw32\4.9.3\/adalib/libgnat.a(socket.o):socket.c:(.text+0x3b4): undefined reference to `_imp__WSAStringToAddressA@20'
collect2.exe: error: ld returned 1 exit status
gprlib: c:\gnatpro\7.3.1\bin\gcc execution error
gprbuild: could not build library for project cal_dll
[2015-11-26 08:36:34] process exited with status 4, 100% (36/36), elapsed time: 01.67s

^ permalink raw reply	[relevance 8%]

* Gnoga on Windows 10
@ 2015-08-02  3:04  5% David Botton
  0 siblings, 0 replies; 200+ results
From: David Botton @ 2015-08-02  3:04 UTC (permalink / raw)


I've tested windows 10 using TDM-GCC 5.1 (64 bit windows) and msysgit shell as well as the built in command prompt, in both cases all built and ran properly (less the sql examples and python 2.7 examples since I don't have build for those windows lib around). In both cases build time was much faster on Windows 10 then 8 (using same gcc version) and in fact was outpacing the linux builds on the same machine for the first time ever.

My tests ran with out issue.

Of course Gnoga runs with out issue on any platform that supports FSF GNAT 4.7 (and also has run time support for gnat sockets) and above including Raspberry Pi, Linux, *BSD, Windows 32 and 64 bits, Mac OSX, etc.

David Botton

^ permalink raw reply	[relevance 5%]

* Re: ANN: GCC 5.1.0 for Mac OS X
  @ 2015-04-30 12:23  5% ` Simon Wright
  0 siblings, 0 replies; 200+ results
From: Simon Wright @ 2015-04-30 12:23 UTC (permalink / raw)


Simon Wright <simon@pushface.org> writes:

> This is GCC 5.1.0

One user-visible change I've noted, in GNAT.Sockets, is that
Vector_Element.Length (used in Vector_Type, used in Receive_Vector and
Send_Vector) is now of type Interfaces.C.size_t; used to be
Ada.Streams.Stream_Element_Count. I guess this is for efficiency in
scatter-gather operations.

^ permalink raw reply	[relevance 5%]

* Re: Questions about Gnat.sockets and raw socket
  2015-04-23  9:21  6% Questions about Gnat.sockets and raw socket loïc maury
  2015-04-23 12:19 13% ` Dmitry A. Kazakov
@ 2015-04-28 10:21  6% ` loïc maury
  1 sibling, 0 replies; 200+ results
From: loïc maury @ 2015-04-28 10:21 UTC (permalink / raw)



Hello,

Finally I used WFP, but unfortunately, in native, it seem to be too complicated
for a binding in Ada.

Thank you

Best

Loic 


Le jeudi 23 avril 2015 11:21:01 UTC+2, loïc maury a écrit :
> Hello,
> 
> For a personal project, I want to create  a packet analyzer.
> 
> Can I use Gnat.socket, for raw socket programming ? it is not clear
> 
> for me, and unfortunately I didn't found any answers in the ada groups.
> 
> I will use it under Windows.
> 
> Thank you
> 
> Best
> 
> Loic

^ permalink raw reply	[relevance 6%]

* Re: Questions about Gnat.sockets and raw socket
  2015-04-23 16:14  6%       ` Dmitry A. Kazakov
@ 2015-04-23 17:32  6%         ` Qun-Ying
  0 siblings, 0 replies; 200+ results
From: Qun-Ying @ 2015-04-23 17:32 UTC (permalink / raw)


Dmitry A. Kazakov wrote:
> On Thu, 23 Apr 2015 08:41:50 -0700 (PDT), loïc maury wrote:
>
> Winpcap is not free, only its run-time is. But you will also need the SDK,
> which is five times as expensive as rawether, last time we checked.
>
> If you have much spare time and a MSDN subscription (1K per annual) you can
> take a sample NDIS from Windows DDK and use it as a starting point.
>
I think you got the wrong information. Winpcap is free:
http://www.winpcap.org/misc/copyright.htm

And its developer's pack (SDK) is freely available:

http://www.winpcap.org/devel.htm


^ permalink raw reply	[relevance 6%]

* Re: Questions about Gnat.sockets and raw socket
  2015-04-23 15:41  6%     ` loïc maury
@ 2015-04-23 16:14  6%       ` Dmitry A. Kazakov
  2015-04-23 17:32  6%         ` Qun-Ying
  0 siblings, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2015-04-23 16:14 UTC (permalink / raw)


On Thu, 23 Apr 2015 08:41:50 -0700 (PDT), loïc maury wrote:

> Le jeudi 23 avril 2015 14:52:45 UTC+2, loïc maury a écrit :
>> Le jeudi 23 avril 2015 14:19:04 UTC+2, Dmitry A. Kazakov a écrit :
>>> On Thu, 23 Apr 2015 02:21:00 -0700 (PDT), loďc maury wrote:
>>> 
>>> > For a personal project, I want to create a packet analyzer.
>>> > Can I use Gnat.socket, for raw socket programming ? it is not clear
>>> > for me, and unfortunately I didn't found any answers in the ada groups.
>>> > 
>>> > I will use it under Windows.
>>> 
>>> The short answer is no, it would not go.
>>> 
>>> Windows does not support raw sockets (naturally GNAT.Sockets does not do
>>> either). Under Windows you will need a so-called NDIS driver to handle
>>> packets away of the network stack, and Ada bindings to.
>>> 
>>> I can recommend an inexpensive NDIS driver we are successfully using under
>>> Windows:
>>> 
>>>    http://www.rawether.net
>>> 
>>> We also have Windows bindings to it, but they are proprietary.
>>> 
>>> P.S. Under Linux you would use raw sockets. GNAT.Sockets does not support
>>> them, but it is relatively simple to adapt.
>>> 
>> Maybe NDIS open source project exist, I will try to find one.
>> 
> Maybe I found a solution, with Winpcap, I can create a binding for this
> library.

Winpcap is not free, only its run-time is. But you will also need the SDK,
which is five times as expensive as rawether, last time we checked.

If you have much spare time and a MSDN subscription (1K per annual) you can
take a sample NDIS from Windows DDK and use it as a starting point. 

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 6%]

* Re: Questions about Gnat.sockets and raw socket
  2015-04-23 12:52  6%   ` loïc maury
@ 2015-04-23 15:41  6%     ` loïc maury
  2015-04-23 16:14  6%       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 200+ results
From: loïc maury @ 2015-04-23 15:41 UTC (permalink / raw)


Le jeudi 23 avril 2015 14:52:45 UTC+2, loïc maury a écrit :
> Le jeudi 23 avril 2015 14:19:04 UTC+2, Dmitry A. Kazakov a écrit :
> > On Thu, 23 Apr 2015 02:21:00 -0700 (PDT), loďc maury wrote:
> > 
> > > For a personal project, I want to create a packet analyzer.
> > > Can I use Gnat.socket, for raw socket programming ? it is not clear
> > > for me, and unfortunately I didn't found any answers in the ada groups.
> > > 
> > > I will use it under Windows.
> > 
> > The short answer is no, it would not go.
> > 
> > Windows does not support raw sockets (naturally GNAT.Sockets does not do
> > either). Under Windows you will need a so-called NDIS driver to handle
> > packets away of the network stack, and Ada bindings to.
> > 
> > I can recommend an inexpensive NDIS driver we are successfully using under
> > Windows:
> > 
> >    http://www.rawether.net
> > 
> > We also have Windows bindings to it, but they are proprietary.
> > 
> > P.S. Under Linux you would use raw sockets. GNAT.Sockets does not support
> > them, but it is relatively simple to adapt.
> > 
> > -- 
> > Regards,
> > Dmitry A. Kazakov
> > http://www.dmitry-kazakov.de
> 
> Hello Dmitry,
> 
> Thank you for the quick answer.
> 
> Maybe NDIS open source project exist, I will try to find one.
> 
> Best
> 
> Loic

Maybe I found a solution, with Winpcap, I can create a binding for this
library.

^ permalink raw reply	[relevance 6%]

* Re: Questions about Gnat.sockets and raw socket
  2015-04-23 12:19 13% ` Dmitry A. Kazakov
@ 2015-04-23 12:52  6%   ` loïc maury
  2015-04-23 15:41  6%     ` loïc maury
  0 siblings, 1 reply; 200+ results
From: loïc maury @ 2015-04-23 12:52 UTC (permalink / raw)


Le jeudi 23 avril 2015 14:19:04 UTC+2, Dmitry A. Kazakov a écrit :
> On Thu, 23 Apr 2015 02:21:00 -0700 (PDT), loďc maury wrote:
> 
> > For a personal project, I want to create a packet analyzer.
> > Can I use Gnat.socket, for raw socket programming ? it is not clear
> > for me, and unfortunately I didn't found any answers in the ada groups.
> > 
> > I will use it under Windows.
> 
> The short answer is no, it would not go.
> 
> Windows does not support raw sockets (naturally GNAT.Sockets does not do
> either). Under Windows you will need a so-called NDIS driver to handle
> packets away of the network stack, and Ada bindings to.
> 
> I can recommend an inexpensive NDIS driver we are successfully using under
> Windows:
> 
>    http://www.rawether.net
> 
> We also have Windows bindings to it, but they are proprietary.
> 
> P.S. Under Linux you would use raw sockets. GNAT.Sockets does not support
> them, but it is relatively simple to adapt.
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Hello Dmitry,

Thank you for the quick answer.

Maybe NDIS open source project exist, I will try to find one.

Best

Loic

^ permalink raw reply	[relevance 6%]

* Re: Questions about Gnat.sockets and raw socket
  2015-04-23  9:21  6% Questions about Gnat.sockets and raw socket loïc maury
@ 2015-04-23 12:19 13% ` Dmitry A. Kazakov
  2015-04-23 12:52  6%   ` loïc maury
  2015-04-28 10:21  6% ` loïc maury
  1 sibling, 1 reply; 200+ results
From: Dmitry A. Kazakov @ 2015-04-23 12:19 UTC (permalink / raw)


On Thu, 23 Apr 2015 02:21:00 -0700 (PDT), loïc maury wrote:

> For a personal project, I want to create a packet analyzer.
> Can I use Gnat.socket, for raw socket programming ? it is not clear
> for me, and unfortunately I didn't found any answers in the ada groups.
> 
> I will use it under Windows.

The short answer is no, it would not go.

Windows does not support raw sockets (naturally GNAT.Sockets does not do
either). Under Windows you will need a so-called NDIS driver to handle
packets away of the network stack, and Ada bindings to.

I can recommend an inexpensive NDIS driver we are successfully using under
Windows:

   http://www.rawether.net

We also have Windows bindings to it, but they are proprietary.

P.S. Under Linux you would use raw sockets. GNAT.Sockets does not support
them, but it is relatively simple to adapt.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 13%]

* Questions about Gnat.sockets and raw socket
@ 2015-04-23  9:21  6% loïc maury
  2015-04-23 12:19 13% ` Dmitry A. Kazakov
  2015-04-28 10:21  6% ` loïc maury
  0 siblings, 2 replies; 200+ results
From: loïc maury @ 2015-04-23  9:21 UTC (permalink / raw)



Hello,

For a personal project, I want to create  a packet analyzer.

Can I use Gnat.socket, for raw socket programming ? it is not clear

for me, and unfortunately I didn't found any answers in the ada groups.

I will use it under Windows.

Thank you

Best

Loic


^ permalink raw reply	[relevance 6%]

* ANN: Simple Components for Ada v4.5 released
@ 2015-01-17 20:04  4% Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2015-01-17 20:04 UTC (permalink / raw)


The library provides implementations of smart pointers, directed graphs,
sets, maps, B-trees, stacks, tables, string editing, unbounded arrays,
expression analyzers, lock-free data structures, synchronization primitives
(events, race condition free pulse events, arrays of events, reentrant
mutexes, deadlock-free arrays of mutexes), pseudo-random non-repeating
numbers, symmetric encoding and decoding, IEEE 754 representations support,
multiple connections server designing tools.

   http://www.dmitry-kazakov.de/ada/components.htm

The new version provides bindings to GNUTLS and an implementation of
SSL/TLS servers, HTTP included.

Changes to the previous version:

- Dynamically allocated terminated strings added in the package
GNAT.Sockets.Connection_State_Machine.Terminated_Strings;
- Input buffer size discriminant added to HTTP_Client connection object;
- Tracing primitive operation extended for encoded/ciphered content;
- GNUTLS bindings added;
- Secure SSL/TLS multiple-connections servers added. The implementation is
based on GNUTLS;
- Secure HTTP implementation added.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 4%]

* Re: Questions about socket programming
      2014-12-24 17:02  7% ` Dmitry A. Kazakov
@ 2015-01-15 13:41  7% ` Kevin K
  2 siblings, 0 replies; 200+ results
From: Kevin K @ 2015-01-15 13:41 UTC (permalink / raw)


I've used Gnat.Sockets when the project I was working on started to support Windows in addition to Linux.

It reduced the number of unique files that were required between the 2 systems.

The main issues we encountered were issues with the Gnat Sockets select call.  GNAT uses a hidden socket in the background to enable termination of the select, and there was some interaction with our code that caused exceptions sporadically.  Never able to reproduce it in a small test case. I ended up writing a companion package that would use the OS calls for the select, with no issues. It has been several years, so it may be fixed now.

The other, as mentioned, were raw sockets.  Due to project requirements, we needed to be able to specify several IP header fields exactly, and the TOS capability isn't supported on modern Windows.

^ permalink raw reply	[relevance 7%]

* Re: ANN: Gnoga v1.0 - The GNU Omnificent GUI for Ada
  2014-12-30  3:03  2% ANN: Gnoga v1.0 - The GNU Omnificent GUI for Ada David Botton
@ 2014-12-30  4:34  0% ` Anh Vo
  0 siblings, 0 replies; 200+ results
From: Anh Vo @ 2014-12-30  4:34 UTC (permalink / raw)


On Monday, December 29, 2014 7:03:51 PM UTC-8, David Botton wrote:
> Introduction
> ----------------
> http://gnoga.com
> 
> Gnoga is an open source development platform for the creation of mission critical and enterprise applications that can be deployed to the cloud, desktop or mobile devices.
> 
> Gnoga applications are written using the open source Gnoga framework licensed under the GPLv3 with Runtime Exceptions for creating free or proprietary software and Ada 2012, the time-tested, safe and secure programming language used for long-lived critical application development.
> 
> This releases contains the Gnoga 1.0 Framework, future releases will include additional platform tools including a full IDE and visual development environment.
> 
> Ada compilers are available for most platforms - see http://GetAdaNow.com
> 
> For more information http://gnoga.com
> 
> Download Gnoga 1.0 at http://gnoga.com/gnoga.1.0.zip  or clone the latest at:
>       git clone git://git.code.sf.net/p/gnoga/code gnoga
> 
> The Gnoga user guide is available at - http://www.gnoga.com/user_guide.html
> 
> Join the Gnoga E-Mail Support List - https://lists.sourceforge.net/lists/listinfo/gnoga-list
> 
> Gnoga Features
> ----------------------
> 
> * Realtime live server push web-app technology for the web
> * Native Gtk Front end for the desktop
> * Native Mac OS X desktop applications that can be submitted to the App Store
> * Write complex web-apps or desktop apps with no HTML or JS
> * The same code base can deploy as a web-app, desktop or mobile app
> * Server side and client side development is in same code base and all in Ada
> * Gnoga applications are clear and easy to read and write
> * Extensive concurrency support
> * Integrates easily with C/C++, Python or any other server side language or library
> * Bind any JavaScript based client libraries to take advantage of existing UI developments
> 
> Gnoga Platforms
> ----------------------
> 
> * GNU/Linux
> * Apple Macintosh OS X
> * Microsoft Windows
> * Raspberry Pi
> * And any other gcc/ada platform supporting GNAT.Sockets
> 
> Gnoga Framework Overview
> --------------------------------------
> 
> 1. The communication platform between the Ada code and the browser / native
>       Gnoga.Server.Connection
> 
> 2. Binding to the HTML5 DOM and Browser
>       Gnoga.Gui.Base (Not per se a binding of Node but takes its place)
>       Gnoga.Gui.Element, Gnoga.Gui.Element.* (HTML Elements)
>       Gnoga.Gui.Element.Canvas - HTML 5 Canvas bindings
>       Gnoga.Gui.Element.SVG - HTML SVG vector graphics
>       Gnoga.Gui.Element.Multimedia - HTML 5 Audio and Video
>       Gnoga.Gui.Element.Style - CSS Style blocks
>       Gnoga.Gui.Window, Gnoga.Gui.Navigator, Gnoga.Gui.Screen,
>       Gnoga.Gui.Location
>       Gnoga.Gui.Document
> 
> 3. Application start up services
>       Gnoga.Server.Application.Singleton - Desktop apps
>       Gnoga.Server.Application.Multi_Connect - Multi user / Web apps
> 
> 4. Gnoga higher level containers and GUI widgets
>       Gnoga.Gui.Views.* - Auto layout of child elements and basis for
>                           custom Gnoga Ada only widgets
>       Gnoga.Gui.Views.Docker - Dock child views to view sides
>       Gnoga.Gui.Views.Card - Stacks of views
> 
> 5. Gnoga client side application APIs
>       Gnoga.Client.Storage - local persistent and session storage on browser
>       Gnoga.Client.Bind_Page - Bind to all elements on pre-made HTML5 pages
> 
> 6. Gnoga database bindings and server side APIs
>       Gnoga.Server.Database - support for MySQL and SQLite 3
>            (for ODBC bindings see deps/simple_components)
>       Gnoga.Server.Model - Active Data models like in Rails
>       Gnoga.Server.Migrations - Rails like database schema migrations
>       Gnoga.Server.Template_Parser - Parse files with tokens or Python 2.7
> 
> 7. Gnoga development tools
>       tool/gnoga_make - Generate application scaffolds
> 
> 8. Plugin bindings to existing JavaScript libraries
>       Gnoga.Gui.Plugin.Ace_Editor - Full editor with Ada syntax highlighting
>       Gnoga.Gui.Plugin.Bootstrap - The Bootsrap framework
>       Gnoga.Gui.Plugin.jQuery - jQuery support to access non-Gnoga Elements
>       Gnoga.Gui.Plugin.jQueryUI - all the jQueryUI Interactions and Effects
>       Gnoga.Gui.Plugin.jQueryUI.Widgets - the jQueryUI Widgets
> 
> 9. Native Desktop and Mobile Application Support coming:
>       Gnoga.Server.Application.Gtk_Window - Native GTK front end
>       Gnoga.Gui.Plugin.MacGap - Native Mac OSX features

It is a fantastic accomplishment in a very short period of time. It is worth to say congratulations and thank you for your terrific efforts again. 

Anh Vo

^ permalink raw reply	[relevance 0%]

* ANN: Gnoga v1.0 - The GNU Omnificent GUI for Ada
@ 2014-12-30  3:03  2% David Botton
  2014-12-30  4:34  0% ` Anh Vo
  0 siblings, 1 reply; 200+ results
From: David Botton @ 2014-12-30  3:03 UTC (permalink / raw)


Introduction
----------------
http://gnoga.com

Gnoga is an open source development platform for the creation of mission critical and enterprise applications that can be deployed to the cloud, desktop or mobile devices.

Gnoga applications are written using the open source Gnoga framework licensed under the GPLv3 with Runtime Exceptions for creating free or proprietary software and Ada 2012, the time-tested, safe and secure programming language used for long-lived critical application development.

This releases contains the Gnoga 1.0 Framework, future releases will include additional platform tools including a full IDE and visual development environment.

Ada compilers are available for most platforms - see http://GetAdaNow.com

For more information http://gnoga.com

Download Gnoga 1.0 at http://gnoga.com/gnoga.1.0.zip  or clone the latest at:
      git clone git://git.code.sf.net/p/gnoga/code gnoga

The Gnoga user guide is available at - http://www.gnoga.com/user_guide.html

Join the Gnoga E-Mail Support List - https://lists.sourceforge.net/lists/listinfo/gnoga-list

Gnoga Features
----------------------

* Realtime live server push web-app technology for the web
* Native Gtk Front end for the desktop
* Native Mac OS X desktop applications that can be submitted to the App Store
* Write complex web-apps or desktop apps with no HTML or JS
* The same code base can deploy as a web-app, desktop or mobile app
* Server side and client side development is in same code base and all in Ada
* Gnoga applications are clear and easy to read and write
* Extensive concurrency support
* Integrates easily with C/C++, Python or any other server side language or library
* Bind any JavaScript based client libraries to take advantage of existing UI developments

Gnoga Platforms
----------------------

* GNU/Linux
* Apple Macintosh OS X
* Microsoft Windows
* Raspberry Pi
* And any other gcc/ada platform supporting GNAT.Sockets

Gnoga Framework Overview
--------------------------------------

1. The communication platform between the Ada code and the browser / native
      Gnoga.Server.Connection

2. Binding to the HTML5 DOM and Browser
      Gnoga.Gui.Base (Not per se a binding of Node but takes its place)
      Gnoga.Gui.Element, Gnoga.Gui.Element.* (HTML Elements)
      Gnoga.Gui.Element.Canvas - HTML 5 Canvas bindings
      Gnoga.Gui.Element.SVG - HTML SVG vector graphics
      Gnoga.Gui.Element.Multimedia - HTML 5 Audio and Video
      Gnoga.Gui.Element.Style - CSS Style blocks
      Gnoga.Gui.Window, Gnoga.Gui.Navigator, Gnoga.Gui.Screen,
      Gnoga.Gui.Location
      Gnoga.Gui.Document

3. Application start up services
      Gnoga.Server.Application.Singleton - Desktop apps
      Gnoga.Server.Application.Multi_Connect - Multi user / Web apps

4. Gnoga higher level containers and GUI widgets
      Gnoga.Gui.Views.* - Auto layout of child elements and basis for
                          custom Gnoga Ada only widgets
      Gnoga.Gui.Views.Docker - Dock child views to view sides
      Gnoga.Gui.Views.Card - Stacks of views

5. Gnoga client side application APIs
      Gnoga.Client.Storage - local persistent and session storage on browser
      Gnoga.Client.Bind_Page - Bind to all elements on pre-made HTML5 pages

6. Gnoga database bindings and server side APIs
      Gnoga.Server.Database - support for MySQL and SQLite 3
           (for ODBC bindings see deps/simple_components)
      Gnoga.Server.Model - Active Data models like in Rails
      Gnoga.Server.Migrations - Rails like database schema migrations
      Gnoga.Server.Template_Parser - Parse files with tokens or Python 2.7

7. Gnoga development tools
      tool/gnoga_make - Generate application scaffolds

8. Plugin bindings to existing JavaScript libraries
      Gnoga.Gui.Plugin.Ace_Editor - Full editor with Ada syntax highlighting
      Gnoga.Gui.Plugin.Bootstrap - The Bootsrap framework
      Gnoga.Gui.Plugin.jQuery - jQuery support to access non-Gnoga Elements
      Gnoga.Gui.Plugin.jQueryUI - all the jQueryUI Interactions and Effects
      Gnoga.Gui.Plugin.jQueryUI.Widgets - the jQueryUI Widgets

9. Native Desktop and Mobile Application Support coming:
      Gnoga.Server.Application.Gtk_Window - Native GTK front end
      Gnoga.Gui.Plugin.MacGap - Native Mac OSX features


^ permalink raw reply	[relevance 2%]

* Re: Questions about socket programming
    2014-12-27  9:48  7%     ` Dmitry A. Kazakov
@ 2014-12-28  0:44  5%     ` David Botton
  1 sibling, 0 replies; 200+ results
From: David Botton @ 2014-12-28  0:44 UTC (permalink / raw)



> *My* complaint is simply that you end up with GNAT lock-in whenever you 
> depend on GNAT-specific packages.

Copy, paste, rename. If AdaCore could redo history based on current policies I'm sure that GNAT.Sockets would have been part of GNATCOLL anyways.

David Botton

^ permalink raw reply	[relevance 5%]

* Re: Questions about socket programming
  @ 2014-12-27  9:48  7%     ` Dmitry A. Kazakov
  2014-12-28  0:44  5%     ` David Botton
  1 sibling, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2014-12-27  9:48 UTC (permalink / raw)


On Fri, 26 Dec 2014 19:21:48 -0600, Randy Brukardt wrote:

> Ada is powerful enough that such lock-in 
> shouldn't be necessary.

It isn't. There is no way to implement sockets in Ada without doing system
calls.

Obviously sockets should be included into the standard library. Even
considering embedded targets, socket I/O is probably more relevant there
than text I/O, which is a part of the library.

GNAT sockets could be a good reference point. The only important (for
embedded applications) part missing is raw sockets.

> So it's better to use a package that is more 
> portable, like Claw.Sockets (if you're already locked into Windows) or 
> Adasockets or (coming soon) NC_Sockets.

Actually GNAT sockets are more portable than AdaSockets, as they work on a
wider set of targets (e.g. VxWorks). You mean compiler independence.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 7%]

* Re: Questions about socket programming
    @ 2014-12-24 17:02  7% ` Dmitry A. Kazakov
  2015-01-15 13:41  7% ` Kevin K
  2 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2014-12-24 17:02 UTC (permalink / raw)


On Wed, 24 Dec 2014 05:43:21 -0800, Hubert wrote:

> I want to write a small telnet server as an exercise and also because I 
> need this functionality elsewhere. I seem to remember that I read in 
> this newsgroup somewhere some negative opinions about Gnatsockets, but I 
> can't remember where and what it was about.

I am using GNAT.Sockets extensively, there is no problems so far.

> So I wonder, should I use Gnatsocket or are there any problems? Should I 
> rather interface with C and use the C socket implementation directly? I 
> must admit that I tried this today and didn't get very far, because I 
> got linker errors like these:
> 
> Berkley_Socket_Interface_C.c:47: undefined reference to 
> `_imp__getaddrinfo@16'
> Berkley_Socket_Interface_C.c:48: undefined reference to `gai_strerrorA'
> Berkley_Socket_Interface_C.c:49: undefined reference to `_imp__WSACleanup@0'
> 
> collect2.exe: error: ld returned 1 exit status
> 
> and I am out of ideas there. I tried to add to the C linker the 
> following switches:
> 
> -lwsock32 -lws2_32

Windows sockets are not Berkeley sockets and conversely. Which is one
reason to use GNAT.Sockets instead.

> but without luck. I found contradictory information what the correct 
> library name is for mingw, so I tried both but apparantly both are 
> wrong, or the respective libraries are not delivered with Adacore Libre.

There are WinSock versions 1 and 2. See

   http://en.wikipedia.org/wiki/Winsock

> I should had that I don't have Mingw installed, just what comes with 
> Adacore.

You can implement Telnet server on top of this:

http://www.dmitry-kazakov.de/ada/components.htm#multiple_GNAT.Sockets.Servers

or this:

http://www.dmitry-kazakov.de/ada/components.htm#GNAT.Sockets.Connection_State_Machine

The first handles socket communication for you, the second parses incoming
packets as well.

Merry Christmas,

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 7%]

* Re: What exactly is the licensing situation with GNAT?
  2014-11-18  0:28  0%                                           ` Randy Brukardt
@ 2014-11-18  9:20  0%                                             ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2014-11-18  9:20 UTC (permalink / raw)


On Mon, 17 Nov 2014 18:28:42 -0600, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
> news:1se4bvo6gaqft.16cfjaiketlz0$.dlg@40tude.net...
>> On Fri, 14 Nov 2014 16:29:59 -0600, Randy Brukardt wrote:
>>
>>> I've been using Claw.Sockets for so long that I don't know what the
>>> underlying implementation is. So I don't know what "select" is used for 
>>> or
>>> whether it's implemented in NC_Sockets. Claw.Sockets has a server type
>>> that's used for implemented servers (like web and mail servers).
>>
>> Select() is essential for heavy duty and light weight servers as it allows
>> one task to handle multiple sockets without blocking. AdaSockets, the only
>> alternative to GNAT.Sockets I know, does not support select.
>>
>> (I don't know if AWS uses blocking sockets for its server or 
>> socket-select)
> 
> Incoming or outgoing?

Both and connect, disconnect as well.

> Since Janus/Ada only uses one thread per Ada program, 
> no server would work at all if everything was blocking. I know the server 
> type works well distributing accesses to different Ada tasks (even on 
> Janus/Ada, where everything is done by one thread).
> 
> OTOH, we implemented non-blocking sockets for outbound traffic in Claw 
> sockets as well. I implemented a version of the web server using those 
> sockets, and it turned out the performance (at least on Windows 2K/XP) was 
> something like 10 times slower using non-blocking sockets compared to 
> busy-waiting the blocking sockets.

Depends on how you measured it. Latencies may increase for obvious reason
of context switching. The rest should have no influence.

> Apparently, Windows launches threads for 
> the non-blocking socket operations, which is SLOW.

No, that cannot be. We are using non-blocking sockets massively e.g. tens
of thousands, needed to fiddle system settings to allow so many. It
certainly does not start threads because Windows cannot have so many.

> I made the busy-waiting 
> much smarter in the web server (using a increasing wait for each iteration) 
> and got much better overall performance than either alternative.

Did you use this:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms741576%28v=vs.85%29.aspx

This a simpler alternative with more control over the policies as compared
to the traditional select:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms740141%28v=vs.85%29.aspx

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[relevance 0%]

* Re: What exactly is the licensing situation with GNAT?
    2014-11-15 11:18  0%                                           ` Tero Koskinen
@ 2014-11-18  0:28  0%                                           ` Randy Brukardt
  2014-11-18  9:20  0%                                             ` Dmitry A. Kazakov
  1 sibling, 1 reply; 200+ results
From: Randy Brukardt @ 2014-11-18  0:28 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:1se4bvo6gaqft.16cfjaiketlz0$.dlg@40tude.net...
> On Fri, 14 Nov 2014 16:29:59 -0600, Randy Brukardt wrote:
>
>> I've been using Claw.Sockets for so long that I don't know what the
>> underlying implementation is. So I don't know what "select" is used for 
>> or
>> whether it's implemented in NC_Sockets. Claw.Sockets has a server type
>> that's used for implemented servers (like web and mail servers).
>
> Select() is essential for heavy duty and light weight servers as it allows
> one task to handle multiple sockets without blocking. AdaSockets, the only
> alternative to GNAT.Sockets I know, does not support select.
>
> (I don't know if AWS uses blocking sockets for its server or 
> socket-select)

Incoming or outgoing? Since Janus/Ada only uses one thread per Ada program, 
no server would work at all if everything was blocking. I know the server 
type works well distributing accesses to different Ada tasks (even on 
Janus/Ada, where everything is done by one thread).

OTOH, we implemented non-blocking sockets for outbound traffic in Claw 
sockets as well. I implemented a version of the web server using those 
sockets, and it turned out the performance (at least on Windows 2K/XP) was 
something like 10 times slower using non-blocking sockets compared to 
busy-waiting the blocking sockets. Apparently, Windows launches threads for 
the non-blocking socket operations, which is SLOW. I made the busy-waiting 
much smarter in the web server (using a increasing wait for each iteration) 
and got much better overall performance than either alternative.

                                                   Randy.






^ permalink raw reply	[relevance 0%]

* Re: What exactly is the licensing situation with GNAT?
  2014-11-15 11:18  0%                                           ` Tero Koskinen
@ 2014-11-15 11:36  6%                                             ` Dmitry A. Kazakov
  0 siblings, 0 replies; 200+ results
From: Dmitry A. Kazakov @ 2014-11-15 11:36 UTC (permalink / raw)


On Sat, 15 Nov 2014 13:18:02 +0200, Tero Koskinen wrote:

> C API for select() is not pretty and you need to be very careful when
> using it to avoid FD_SET overflows, for example.

All socket API is awful stuff.
 
> Many prefer to use poll() instead of select(), since API for poll() is
> much cleaner.
> 
> It is also a nightmare to create Ada bindings to select().

The approach should be similar to GNAT.Sockets, e.g. a medium- or
higher-level socket API with all nasty and OS-dependent details hidden.
GNAT.Sockets is medium level. Ideally, it could be a bit higher, e.g. have
a protected object waitable for a socket event.

> They are of course tied to specific systems, but people have
> created "wrapper" libraries like libevent[1], which allow one
> to choose their favorite polling mechanism and use same API
> on all systems.

Yes, that's the right way to do it.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 6%]

* Re: What exactly is the licensing situation with GNAT?
  @ 2014-11-15 11:18  0%                                           ` Tero Koskinen
  2014-11-15 11:36  6%                                             ` Dmitry A. Kazakov
  2014-11-18  0:28  0%                                           ` Randy Brukardt
  1 sibling, 1 reply; 200+ results
From: Tero Koskinen @ 2014-11-15 11:18 UTC (permalink / raw)


15.11.2014 11:29, Dmitry A. Kazakov wrote:
> On Fri, 14 Nov 2014 16:29:59 -0600, Randy Brukardt wrote:
> 
>> I've been using Claw.Sockets for so long that I don't know what the 
>> underlying implementation is. So I don't know what "select" is used for or 
>> whether it's implemented in NC_Sockets. Claw.Sockets has a server type 
>> that's used for implemented servers (like web and mail servers).

(Not_)Claw_Sockets does not provide select at API level. However, it
uses select() internally.

-- Taken from my Linux port
package NC.Sockets is
   ...
private
   ...
   function Select_function(Ignored           : Claw.Int;
                             Read_FD_Set       : access FD_SET_Type;
                             Write_FD_Set      : access FD_SET_Type;
                             Exceptions_FD_Set : access FD_SET_Type;
                             Timeout           : access Timeval_Type)
             return Claw.Int;
    pragma Import(C, Select_function, "select_wrapper");
end NC.Sockets;

> Select() is essential for heavy duty and light weight servers as it allows
> one task to handle multiple sockets without blocking. AdaSockets, the only
> alternative to GNAT.Sockets I know, does not support select.

C API for select() is not pretty and you need to be very careful when
using it to avoid FD_SET overflows, for example.

Many prefer to use poll() instead of select(), since API for poll() is
much cleaner.

It is also a nightmare to create Ada bindings to select(). I ended up
using a wrapper C function when creating Linux port of NC.Sockets:
https://bitbucket.org/tkoskine/not-claw-sockets-linux-x86/src/4bc1528f59f910d4ea596d6aa63936b313b293bf/select_wrapper.c?at=default

Operating system specific kqueue/epoll APIs are also popular, since
they offer some performance advantages over select/poll.

They are of course tied to specific systems, but people have
created "wrapper" libraries like libevent[1], which allow one
to choose their favorite polling mechanism and use same API
on all systems.

Yours,
 Tero

[1] http://libevent.org/


^ permalink raw reply	[relevance 0%]

Results 1-200 of ~800   | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2014-11-10  9:30     What exactly is the licensing situation with Gnat? Hubert
2014-11-11 13:37     ` What exactly is the licensing situation with GNAT? john
2014-11-11 22:52       ` Hubert
2014-11-11 23:10         ` David Botton
2014-11-11 23:25           ` Alan Jump
2014-11-12  0:50             ` David Botton
2014-11-12  1:15               ` Hubert
2014-11-12  1:24                 ` David Botton
2014-11-12  8:12                   ` Simon Wright
2014-11-12  8:35                     ` Hubert
2014-11-12  9:25                       ` Mark Carroll
2014-11-12  9:37                         ` Hubert
2014-11-12 10:31                           ` jm.tarrasa
2014-11-12 10:44                             ` Hubert
2014-11-12 22:53                               ` Randy Brukardt
2014-11-12 23:21                                 ` David Botton
2014-11-14  4:51                                   ` Randy Brukardt
2014-11-14  5:12                                     ` David Botton
2014-11-14  6:13                                       ` Randy Brukardt
2014-11-14  8:40                                         ` Dmitry A. Kazakov
2014-11-14 22:29                                           ` Randy Brukardt
2014-11-15  9:29                                             ` Dmitry A. Kazakov
2014-11-15 11:18  0%                                           ` Tero Koskinen
2014-11-15 11:36  6%                                             ` Dmitry A. Kazakov
2014-11-18  0:28  0%                                           ` Randy Brukardt
2014-11-18  9:20  0%                                             ` Dmitry A. Kazakov
2014-12-24 13:43     Questions about socket programming Hubert
2014-12-24 14:22     ` David Botton
2014-12-27  1:21       ` Randy Brukardt
2014-12-27  9:48  7%     ` Dmitry A. Kazakov
2014-12-28  0:44  5%     ` David Botton
2014-12-24 17:02  7% ` Dmitry A. Kazakov
2015-01-15 13:41  7% ` Kevin K
2014-12-30  3:03  2% ANN: Gnoga v1.0 - The GNU Omnificent GUI for Ada David Botton
2014-12-30  4:34  0% ` Anh Vo
2015-01-17 20:04  4% ANN: Simple Components for Ada v4.5 released Dmitry A. Kazakov
2015-04-23  9:21  6% Questions about Gnat.sockets and raw socket loïc maury
2015-04-23 12:19 13% ` Dmitry A. Kazakov
2015-04-23 12:52  6%   ` loïc maury
2015-04-23 15:41  6%     ` loïc maury
2015-04-23 16:14  6%       ` Dmitry A. Kazakov
2015-04-23 17:32  6%         ` Qun-Ying
2015-04-28 10:21  6% ` loïc maury
2015-04-30 11:22     ANN: GCC 5.1.0 for Mac OS X Simon Wright
2015-04-30 12:23  5% ` Simon Wright
2015-08-02  3:04  5% Gnoga on Windows 10 David Botton
2015-11-26  7:56  8% Using Gnat.Sockets in a Windows DLL ahlan
2015-11-26  8:39  6% ` Dmitry A. Kazakov
2015-12-08  7:43 11% ` ahlan
2015-12-08  9:52  5%   ` Dmitry A. Kazakov
2015-12-09  7:20  5% ` ahlan
2015-12-09  9:20 11%   ` Dmitry A. Kazakov
2015-12-09 12:02  6% ` ahlan
2015-12-09 12:33 11%   ` Dmitry A. Kazakov
2015-12-09 15:06 12% ` ahlan
2015-12-09 15:58 13%   ` Dmitry A. Kazakov
2015-12-09 19:11  6%   ` Simon Wright
2015-12-11 17:53 12% ` ahlan
2015-12-12 12:47  6%   ` Simon Wright
2015-12-12 19:44  6%     ` ahlan
2015-12-12 20:38  6%       ` Simon Wright
2015-12-24 14:46  9% ` ahlan
2015-12-25 11:09  5%   ` Simon Wright
2016-01-13 20:25  5% ` ahlan.marriott
2016-04-20 17:10  5%   ` Dmitry A. Kazakov
2016-04-23  9:24  6%     ` ahlan.marriott
2016-04-21 12:59  5% Building an encapsulated library that uses GNAT sockets under Windows Dmitry A. Kazakov
2016-04-22  7:58 11% ` ahlan.marriott
2016-04-22  8:23  6%   ` Dmitry A. Kazakov
2016-04-23  9:20  6%     ` Ahlan
2016-04-23  9:48  5%       ` Dmitry A. Kazakov
2016-04-23 14:45 10%         ` ahlan.marriott
2016-04-23 19:56  6%           ` Dmitry A. Kazakov
2016-04-23 21:16  5%             ` Simon Wright
2016-04-24  8:13  6%               ` ahlan
2016-04-24  8:31  6%                 ` Simon Wright
2016-04-26 19:43  5%                   ` ahlan.marriott
2016-04-26 20:24  6%                     ` Simon Wright
2016-04-26 22:32  6%                     ` Jeffrey R. Carter
2016-04-27 22:16  5%                     ` Randy Brukardt
2016-04-27 23:43  5%                       ` Jeffrey R. Carter
2016-04-28  5:18  6%                         ` J-P. Rosen
2016-04-28  5:59  4%                           ` Jeffrey R. Carter
2016-05-09 22:32  5%                             ` David Thompson
2016-04-28 20:23  4%                         ` Randy Brukardt
2016-04-28 21:47  5%                           ` Jeffrey R. Carter
2016-04-28  5:13  6%                       ` J-P. Rosen
2016-04-26 20:20  6%               ` Dmitry A. Kazakov
2016-04-26 21:23  4%                 ` Simon Wright
2016-04-27  6:53  6%                   ` Simon Wright
2016-04-27  7:25  5%                     ` ahlan
2016-04-27  8:27  5%                   ` Dmitry A. Kazakov
2016-04-27  9:59  6%                     ` Simon Wright
2016-04-24 16:31  4% Broadcasting UDP ahlan.marriott
2016-04-24 17:22  0% ` Dmitry A. Kazakov
2016-04-25 14:18  0%   ` ahlan
2016-08-11 14:39  4% A few questions on parsing, sockets, UTF-8 strings john
2016-08-11 16:23  0% ` Dmitry A. Kazakov
2016-09-01 15:43  3% Rendezvous with select ... else and "or terminate" not possible - but how do I quit this task? Some Dude
2016-09-01 16:05  4% ` J-P. Rosen
2016-09-01 16:10  0% ` Dmitry A. Kazakov
2016-09-13  8:46     Question on bounded / unbounded strings Arie van Wingerden
2016-09-13  9:04     ` Dmitry A. Kazakov
2016-09-22  2:10       ` John Smith
2016-09-22  7:24         ` Dmitry A. Kazakov
2016-09-23 23:58           ` John Smith
2016-09-24  7:52             ` Dmitry A. Kazakov
2016-09-24 16:25               ` John Smith
2016-09-24 17:44  3%             ` Dmitry A. Kazakov
2016-09-24 18:37  0%               ` John Smith
2016-09-24 18:59  0%               ` John Smith
2016-09-14 12:51     is type String from Ada Binary-Safe ? Daniel Norte Moraes
2016-09-14 13:12  5% ` Dmitry A. Kazakov
2016-09-15 13:21  5% ` Daniel Norte Moraes
2016-09-16 20:58 11% IPv6 + UDP alternative to Gnat.Sockets ? Daniel Norte Moraes
2016-09-17 14:12  6% ` Per Sandberg
2016-09-17 18:08  6% ` Daniel Norte Moraes
2016-09-18 20:33 12%   ` Stephen Leake
2016-09-18 21:56 13% ` Daniel Norte Moraes
2016-09-19 17:04  6% ` jrmarino
2016-09-19 22:36  6% ` Daniel Norte Moraes
2016-09-20 23:51  6% ` Daniel Norte Moraes
2016-10-12 14:23  9% Gnat Sockets - UDP timeout too short ahlan
2016-11-04  8:48 11% ` ahlan.marriott
2016-10-13 16:54  5% ANN: Simple Components for Ada v 4.16 Dmitry A. Kazakov
2016-11-19 12:06  6% ANN: Simple Components v4.17 released Dmitry A. Kazakov
2017-02-20 17:53  6% ANN: Simple Components for Ada v4.19 Dmitry A. Kazakov
2017-06-02  1:23     Microsoft UWP/WinRt alby.gamper
2017-06-02  7:24     ` Dmitry A. Kazakov
2017-06-02 12:27       ` Lucretia
2017-06-02 13:28  5%     ` Dmitry A. Kazakov
2017-06-02 14:53  0%       ` gautier_niouzes
2017-06-02 14:56  0%         ` Dmitry A. Kazakov
2017-06-02 21:11  0%         ` Randy Brukardt
2017-06-08 10:36 11% GNAT.Sockets Streaming inefficiency masterglob
2017-06-08 14:46  6% ` Dmitry A. Kazakov
2017-06-08 15:39  6% ` Robert Eachus
2017-06-09 13:30  5% ` gautier_niouzes
2017-06-09 15:24  5%   ` Dmitry A. Kazakov
2017-06-19  9:22  6%     ` masterglob
2017-06-28  9:25     send email Distant Worlds
2017-07-18  7:48  4% ` Björn Lundin
2017-07-17 18:30  6% HTTP with Simple Components: Status.Kind always File Felix Krause
2017-07-17 20:59  5% ` Dmitry A. Kazakov
2017-07-19 16:09  0%   ` Felix Krause
2017-07-19 16:33  0%     ` Dmitry A. Kazakov
2017-09-16  6:40     NTP Anatoly Chernyshev
2017-09-16  9:29  5% ` NTP Dmitry A. Kazakov
2017-10-01 13:44  6% ANN: Simple Components for Ada v4.24 Dmitry A. Kazakov
2017-10-21  2:05  4% Finding the end of a stream from a socket Andrew Shvets
2017-10-21  8:44     ` Dmitry A. Kazakov
2017-10-21 13:45  6%   ` Andrew Shvets
2017-10-21 18:11  0%     ` Dennis Lee Bieber
2017-10-21 19:19  0%       ` Dmitry A. Kazakov
2017-10-21 19:46  0%         ` Andrew Shvets
2017-10-22 12:26  0%         ` Andrew Shvets
2017-10-22 12:28  0%           ` Andrew Shvets
2017-10-21 17:34       ` Andrew Shvets
2017-10-21 19:18  6%     ` Andrew Shvets
2017-10-25 17:23  6% alternative for buggy accept_socket to create a non-blocking version Matt Borchers
2017-10-25 19:14  5% ` Matt Borchers
2017-10-26 13:43  0%   ` Shark8
2017-10-27  9:14  5% ` Björn Lundin
2017-10-27 16:26  0% ` Daniel Norte Moraes
2017-11-26 13:00  4% ANN: Simple Components for Ada v4.25 Dmitry A. Kazakov
2017-12-17 15:02     ANN: MAX! home automation v2.0 Dmitry A. Kazakov
2017-12-17 16:10     ` Brian Drummond
2017-12-17 17:30       ` Dmitry A. Kazakov
2017-12-19 13:40         ` Brian Drummond
2017-12-19 14:00  5%       ` Dmitry A. Kazakov
2018-01-19 17:29  6% GNAT implementation of socket sets Dmitry A. Kazakov
2018-01-19 19:10  0% ` Simon Wright
2018-03-25  4:04  9% TCP Server & Client Andrew Shvets
2018-03-25  8:22  4% ` Simon Wright
2018-03-25 19:17  0%   ` Andrew Shvets
2018-06-02 14:34  7% ANN: Simple components for Ada v4.29 Dmitry A. Kazakov
2018-06-30 18:04     Teaching C/C++ from Ada perspective? kouaoua16
2018-07-03 12:40     ` Dan'l Miller
2018-07-03 20:54       ` Maciej Sobczak
2018-07-04  3:10         ` Dan'l Miller
2018-07-04  7:59           ` Maciej Sobczak
2018-07-04  8:37             ` Marius Amado-Alves
2018-07-04 12:22               ` Maciej Sobczak
2018-07-04 14:13                 ` Simon Wright
2018-07-04 14:56                   ` Maciej Sobczak
2018-07-04 15:52                     ` Dmitry A. Kazakov
2018-07-04 20:13                       ` Maciej Sobczak
2018-07-04 21:09                         ` Dmitry A. Kazakov
2018-07-05  5:49                           ` Maciej Sobczak
2018-07-05 18:53                             ` Randy Brukardt
2018-07-05 20:12                               ` Maciej Sobczak
2018-07-06 18:51                                 ` Randy Brukardt
2018-07-06 20:22                                   ` Maciej Sobczak
2018-07-06 23:26                                     ` Paul Rubin
2018-07-07  6:17                                       ` J-P. Rosen
2018-07-07  6:37                                         ` Micronian Coder
2018-07-07  8:48  6%                                       ` Privacy and child packages (Was: Teaching C/C++ from Ada perspective?) Jacob Sparre Andersen
2018-07-03 10:43     UDP Send gets NETWORK_IS_UNREACHABLE Petter Fryklund
2018-07-03 12:16     ` Dmitry A. Kazakov
2018-07-04  9:50  5%   ` Petter Fryklund
2018-07-04 10:23  5%     ` Dmitry A. Kazakov
2018-07-04 11:11           ` Petter Fryklund
2018-07-04 13:07  6%         ` Petter Fryklund
2018-07-04 13:42  0%           ` Dmitry A. Kazakov
2018-07-06  5:31                 ` Petter Fryklund
2018-07-06  7:23                   ` Dmitry A. Kazakov
2018-07-06  8:24  5%                 ` Petter Fryklund
2018-08-05 11:21  4% ANN: Simple components for Ada v 4.30 Dmitry A. Kazakov
2018-08-28  8:04  4% Reusable free code: Simple components - MODBUS.Synchronos.connect not returning Karl Müller
2018-08-28 16:03  0% ` Dmitry A. Kazakov
2018-11-07 17:08  4% ANN: Simple components v4.31 Dmitry A. Kazakov
2018-11-23  6:27 11% GNAT Sockets UDP problem on Windows 10 Petter Fryklund
2018-11-23  8:41  6% ` Petter Fryklund
2018-11-24 17:38  4% Simple components for Ada v4.33 Dmitry A. Kazakov
2019-01-08 11:50  7% ANN: Simple Components for Ada v4.36 Dmitry A. Kazakov
2019-02-06 23:10  8% Ada x <whatever> Datagram Sockets Rego, P.
2019-02-07  0:42  0% ` Jere
2019-02-07  5:28  0%   ` Rego, P.
2019-02-07  6:00         ` Egil H H
2019-02-07  6:41           ` Rego, P.
2019-02-07  8:28             ` Dmitry A. Kazakov
2019-02-08  0:15               ` Randy Brukardt
2019-02-08  8:25                 ` Simon Wright
2019-02-09  1:01                   ` Randy Brukardt
2019-02-10 17:54                     ` Simon Wright
2019-02-11 23:19                       ` Randy Brukardt
2019-02-12 11:35  3%                     ` Simon Wright
2019-02-07 11:47             ` Jere
2019-02-08 20:00  5%           ` Rego, P.
2019-02-07  8:58  9% Gnat Sockets - Obtaining all the home addresses ahlan
2019-05-14 17:05  6% ANN: Simple Components v4.40 Dmitry A. Kazakov
2019-11-05 19:06 12% Socket & Multicast problems / GNAT.Sockets Shark8
2019-11-05 19:10  6% ` Shark8
2019-11-05 19:57 12% ` Dmitry A. Kazakov
2019-11-05 20:11  6%   ` Shark8
2019-11-05 20:45  6%     ` Dmitry A. Kazakov
2020-04-02 13:58     Simple parse from https website Rego, P.
2020-04-02 14:42     ` Dmitry A. Kazakov
2020-04-02 14:48       ` Rego, P.
2020-04-02 17:16  7%     ` Dmitry A. Kazakov
2020-04-02 18:27  6%       ` Rego, P.
2020-04-02 19:05  6%         ` Dmitry A. Kazakov
2020-04-02 19:34  7%           ` Rego, P.
2020-04-03  5:19  0%             ` Jere
2020-04-03  6:47  0%             ` Dmitry A. Kazakov
2020-05-07  7:36  4% ANN: Simple Components v4.49 Dmitry A. Kazakov
2020-05-09  9:32  0% ` Azathoth Hastur
2020-08-31 13:28  4% ANN: Simple Components for Ada 4.51 IEEE 754-2008 Decimal Dmitry A. Kazakov
2020-09-03  4:30  0% ` linda white
2020-10-18  6:43  6% ANN: Simple Components for Ada v4.51 Dmitry A. Kazakov
2020-12-13  9:02  4% ANN: Simple components v4.53 Dmitry A. Kazakov
2020-12-21  4:59  6% Read/write access to Unix character devices philip...@gmail.com
2020-12-22  1:23  5% ` Randy Brukardt
2020-12-28 13:26  0% ` Björn Lundin
2021-01-13 12:01  4% ANN: Simple Components v Dmitry A. Kazakov
2021-11-06 12:04  4% ANN: Simple Components for Ada v4.59 Dmitry A. Kazakov
2022-01-29 16:31     file "synchronization-interprocess.ads" not found hreba
2022-01-29 19:09     ` Dmitry A. Kazakov
2022-02-01 19:37  8%   ` hreba
2022-02-01 20:11  6%     ` Dmitry A. Kazakov
2022-05-21 10:03  5% ANN: Simple Components v4.62 Dmitry A. Kazakov
2022-06-29 10:15  6% SimpleComponents / MQTT slos
2022-06-29 15:00  0% ` Dmitry A. Kazakov
2022-07-01  8:51  4%   ` slos
2022-07-01 11:05  6%     ` Dmitry A. Kazakov
2022-07-01 13:22  0%       ` slos
2022-12-31 12:11  6% Sockets, Streams, and Element_Arrays: Much confusion Mark Gardner
2022-12-31 13:11  0% ` Dmitry A. Kazakov
2022-12-31 13:50       ` Mark Gardner
2022-12-31 14:16  5%     ` Dmitry A. Kazakov
2022-12-31 17:39  0% ` Simon Wright
2022-12-31 19:36  4%   ` Mark Gardner
2023-01-05  7:55  5% ` Daniel Norte de Moraes
2023-01-05 10:35  5%   ` Dmitry A. Kazakov
2023-02-07 20:29     Broadcast / iterate to all Connection objects via Simple Components? A.J.
2023-02-08  9:55     ` Jeffrey R.Carter
2023-02-13  7:28       ` Emmanuel Briot
2023-02-13  8:30         ` Dmitry A. Kazakov
2023-02-13  8:44           ` Emmanuel Briot
2023-02-13 10:55  4%         ` Dmitry A. Kazakov
2023-02-13 11:07  4%           ` Emmanuel Briot
2023-02-13 11:57  5%             ` Dmitry A. Kazakov
2023-02-13 13:22                   ` Niklas Holsti
2023-02-13 15:10                     ` Dmitry A. Kazakov
2023-02-13 16:26                       ` Niklas Holsti
2023-02-13 19:48                         ` Dmitry A. Kazakov
2023-02-15  9:54                           ` Niklas Holsti
2023-02-15 10:57                             ` Dmitry A. Kazakov
2023-02-15 18:37                               ` Niklas Holsti
2023-02-19  1:27  3%                             ` A.J.
2023-02-13 16:40  3%             ` Jeremy Grosser <jeremy@synack.me>
2023-02-13 20:33  5% ` Daniel Norte de Moraes
2023-03-30 21:49     ChatGPT Anatoly Chernyshev
2023-03-30 23:00     ` ChatGPT Jeffrey R.Carter
2023-03-31  6:54       ` ChatGPT Dmitry A. Kazakov
2023-03-31 11:04  4%     ` ChatGPT magardner2010
2023-05-30 16:36  7% GNAT or Language Problems? Jeffrey R.Carter
2023-06-17  7:28  0% ` Randy Brukardt
2023-07-04 10:56  4% gnat -xdr flag confusion magardner2010
2024-02-16  9:41     In memory Stream DrPi
2024-02-17 13:36     ` DrPi
2024-02-17 14:28       ` Dmitry A. Kazakov
2024-02-17 18:09  5%     ` Simon Wright

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