Re: libevent manuals

2023-01-18 Thread Ingo Schwarze
Hi Ted,

Ted Bullock wrote on Mon, Jan 16, 2023 at 12:56:06PM -0700:

> The impetus is that the event(3) manual page isn't all that good for
> documenting how to use the library and it is missing functions that are
> included in the API and available in the shared library.

That seems true, and those are good reasons to improve the manual pages.

> Upstream of course has moved on to version 2.x, as far as I can tell
> there is no more maintenance being done on the 1.4 version

According to
  https://github.com/libevent/libevent/tree/patches-1.4
that seems accurate to me: it appears the 1.4 branch was last touched
in the git repo eight years ago, and it is marked "stale",
along with the 2.0 and 2.1 branches.

> that OpenBSD ships except the work that is done internally in the OS.

Given that our event.3 says
  .\" Copyright (c) 2000 Artur Grabowski 
and that the libevent git repo contains a Jurassic version
of our event.3 in the 1.4 branch and does no longer appear
to contain *any* kind of documentation in the master branch -
in particular, there is no event.3 in the master branch any longer -
i think maintaining the libevent manual pages ourselves is perfectly
fine.  I see no danger that any documentation might need to be merged
from the libevent git: it appears the libevent project regards
documentation as a useless distraction at best...  :-o

> Anyway, here is what I came up with for a few functions after reading
> the source tree. I also went back through historical releases to see
> how the API evolved over time.

I think this is likely a worthwhile project, but still needs a lot
of work before it can be considered for commit.

> I'm planning to finish off documenting the rest of the library, if
> folks have feedback, I'm interested.

Given how much feedback i have on your first file, i'm not yet reading
your second and third file right now.

We do development in steps, and the tree needs to build and be better
after each commit than before that commit.  So to be able to be committed,
your patch for the first file should also delete the now redundant
information from event.3.  Regard it as splitting one well-defined
part out of the excessively large event.3 and adding lots of missing
information while splitting it out.

> event_init.3
> 

At this point, one line is missing:

  .\" $OpenBSD$

The command `mandoc -T lint` tells you:

  mandoc: event_init.3: STYLE: RCS id missing: (OpenBSD)

> .\" Copyright (c) 2023 Ted Bullock 
> .\"
> .\" Permission to use, copy, modify, and distribute this software for any
> .\" purpose with or without fee is hereby granted, provided that the above
> .\" copyright notice and this permission notice appear in all copies.
> .\"
> .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> .\"
> .Dd $Mdocdate: January 9 2023 $
> .Dt EVENT_INIT 3
> .Os
> .Sh NAME
> .Nm event_base_new ,
> .Nm event_init

This is not nice.
Unless there is a good reason to name the page after a function that
is not the first function in the NAME section, put the function
corresponding to the file name first in NAME and in all other sections.

> .Nd initializes an
> .Vt event_base
> instance

While nesting markup inside .Nd is technically possible,
it is fragile, looks ugly, and we certainly don't do it in OpenBSD.

> .Sh SYNOPSIS
> .In event.h
> .Ft "struct event_base *"
> .Fn event_base_new void
> .Ft "struct event_base *"
> .Fn event_init void
> .Sh DESCRIPTION
> The functions
> .Fn event_base_new
> and
> .Fn event_init
> initialize the
> .Lb libevent

We don't normally use the .Lb macro in OpenBSD.
Maybe just talk about "the event library" with no markup?
The existing event.3 talks about

The
.Nm event
API ...

which is not wrong, but i'm not convinced the .Nm markup provides much
value here.

> and need to be called prior to scheduling an event or
> starting the event-loop. The two functions are similar, although global
> variables are set when calling
> .Fn event_init
> to help simplify the API for programs requiring only one event-loop.

This is not good.  Don't start comparing functions without precisely
saying first what each function actually does, in particular not in the
first sentence of a manual page.

Instead, the first sentence should only state the general purpose of
the functions documented in the page.  In this page, it might not be
needed at all, you could probably start with event_base_new(3) right
away.

After the introductory sentence(s), if any, start with one function and
document it thoroughly.  

libevent manuals

2023-01-16 Thread Ted Bullock
Hi folks,

I'm writing manual pages for the libevent variant bundled with OpenBSD,
this is a documentation project that I started in something like 2012
but got pulled away from due to life circumstances. I've returned to
it after reading an old Things to Do - *urgent* list I left in a binder
over a decade ago. heh.

The impetus is that the event(3) manual page isn't all that good for
documenting how to use the library and it is missing functions that are
included in the API and available in the shared library.

Upstream of course has moved on to version 2.x, as far as I can tell
there is no more maintenance being done on the 1.4 version that OpenBSD
ships except the work that is done internally in the OS.

Anyway, here is what I came up with for a few functions after reading
the source tree. I also went back through historical releases to see
how the API evolved over time.

I'm planning to finish off documenting the rest of the library, if
folks have feedback, I'm interested.

Take Care,

event_init.3


.\" Copyright (c) 2023 Ted Bullock 
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: January 9 2023 $
.Dt EVENT_INIT 3
.Os
.Sh NAME
.Nm event_base_new ,
.Nm event_init
.Nd initializes an
.Vt event_base
instance
.Sh SYNOPSIS
.In event.h
.Ft "struct event_base *"
.Fn event_base_new void
.Ft "struct event_base *"
.Fn event_init void
.Sh DESCRIPTION
The functions
.Fn event_base_new
and
.Fn event_init
initialize the
.Lb libevent
and need to be called prior to scheduling an event or
starting the event-loop. The two functions are similar, although global
variables are set when calling
.Fn event_init
to help simplify the API for programs requiring only one event-loop.
.Pp
The
.Lb libevent
API is generally not thread-safe unless only one
.Vt "event_base"
instance is accessible per thread or care is taken to lock access.
.Pp
These functions allocate memory that should be freed using
.Xr event_base_free 3 .
.Pp
Diagnostic and error messages are retrievable from these functions by
configuring a message log callback with
.Xr event_set_log_callback 3 .
.Pp
After a call to
.Xr fork 2
some notification methods will not persist and need to reinitiliazed with
.Xr event_reinit 3 .
.Sh RETURN VALUES
The
.Fn event_base_new
and
.Fn event_init
functions return a
.Vt "struct event_base"
pointer.
If the functions fail, for example, due to a lack of memory, they do
.Em NOT
return.
.Sh ENVIRONMENT
Programs using the
.Lb libevent
are configurable with environment variables prior to calling
.Fn event_base_new
or
.Fn event_init .
.Bl -tag
.It Ev Sy EVENT_SHOW_METHOD
If the log callback is configured, report which kernel notification method the
library is using.
.It Ev Sy EVENT_NOKQUEUE
Disable library support for
.Xr kqueue 2
.It Ev Sy EVENT_NOPOLL
Disable library support for
.Xr poll 2
.It Ev Sy EVENT_NOSELECT
Disable library support for
.Xr select 2
.El
.Sh EXAMPLES
In this example code a new
.Vt "struct event_base"
is initialized with support for logging.
This example also applies to
.Fn event_base_new ,
the difference being that internal global variables are configured to simplify
other parts of the API.
.Bd -literal -offset indent
#include 
#include 

void cb(int sev, const char* msg)
{
printf("%d: %s\n", sev, msg);
}

int main()
{
event_set_log_callback(cb);

struct event_base *base = event_init();
if (base == NULL) {
printf("event_init failed, will not return\\n");
return 1;
}
/* do something with the event library here */

event_base_free(base);
return 0;
}
.Ed
.Sh SEE ALSO
.Xr event_set_log_callback 3 ,
.Xr event_base_free 3 ,
.Xr event_dispatch 3
.Sh HISTORY
The function
.Fn event_init
first appeared in
.Lb libevent-0.1
although it's protoype has changed various times since that release. In
.Lb libevent-1.4.1beta
.Fn event_base_new
was added and
.Fn event_init
was once again changed to wrap around the new function.
.Pp
Environment variable options first appeared in
.Lb libevent-0.7a .
.Sh AUTHORS
The
.Lb libevent
was written by
.An -nosplit
.An Niels Provos
and
.An Nick Mathewson
.Pp
This manual was written by
.An Ted Bullock Aq Mt tbull...@comlore.com


event_set_log_callback.3


.\" Copyright (c)