Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于ep_wait问题 #790

Closed
lindxmooc opened this issue Jan 10, 2018 · 7 comments
Closed

关于ep_wait问题 #790

lindxmooc opened this issue Jan 10, 2018 · 7 comments

Comments

@lindxmooc
Copy link

云风大神,我想请教一下,如果我只是在Linux下开发,这个
static int
sp_wait(int efd, struct event *e, int max) {
struct epoll_event ev[max];
int n = epoll_wait(efd , ev, max, -1);
int i;
for (i=0;i<n;i++) {
e[i].s = ev[i].data.ptr;
unsigned flag = ev[i].events;
e[i].write = (flag & EPOLLOUT) != 0;
e[i].read = (flag & EPOLLIN) != 0;
}

return n;

}
是否可以改成这样:
static int
sp_wait1(int efd, *struct epoll_event ev, int max) {
int n = epoll_wait(efd , ev, max, -1);
return n;
}
不做for循环,毕竟在socket_server_poll()函数里已经有一个for (;;) {...}了,这样做,会不会高效点?

@zhongfq
Copy link

zhongfq commented Jan 10, 2018 via email

@lindxmooc
Copy link
Author

lindxmooc commented Jan 10, 2018

我是在这里修改处理了:
socket_server_poll(struct socket_server *ss, struct socket_message * result, int * more) {
for (;;) {

	if (ss->event_index == ss->event_n) {
		ss->event_n = sp_wait1(ss->event_fd, ss->evs, MAX_EVENT);
		//...
	}

	int _i = ss->event_index ++;
	struct event e[1];
	e->read = ss->evs[_i].events & (EPOLLIN | EPOLLHUP);
	e->write = ss->evs[_i].events & EPOLLOUT;
	e->error = ss->evs[_i].events & EPOLLERR;
	e->s = ss->evs[_i].data.ptr;

	// struct event *e = &ss->ev[ss->event_index++];
	struct socket *s = e->s;
	//...

其中的 evs是我在struct socket_server结构体里加上的:
struct epoll_event evs[MAX_EVENT];

@lindxmooc
Copy link
Author

这样做可以吗,对于只在Linux下开发,能提高一点效率吗?

@samoyedsun
Copy link
Contributor

samoyedsun commented Jan 10, 2018 via email

@cloudwu
Copy link
Owner

cloudwu commented Jan 11, 2018

你的程序效率出现问题了?

@lindxmooc
Copy link
Author

不是,我是在了解源码的时候看到的,所以才产生这个疑问,比如现在有6400个连接服务器,感觉就for循环了6400 * 2,因为ep_wait会分成100次回调,在每一次当中,sp_wait中for循环64次,在外面又循环处理64次,不知道是不是这样理解?

@samoyedsun
Copy link
Contributor

samoyedsun commented Jan 18, 2018 via email

@cloudwu cloudwu closed this as completed Oct 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants