网络编程- 客户端(select) 服务端 epoll

服务端,收到客户端的消息转给另一个线程进行转发

#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<sys/epoll.h>
#include<map>
#include<typeinfo>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define BUFFER_SIZE 40
#define MAX_EVENTS 1234
#define DEFAULT_PORT 1231

queue<char *>q;
map<int ,int>flag_fd;
map<int ,int>fd_flag;

void *send_queue_to_client(void *)
{
    while(1)
    {
        while(!q.empty())
        {

            char *s=q.front();
            printf("------thread running now------    %s将要发送给%c\n",s,s[0]);
            int go=s[0]-'0';
            go=flag_fd[go];
            if(go==0)
            {
                printf("未指明要发送的对象,不做处理,直接舍弃\n");
            }
            else
            {
                int flag_send=send(go,s,strlen(s),0);
                if(flag_send<0)
                    printf("send失败");
                printf("发送%s到%c成功\n",s,s[0]);
            }
            delete []s;
            q.pop();
            sleep(3);
        }
        sleep(10);
    }
}


void thread_create(pthread_t send_buff_to_client )
{
    send_buff_to_client=pthread_create(&send_buff_to_client,N
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值