Lely core libraries 2.3.4
poll.h File Reference

This header file is part of the I/O library; it contains the I/O polling declarations for Windows. More...

#include <lely/ev/poll.h>
#include <lely/io2/ctx.h>
#include <lely/io2/sys/io.h>
#include <windows.h>
Include dependency graph for poll.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  io_cp
 An I/O completion packet. More...
 

Macros

#define IO_CP_INIT(func)
 The static initializer for io_cp.
 

Typedefs

typedef void io_cp_func_t(struct io_cp *cp, size_t nbytes, int errc)
 The type of function invoked by an I/O polling instance (through ev_poll_wait()) when an overlapped I/O operation completes.
 

Functions

io_poll_tio_poll_create (io_ctx_t *ctx)
 Creates a new I/O polling instance.
 
void io_poll_destroy (io_poll_t *poll)
 Destroys an I/O polling instance.
 
io_ctx_tio_poll_get_ctx (const io_poll_t *poll)
 Returns a pointer to the I/O context with which the I/O polling instance is registered.
 
ev_poll_tio_poll_get_poll (const io_poll_t *poll)
 Returns a pointer to the ev_poll_t instance corresponding to the I/O polling instance.
 
int io_poll_register_handle (io_poll_t *poll, HANDLE handle)
 Registers a file handle with (the I/O completion port of) an I/O polling instance.
 
int io_poll_post (io_poll_t *poll, size_t nbytes, struct io_cp *cp)
 Posts a completion packet to the I/O completion port of an I/O polling instance.
 

Detailed Description

This header file is part of the I/O library; it contains the I/O polling declarations for Windows.

The Windows implementation is based on I/O completion ports.

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 poll.h.

Typedef Documentation

◆ io_cp_func_t

typedef void io_cp_func_t(struct io_cp *cp, size_t nbytes, int errc)

The type of function invoked by an I/O polling instance (through ev_poll_wait()) when an overlapped I/O operation completes.

Parameters
cpa pointer to the I/O completion packet.
nbytesthe number of bytes transfered in the operation.
errcthe error code.

Definition at line 47 of file poll.h.

Function Documentation

◆ io_poll_create()

io_poll_t * io_poll_create ( io_ctx_t ctx)

Creates a new I/O polling instance.

The polling instance creates and manages an I/O completion port.

Parameters
ctxa pointer to the I/O context with which the polling instance should be registered.
Returns
a pointer to the new polling instance, or NULL on error. In the latter case, the error number can be obtained with GetLastError().

◆ io_poll_destroy()

void io_poll_destroy ( io_poll_t poll)

Destroys an I/O polling instance.

See also
io_poll_create()

Destroys an I/O polling instance.

See also
io_poll_create()

Definition at line 243 of file poll.c.

◆ io_poll_register_handle()

int io_poll_register_handle ( io_poll_t poll,
HANDLE  handle 
)

Registers a file handle with (the I/O completion port of) an I/O polling instance.

This operation cannot be undone.

This function is implemented using CreateIoCompletionPort().

Parameters
polla pointer to an I/O polling instance.
handlethe file handle to be registered.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with GetLastError().

◆ io_poll_post()

int io_poll_post ( io_poll_t poll,
size_t  nbytes,
struct io_cp cp 
)

Posts a completion packet to the I/O completion port of an I/O polling instance.

Parameters
polla pointer to an I/O polling instance.
nbytesthe number of bytes reported to the io_cp_func_t callback function.
cpa pointer to an I/O completion packet.

This function is implemented using PostQueuedCompletionStatus().

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with GetLastError().