oceanbase

Форк
0
/
ussl-deps.c 
50 строк · 1.5 Кб
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

20
static __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)
23
  INIT_LIBC_FUNC_PTR(setsockopt);
24
  INIT_LIBC_FUNC_PTR(listen);
25
  INIT_LIBC_FUNC_PTR(connect);
26
  INIT_LIBC_FUNC_PTR(accept);
27
  INIT_LIBC_FUNC_PTR(accept4);
28
  INIT_LIBC_FUNC_PTR(epoll_ctl);
29
  INIT_LIBC_FUNC_PTR(read);
30
  INIT_LIBC_FUNC_PTR(write);
31
  INIT_LIBC_FUNC_PTR(close);
32
  INIT_LIBC_FUNC_PTR(writev);
33
}
34

35
int make_socket_non_blocking(int fd)
36
{
37
  int ret = 0, flags = 0;
38
  flags = fcntl(fd, F_GETFL, 0);
39
  if (-1 == flags) {
40
    ussl_log_error("call fcntl with F_GETFL failed, errno:%d", errno);
41
    ret = -1;
42
  } else {
43
    flags |= O_NONBLOCK;
44
    if (-1 == fcntl(fd, F_SETFL, flags)) {
45
      ussl_log_error("call fcntl with F_SETFL failed, errno:%d", errno);
46
      ret = -1;
47
    }
48
  }
49
  return ret;
50
}
51

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.