Lely core libraries  2.3.4
ctx.h File Reference

This header file is part of the I/O library; it contains the I/O context and service declarations. More...

#include <lely/io2/io2.h>
#include <lely/util/dllist.h>
Include dependency graph for ctx.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  io_svc
 An I/O service. More...
 
struct  io_svc_vtbl
 The virtual table of an I/O service. More...
 

Macros

#define IO_SVC_INIT(vptr)
 The static initializer for io_svc.
 

Enumerations

enum  io_fork_event { IO_FORK_PREPARE , IO_FORK_PARENT , IO_FORK_CHILD }
 The type of event generated by an I/O context before and after a process fork. More...
 

Functions

io_ctx_tio_ctx_create (void)
 Creates a new I/O context. More...
 
void io_ctx_destroy (io_ctx_t *ctx)
 Destroys an I/O context. More...
 
void io_ctx_insert (io_ctx_t *ctx, struct io_svc *svc)
 Registers an I/O service with an I/O context. More...
 
void io_ctx_remove (io_ctx_t *ctx, struct io_svc *svc)
 Unregisters an I/O service with an I/O context. More...
 
int io_ctx_notify_fork (io_ctx_t *ctx, enum io_fork_event e)
 Notifies all registered I/O services of the specified fork event. More...
 
void io_ctx_shutdown (io_ctx_t *ctx)
 Shuts down all registered I/O services in reverse order of registration. More...
 

Detailed Description

This header file is part of the I/O library; it contains the I/O context and service declarations.

An I/O context provides a mechanism to synchronize I/O services during process forking and shutdown.

Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file ctx.h.

Enumeration Type Documentation

◆ io_fork_event

The type of event generated by an I/O context before and after a process fork.

See also
io_ctx_notify_fork()
Enumerator
IO_FORK_PREPARE 

The event generated before the fork.

IO_FORK_PARENT 

The event generated after the fork in the parent process.

IO_FORK_CHILD 

The event generated after the fork in the child process.

Definition at line 37 of file ctx.h.

Function Documentation

◆ io_ctx_create()

io_ctx_t* io_ctx_create ( void  )

Creates a new I/O context.

Returns
a pointer to the new context, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 90 of file ctx.c.

◆ io_ctx_destroy()

void io_ctx_destroy ( io_ctx_t ctx)

Destroys an I/O context.

See also
io_ctx_create()

Definition at line 117 of file ctx.c.

◆ io_ctx_insert()

void io_ctx_insert ( io_ctx_t ctx,
struct io_svc svc 
)

Registers an I/O service with an I/O context.

Precondition
svc is not registered with any I/O context, including ctx.
See also
io_ctx_remove()

Definition at line 126 of file ctx.c.

◆ io_ctx_remove()

void io_ctx_remove ( io_ctx_t ctx,
struct io_svc svc 
)

Unregisters an I/O service with an I/O context.

This function MUST NOT be invoked while io_ctx_notify_fork() or io_ctx_shutdown() is running.

Precondition
svc is registered with ctx.
See also
io_ctx_insert()

Definition at line 141 of file ctx.c.

◆ io_ctx_notify_fork()

int io_ctx_notify_fork ( io_ctx_t ctx,
enum io_fork_event  e 
)

Notifies all registered I/O services of the specified fork event.

Services are notified in order of registration, unless e is IO_FORK_PREPARE, in which case they are notified in reverse order.

It is the responsibility of the caller to ensure that no services are unregistered while this function is running.

Returns
0 on success or -1 if any service returned an error. In the latter case, the error number generated by the first failing service can be obtained with get_errc().

Definition at line 156 of file ctx.c.

◆ io_ctx_shutdown()

void io_ctx_shutdown ( io_ctx_t ctx)

Shuts down all registered I/O services in reverse order of registration.

Each service is shut down only once, irrespective of the number of calls to this function.

It is the responsibility of the caller to ensure that no services are unregistered while this function is running.

Definition at line 200 of file ctx.c.