linux基础 ---select/poll《十一》

本文介绍了Linux中用于处理多个并发连接的select和poll函数。通过使用select,一个进程可以有效地管理并响应多个客户端的连接。poll作为另一种解决方案,提供了更灵活的事件监控方式。文章通过实例展示了这两个函数的使用方法。

一个进程如何解决多个问题:
在这里插入图片描述
select函数:
在这里插入图片描述
在这里插入图片描述
select使用 ==》 一个进程搞定多个客户端的连接

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>


int main(int argc, const char* argv[])
{
    if(argc < 2)
    {
        printf("eg: ./a.out port\n");
        exit(1);
    }
    struct sockaddr_in serv_addr;
    socklen_t serv_len = sizeof(serv_addr);
    int port = atoi(argv[1]);

    // 创建套接字
    int lfd = socket(AF_INET, SOCK_STREAM, 0);
    // 初始化服务器 sockaddr_in 
    memset(&serv_addr, 0, serv_len);
    serv_addr.sin_family = AF_INET;                   // 地址族 
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);    // 监听本机所有的IP
    serv_addr.sin_port = htons(port);            // 设置端口 
    // 绑定IP和端口
    bind(lfd, (struct sockaddr*)&serv_addr, serv_len);

    // 设置同时监听的最大个数
    liste
出现这个问题 /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_standard.o: in function `std_event_loop_once': tevent_standard.c:(.text.std_event_loop_once+0x14): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_standard.c:(.text.std_event_loop_once+0x1bc): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_standard.o: in function `std_event_set_fd_flags': tevent_standard.c:(.text.std_event_set_fd_flags+0x24): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_select.o: in function `select_event_loop_once': tevent_select.c:(.text.select_event_loop_once+0x10): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_select.o:tevent_select.c:(.text.select_event_add_fd+0x1c): more undefined references to `talloc_check_name' follow /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_select.o: in function `select_event_add_fd': tevent_select.c:(.text.select_event_add_fd+0xa4): undefined reference to `_talloc_set_destructor' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_select.o: in function `select_event_fd_destructor': tevent_select.c:(.text.select_event_fd_destructor+0x1c): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_select.o: in function `select_event_context_init': tevent_select.c:(.text.select_event_context_init+0x10): undefined reference to `_talloc_zero' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_poll.o: in function `poll_event_set_fd_flags': tevent_poll.c:(.text.poll_event_set_fd_flags+0x1c): undefined reference to `_talloc_get_type_abort' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_poll.o: in function `poll_event_add_fd': tevent_poll.c:(.text.poll_event_add_fd+0x20): undefined reference to `_talloc_get_type_abort' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_poll.c:(.text.poll_event_add_fd+0x68): undefined reference to `talloc_get_size' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_poll.c:(.text.poll_event_add_fd+0x9c): undefined reference to `_talloc_realloc_array' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_poll.c:(.text.poll_event_add_fd+0xb4): undefined reference to `_talloc_free' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_poll.c:(.text.poll_event_add_fd+0xe4): undefined reference to `_talloc_realloc_array' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_poll.c:(.text.poll_event_add_fd+0x154): undefined reference to `_talloc_set_destructor' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_poll.o: in function `poll_event_fd_destructor': tevent_poll.c:(.text.poll_event_fd_destructor+0x28): undefined reference to `_talloc_get_type_abort' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_poll.o: in function `poll_event_context_init': tevent_poll.c:(.text.poll_event_context_init+0x10): undefined reference to `_talloc_zero' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_poll.o: in function `poll_event_loop_once': tevent_poll.c:(.text.poll_event_loop_once+0x5c): undefined reference to `_talloc_get_type_abort' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_epoll.o: in function `epoll_event_context_init': tevent_epoll.c:(.text.epoll_event_context_init+0x14): undefined reference to `_talloc_zero' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_epoll.c:(.text.epoll_event_context_init+0x44): undefined reference to `_talloc_set_destructor' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_epoll.c:(.text.epoll_event_context_init+0x64): undefined reference to `_talloc_free' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_epoll.o: in function `epoll_event_loop_once': tevent_epoll.c:(.text.epoll_event_loop_once+0x14): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_epoll.c:(.text.epoll_event_loop_once+0x1ac): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_epoll.o: in function `epoll_event_fd_destructor': tevent_epoll.c:(.text.epoll_event_fd_destructor+0x1c): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_epoll.o: in function `epoll_event_set_fd_flags': tevent_epoll.c:(.text.epoll_event_set_fd_flags+0x24): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: ./../lib/tevent/tevent_epoll.o: in function `epoll_event_add_fd': tevent_epoll.c:(.text.epoll_event_add_fd+0x1c): undefined reference to `talloc_check_name' /data/red-round3/red-round3/bcm504L04/toolchain/opt/toolchains/crosstools-arm_softfp-gcc-10.3-linux-4.19-glibc-2.32-binutils-2.36.1/bin/../lib/gcc/arm-buildroot-linux-gnueabi/10.3.0/../../../../arm-buildroot-linux-gnueabi/bin/ld: tevent_epoll.c:(.text.epoll_event_add_fd+0x68): undefined reference to `_talloc_set_destructor' collect2: error: ld returned 1 exit status Makefile:2167: recipe for target 'bin/libtevent.so.0' failed make[4]: *** [bin/libtevent.so.0] Error 1 make[4]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/source3' Makefile:224: recipe for target '/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.built' failed make[3]: *** [/data/red-round3/red-round3/Iplatform/openwrt/build_dir/target-arm-openwrt-linux-uclibc-be220v1/samba-3.6.25/.built] Error 2 make[3]: Leaving directory '/data/red-round3/red-round3/Iplatform/packages/opensource/samba' package/Makefile:133: recipe for target 'package/feeds/iplatform/samba/compile' failed make[2]: *** [package/feeds/iplatform/samba/compile] Error 2 make[2]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt' /data/red-round3/red-round3/Iplatform/openwrt/include/toplevel.mk:184: recipe for target 'package/samba/compile' failed make[1]: *** [package/samba/compile] Error 2 make[1]: Leaving directory '/data/red-round3/red-round3/Iplatform/openwrt' Makefile:234: recipe for target 'iplatform_package/samba/compile' failed make: *** [iplatform_package/samba/compile] Error 2
最新发布
11-02
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值