3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2014-2017 Nest Labs, Inc.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file contains the basis class for reference counting
22 * objects by the Inet layer as well as a class for representing
23 * the pending or resulting I/O events on a socket.
26 #include "InetLayerBasis.h"
31 #if CHIP_SYSTEM_CONFIG_USE_SOCKETS
33 * Sets the bit for the specified file descriptor in the given sets of file descriptors.
35 * @param[in] socket The file descriptor for which the bit is being set.
37 * @param[out] nfds A reference to the range of file descriptors in the set.
39 * @param[in] readfds A pointer to the set of readable file descriptors.
41 * @param[in] writefds A pointer to the set of writable file descriptors.
43 * @param[in] exceptfds A pointer to the set of file descriptors with errors.
46 void SocketEvents::SetFDs(int socket, int & nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds)
48 if (socket != INET_INVALID_SOCKET_FD)
51 FD_SET(socket, readfds);
53 FD_SET(socket, writefds);
55 FD_SET(socket, exceptfds);
56 if (IsSet() && (socket + 1) > nfds)
62 * Set the read, write or exception bit flags for the specified socket based on its status in
63 * the corresponding file descriptor sets.
65 * @param[in] socket The file descriptor for which the bit flags are being set.
67 * @param[in] readfds A pointer to the set of readable file descriptors.
69 * @param[in] writefds A pointer to the set of writable file descriptors.
71 * @param[in] exceptfds A pointer to the set of file descriptors with errors.
74 SocketEvents SocketEvents::FromFDs(int socket, fd_set * readfds, fd_set * writefds, fd_set * exceptfds)
78 if (socket != INET_INVALID_SOCKET_FD)
80 if (FD_ISSET(socket, readfds))
82 if (FD_ISSET(socket, writefds))
84 if (FD_ISSET(socket, exceptfds))
90 #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS