Lely core libraries 2.3.4
fd.c File Reference

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

#include "fd.h"
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
Include dependency graph for fd.c:

Go to the source code of this file.

Functions

int io_fd_set_cloexec (int fd)
 Sets the FD_CLOEXEC flag of the file descriptor fd. More...
 
int io_fd_set_nonblock (int fd)
 Sets the O_NONBLOCK flag of the file descriptor fd. More...
 
int io_fd_wait (int fd, int *events, int timeout)
 Waits for one or more of the I/O events in *events to occur as if by POSIX poll(). More...
 
ssize_t io_fd_recvmsg (int fd, struct msghdr *msg, int flags, int timeout)
 Equivalent to POSIX recvmsg(fd, msg, flags), except that if fd is non-blocking (or the implementation supports the MSG_DONTWAIT flag) and timeout is non-negative, this function behaves as if fd is blocking and the SO_RCVTIMEO option is set with timeout milliseconds. More...
 
ssize_t io_fd_sendmsg (int fd, const struct msghdr *msg, int flags, int timeout)
 Equivalent to POSIX sendmsg(fd, msg, flags | MSG_NOSIGNAL), except that if fd is non-blocking (or the implementation supports the MSG_DONTWAIT flag) and timeout is non-negative, this function behaves as if fd is blocking and the SO_SNDTIMEO option is set with timeout milliseconds. More...
 

Detailed Description

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

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.c.

Function Documentation

◆ io_fd_set_cloexec()

int io_fd_set_cloexec ( int  fd)

Sets the FD_CLOEXEC flag of the file descriptor fd.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained from errno.

Definition at line 33 of file fd.c.

◆ io_fd_set_nonblock()

int io_fd_set_nonblock ( int  fd)

Sets the O_NONBLOCK flag of the file descriptor fd.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained from errno.

Definition at line 44 of file fd.c.

◆ io_fd_wait()

int io_fd_wait ( int  fd,
int *  events,
int  timeout 
)

Waits for one or more of the I/O events in *events to occur as if by POSIX poll().

On succes, the reported events are stored in *events.

Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained from errno.

Definition at line 55 of file fd.c.

◆ io_fd_recvmsg()

ssize_t io_fd_recvmsg ( int  fd,
struct msghdr *  msg,
int  flags,
int  timeout 
)

Equivalent to POSIX recvmsg(fd, msg, flags), except that if fd is non-blocking (or the implementation supports the MSG_DONTWAIT flag) and timeout is non-negative, this function behaves as if fd is blocking and the SO_RCVTIMEO option is set with timeout milliseconds.

The timeout interval will be rounded up to the system clock granularity, but this function MAY return early if interrupted by a signal.

Definition at line 80 of file fd.c.

◆ io_fd_sendmsg()

ssize_t io_fd_sendmsg ( int  fd,
const struct msghdr *  msg,
int  flags,
int  timeout 
)

Equivalent to POSIX sendmsg(fd, msg, flags | MSG_NOSIGNAL), except that if fd is non-blocking (or the implementation supports the MSG_DONTWAIT flag) and timeout is non-negative, this function behaves as if fd is blocking and the SO_SNDTIMEO option is set with timeout milliseconds.

The timeout interval will be rounded up to the system clock granularity, but this function MAY return early if interrupted by a signal.

Definition at line 116 of file fd.c.