caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] POSIX time implementation
@ 2015-09-05 11:52 "Markus W. Weißmann"
  2015-09-05 16:59 ` Gerd Stolpmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: "Markus W. Weißmann" @ 2015-09-05 11:52 UTC (permalink / raw)
  To: caml-list

Hi,

I was searching for an existing library implementing a clock_gettime(2) function that would deliver a ‘struct timespec’ [1] with the current time.
I want it for my POSIX message queue implementation [2] for the timed functions that require an absolute ‘struct timespec’ for their timeout.
So what a user of mqueue requires is a 1.) function to get the current time as ‘struct timespec’ and 2.) to add seconds/nanoseconds to such a value to create a timeout.

The existing solutions I found:
* The Unix library [3] implements ‘struct timeval’ as float (only microseconds, imho the float conversion is a bit of a hack — a clever one though)
* Netsys.clock_gettime from ocamlnet [4] implements ’struct timespec’ but has it as float/int for seconds/nanoseconds (whats with the float? All systems I found use either in32 or int64 for time_t)
* Mtime [5] implements clock_gettime(2) but seems to only offers relative values
* Ptime [6] appears to be the uber-POSIX time implementation but lacks clock_gettime (and probably always will)

I’d like my library to be a good OCaml citizen and _not_ implement my own special purpose timing functions (which are incompatible to everyone else’s).
Ptime looks like the ultimate solution for the datatype; ocamlnet gets the closest to my requirements — while being a gigantic library most of which has nothing to do with the domain of mqueue.

I’m a bit stuck on this one and would like to get some advice — and/or corrections if I misinterpreted one of the above solutions.

regards
-Markus

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
[2] http://mqueue.forge.ocamlcore.org/
[3] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html
[4] http://projects.camlcity.org/projects/dl/ocamlnet-4.0.4/doc/html-main/Netsys_posix.html
[5] http://erratique.ch/software/mtime
[6] http://erratique.ch/software/ptime

-- 
Markus Weißmann, M.Sc.
Technische Universität München
Institut für Informatik
Boltzmannstr. 3
D-85748 Garching
Germany
http://wwwknoll.in.tum.de/


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

* Re: [Caml-list] POSIX time implementation
  2015-09-05 11:52 [Caml-list] POSIX time implementation "Markus W. Weißmann"
@ 2015-09-05 16:59 ` Gerd Stolpmann
  2015-09-06  0:04 ` Milan Stanojević
  2015-09-08  9:02 ` Markus Weißmann
  2 siblings, 0 replies; 4+ messages in thread
From: Gerd Stolpmann @ 2015-09-05 16:59 UTC (permalink / raw)
  To: "Markus W. Weißmann"; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2338 bytes --]

Am Samstag, den 05.09.2015, 13:52 +0200 schrieb "Markus W. Weißmann":
> Hi,
> 
> * Netsys.clock_gettime from ocamlnet [4] implements ’struct timespec’ but has it as float/int for seconds/nanoseconds (whats with the float? All systems I found use either in32 or int64 for time_t)

I picked float for ease of use, and better compatibility with the time
functions in Unix (which all use floats for time_t). Only the integral
part is put into the float which provides 52 bits for the mantissa, so
it is really large enough.

> I’d like my library to be a good OCaml citizen and _not_ implement my own special purpose timing functions (which are incompatible to everyone else’s).
> Ptime looks like the ultimate solution for the datatype; ocamlnet gets the closest to my requirements — while being a gigantic library most of which has nothing to do with the domain of mqueue.

You'd only need the netsys part, which is practically standalone. None
of the other modules would get linked in. (I guess your are programming
for embedded platforms as POSIX message queues are typically found
there, and the size of executable probably matters.)

Of course you could also just copy the C code. OCamlnet has a liberal
license.

Gerd

> I’m a bit stuck on this one and would like to get some advice — and/or corrections if I misinterpreted one of the above solutions.
> 
> regards
> -Markus
> 
> [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
> [2] http://mqueue.forge.ocamlcore.org/
> [3] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html
> [4] http://projects.camlcity.org/projects/dl/ocamlnet-4.0.4/doc/html-main/Netsys_posix.html
> [5] http://erratique.ch/software/mtime
> [6] http://erratique.ch/software/ptime
> 
> -- 
> Markus Weißmann, M.Sc.
> Technische Universität München
> Institut für Informatik
> Boltzmannstr. 3
> D-85748 Garching
> Germany
> http://wwwknoll.in.tum.de/
> 
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [Caml-list] POSIX time implementation
  2015-09-05 11:52 [Caml-list] POSIX time implementation "Markus W. Weißmann"
  2015-09-05 16:59 ` Gerd Stolpmann
@ 2015-09-06  0:04 ` Milan Stanojević
  2015-09-08  9:02 ` Markus Weißmann
  2 siblings, 0 replies; 4+ messages in thread
From: Milan Stanojević @ 2015-09-06  0:04 UTC (permalink / raw)
  To: Markus W. Weißmann; +Cc: Caml List

[-- Attachment #1: Type: text/plain, Size: 2635 bytes --]

Jane Street's Core_kernel has Time_ns module. Time is represented as an
int, number of nanoseconds since unix epoch. Time_ns.now uses
clock_gettime(CLOCK_REALTIME)
There are also usual functions for operating on time and time spans.
Not sure if Core_kernel is too big for your project.
Hi,

I was searching for an existing library implementing a clock_gettime(2)
function that would deliver a ‘struct timespec’ [1] with the current time.
I want it for my POSIX message queue implementation [2] for the timed
functions that require an absolute ‘struct timespec’ for their timeout.
So what a user of mqueue requires is a 1.) function to get the current time
as ‘struct timespec’ and 2.) to add seconds/nanoseconds to such a value to
create a timeout.

The existing solutions I found:
* The Unix library [3] implements ‘struct timeval’ as float (only
microseconds, imho the float conversion is a bit of a hack — a clever one
though)
* Netsys.clock_gettime from ocamlnet [4] implements ’struct timespec’ but
has it as float/int for seconds/nanoseconds (whats with the float? All
systems I found use either in32 or int64 for time_t)
* Mtime [5] implements clock_gettime(2) but seems to only offers relative
values
* Ptime [6] appears to be the uber-POSIX time implementation but lacks
clock_gettime (and probably always will)

I’d like my library to be a good OCaml citizen and _not_ implement my own
special purpose timing functions (which are incompatible to everyone
else’s).
Ptime looks like the ultimate solution for the datatype; ocamlnet gets the
closest to my requirements — while being a gigantic library most of which
has nothing to do with the domain of mqueue.

I’m a bit stuck on this one and would like to get some advice — and/or
corrections if I misinterpreted one of the above solutions.

regards
-Markus

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
[2] http://mqueue.forge.ocamlcore.org/
[3] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html
[4]
http://projects.camlcity.org/projects/dl/ocamlnet-4.0.4/doc/html-main/Netsys_posix.html
[5] http://erratique.ch/software/mtime
[6] http://erratique.ch/software/ptime

--
Markus Weißmann, M.Sc.
Technische Universität München
Institut für Informatik
Boltzmannstr. 3
D-85748 Garching
Germany
http://wwwknoll.in.tum.de/


--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

[-- Attachment #2: Type: text/html, Size: 3881 bytes --]

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

* Re: [Caml-list] POSIX time implementation
  2015-09-05 11:52 [Caml-list] POSIX time implementation "Markus W. Weißmann"
  2015-09-05 16:59 ` Gerd Stolpmann
  2015-09-06  0:04 ` Milan Stanojević
@ 2015-09-08  9:02 ` Markus Weißmann
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Weißmann @ 2015-09-08  9:02 UTC (permalink / raw)
  To: caml-list

For the record:
I found another OCaml implementation of clock_gettime(2): oclock [7] 
(also available via opam).
Unfortunately oclock implements 'struct timespec { time_t, long }' as 
int64, making some conversion necessary, too.

regards
-Markus

[7] http://micdel.fr/oclock.html

On 2015-09-05 13:52, Markus W. Weißmann wrote:
> Hi,
>
> I was searching for an existing library implementing a
> clock_gettime(2) function that would deliver a ‘struct timespec’ [1]
> with the current time.
> I want it for my POSIX message queue implementation [2] for the timed
> functions that require an absolute ‘struct timespec’ for their
> timeout.
> So what a user of mqueue requires is a 1.) function to get the
> current time as ‘struct timespec’ and 2.) to add seconds/nanoseconds
> to such a value to create a timeout.
>
> The existing solutions I found:
> * The Unix library [3] implements ‘struct timeval’ as float (only
> microseconds, imho the float conversion is a bit of a hack — a clever
> one though)
> * Netsys.clock_gettime from ocamlnet [4] implements ’struct timespec’
> but has it as float/int for seconds/nanoseconds (whats with the 
> float?
> All systems I found use either in32 or int64 for time_t)
> * Mtime [5] implements clock_gettime(2) but seems to only offers 
> relative values
> * Ptime [6] appears to be the uber-POSIX time implementation but
> lacks clock_gettime (and probably always will)
>
> I’d like my library to be a good OCaml citizen and _not_ implement my
> own special purpose timing functions (which are incompatible to
> everyone else’s).
> Ptime looks like the ultimate solution for the datatype; ocamlnet
> gets the closest to my requirements — while being a gigantic library
> most of which has nothing to do with the domain of mqueue.
>
> I’m a bit stuck on this one and would like to get some advice —
> and/or corrections if I misinterpreted one of the above solutions.
>
> regards
> -Markus
>
> [1] 
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
> [2] http://mqueue.forge.ocamlcore.org/
> [3] http://caml.inria.fr/pub/docs/manual-ocaml/libref/Unix.html
> [4]
> 
> http://projects.camlcity.org/projects/dl/ocamlnet-4.0.4/doc/html-main/Netsys_posix.html
> [5] http://erratique.ch/software/mtime
> [6] http://erratique.ch/software/ptime
>
> --
> Markus Weißmann, M.Sc.
> Technische Universität München
> Institut für Informatik
> Boltzmannstr. 3
> D-85748 Garching
> Germany
> http://wwwknoll.in.tum.de/


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

end of thread, other threads:[~2015-09-08  9:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-05 11:52 [Caml-list] POSIX time implementation "Markus W. Weißmann"
2015-09-05 16:59 ` Gerd Stolpmann
2015-09-06  0:04 ` Milan Stanojević
2015-09-08  9:02 ` Markus Weißmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).