Lely core libraries  2.2.5
fd_loop.c File Reference

This file is part of the I/O library; it contains the file descriptor event loop implementation. More...

#include "io.h"
#include <lely/libc/stdatomic.h>
#include <lely/ev/std_exec.h>
#include <lely/ev/task.h>
#include <lely/io2/posix/fd_loop.h>
#include <lely/util/sllist.h>
#include <lely/util/util.h>
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/eventfd.h>
Include dependency graph for fd_loop.c:

Go to the source code of this file.

Data Structures

struct  io_fd_loop
 A file descriptor event loop. More...
 

Functions

io_fd_loop_tio_fd_loop_create (io_poll_t *poll)
 Creates a new file descriptor event loop. More...
 
void io_fd_loop_destroy (io_fd_loop_t *loop)
 Destroys a file descriptor event loop. More...
 
ev_poll_tio_fd_loop_get_poll (const io_fd_loop_t *loop)
 Returns a pointer to the polling instance used by the event loop.
 
ev_exec_tio_fd_loop_get_exec (const io_fd_loop_t *loop)
 Returns a pointer to the executor corresponding to the event loop.
 
int io_fd_loop_get_fd (const io_fd_loop_t *loop)
 Returns the file descriptor corresponding to the event loop.
 
void io_fd_loop_stop (io_fd_loop_t *loop)
 Stops the file descriptor event loop. More...
 
int io_fd_loop_stopped (io_fd_loop_t *loop)
 Returns 1 if the file descriptor event loop is stopped, and 0 if not.
 
void io_fd_loop_restart (io_fd_loop_t *loop)
 Restarts a file descriptor event loop. More...
 
size_t io_fd_loop_run (io_fd_loop_t *loop)
 Equivalent to. More...
 

Detailed Description

This file is part of the I/O library; it contains the file descriptor event loop implementation.

See also
lely/io2/posix/fd_loop.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 fd_loop.c.

Function Documentation

◆ io_fd_loop_create()

io_fd_loop_t* io_fd_loop_create ( io_poll_t poll)

Creates a new file descriptor event loop.

Parameters
polla pointer to the I/O polling instance used to monitor the event loop.
Returns
a pointer to the new event loop, or NULL on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 224 of file fd_loop.c.

◆ io_fd_loop_destroy()

void io_fd_loop_destroy ( io_fd_loop_t loop)

Destroys a file descriptor event loop.

See also
io_fd_loop_create()

Definition at line 251 of file fd_loop.c.

◆ io_fd_loop_stop()

void io_fd_loop_stop ( io_fd_loop_t loop)

Stops the file descriptor event loop.

Subsequent calls to io_fd_loop_run() and io_fd_loop_run_one() will return 0 immediately.

Postcondition
io_fd_loop_stopped() returns 1.

Definition at line 284 of file fd_loop.c.

◆ io_fd_loop_restart()

void io_fd_loop_restart ( io_fd_loop_t loop)

Restarts a file descriptor event loop.

Postcondition
io_fd_loop_stopped() returns 0.

Definition at line 313 of file fd_loop.c.

◆ io_fd_loop_run()

size_t io_fd_loop_run ( io_fd_loop_t loop)

Equivalent to.

size_t n = 0;
while (io_fd_loop_run_one(loop))
n += n < SIZE_MAX;
return n;

Definition at line 328 of file fd_loop.c.