Code Monkey home page Code Monkey logo

talkroom's People

Contributors

viayie avatar

Watchers

 avatar  avatar

talkroom's Issues

求助

in the epoll.h

`void initlistensocket(int efd, short port)
{
/创建监听套接字/
int lfd = Socket(AF_INET, SOCK_STREAM, 0);

/*修改lfd为非阻塞*/
int flag = 0;
if ((flag = fcntl(lfd, F_SETFL, O_NONBLOCK)) < 0) {
    printf("%s: fcntl nonblocking failed, %s\n", __func__, strerror(errno));
    return;
}

/*端口复用*/
int opt = 1;
setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));

/*初始化lfd*/
//void eventset(struct myevent_s *ev, int fd, void (*call_back)(int, int, void *), void *arg);
//将lfd放置在将自定义结构体数组的最后
//acceptconn()是lfd的回调函数
//arg是回调函数acceptconn()的参数,指向lfd带的结构体中ptr指向的自定义结构体
eventset(&g_events[MAX_EVENTS], lfd, acceptconn, &g_events[MAX_EVENTS]);

/*将lfd挂在红黑树上,设定监听事件为读事件*/
eventadd(efd, EPOLLIN, &g_events[MAX_EVENTS]);

/*绑定*/
struct sockaddr_in servaddr;
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(port);
Bind(lfd, (struct sockaddr *)&servaddr, sizeof(servaddr));

/*监听*/
Listen(lfd, 128);

return;

}`

eventset(&g_events[MAX_EVENTS], lfd, acceptconn, &g_events[MAX_EVENTS]);

eventadd(efd, EPOLLIN, &g_events[MAX_EVENTS]);

如果要初始化g_events[max_events + 1] 不应该有for循环吗?
另外acceptconn()函数怎么不像一个回调函数?你在eventset() 把他当作了回调函数, 但是你在acceptconn函数中还调用了eventset()函数,这时候eventset(),有是另一个所谓的回调? 你不觉得把 eventset()函数放在acceptconn()中更好吗?,然后eventset在调用dataprocess().
就像这样?

for(i= 0 ; i < max_events + 1; i++){ acceptcon(); }

void acceptcon(int sd, ...){ eventset(...)//初始化g_events[i] }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.