oceanbase
1/**
2* Copyright (c) 2021 OceanBase
3* OceanBase CE is licensed under Mulan PubL v2.
4* You can use this software according to the terms and conditions of the Mulan PubL v2.
5* You may obtain a copy of Mulan PubL v2 at:
6* http://license.coscl.org.cn/MulanPubL-2.0
7* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10* See the Mulan PubL v2 for more details.
11*/
12
13#include "ussl-deps.h"14#include <dlfcn.h>15#include <fcntl.h>16#include <stdlib.h>17#include <sys/socket.h>18#include <sys/stat.h>19
20static __attribute__((constructor(101))) void init_libc_func_ptr()21{
22#define INIT_LIBC_FUNC_PTR(fname) libc_##fname = (typeof(libc_##fname))dlsym(RTLD_NEXT, #fname)23INIT_LIBC_FUNC_PTR(setsockopt);24INIT_LIBC_FUNC_PTR(listen);25INIT_LIBC_FUNC_PTR(connect);26INIT_LIBC_FUNC_PTR(accept);27INIT_LIBC_FUNC_PTR(accept4);28INIT_LIBC_FUNC_PTR(epoll_ctl);29INIT_LIBC_FUNC_PTR(read);30INIT_LIBC_FUNC_PTR(write);31INIT_LIBC_FUNC_PTR(close);32INIT_LIBC_FUNC_PTR(writev);33}
34
35int make_socket_non_blocking(int fd)36{
37int ret = 0, flags = 0;38flags = fcntl(fd, F_GETFL, 0);39if (-1 == flags) {40ussl_log_error("call fcntl with F_GETFL failed, errno:%d", errno);41ret = -1;42} else {43flags |= O_NONBLOCK;44if (-1 == fcntl(fd, F_SETFL, flags)) {45ussl_log_error("call fcntl with F_SETFL failed, errno:%d", errno);46ret = -1;47}48}49return ret;50}
51