Lely core libraries 2.3.4
ctx.c File Reference

This file is part of the I/O library; it contains the implementation of the I/O context functions. More...

#include "io2.h"
#include <lely/libc/threads.h>
#include <lely/io2/ctx.h>
#include <lely/util/errnum.h>
#include <lely/util/util.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for ctx.c:

Go to the source code of this file.

Data Structures

struct  io_ctx
 

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 file is part of the I/O library; it contains the implementation of the I/O context functions.

See also
lely/io2/ctx.h
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.c.

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.