Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbed7856

Browse files
committed
Use epoll
1 parentbd824c1 commitbed7856

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

‎contrib/multimaster/sockhub/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CC = gcc
2-
CFLAGS = -c -I. -Wall -O3 -g -fPIC -DUSE_EPOLL
2+
CFLAGS = -c -I. -Wall -O3 -g -fPIC
33
LD =$(CC)
44
LDFLAGS = -g
55
AR = ar

‎contrib/multimaster/sockhub/sockhub.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ void ShubInitialize(Shub* shub, ShubParams* params)
263263
shub->output=-1;
264264
#ifdefUSE_EPOLL
265265
shub->epollfd=epoll_create(MAX_EVENTS);
266+
if (shub->epollfd<0) {
267+
shub->params->error_handler("Failed to create epoll",SHUB_FATAL_ERROR);
268+
}
266269
#else
267270
FD_ZERO(&shub->inset);
268271
shub->max_fd=0;
@@ -299,14 +302,15 @@ void ShubLoop(Shub* shub)
299302
inti,rc;
300303
#ifdefUSE_EPOLL
301304
structepoll_eventevents[MAX_EVENTS];
302-
rc=epoll_wait(shub->epollfd,events,MAX_EVENTS,shub->params->delay);
305+
rc=epoll_wait(shub->epollfd,events,MAX_EVENTS,shub->in_buffer_used==0 ?-1 :shub->params->delay);
303306
#else
304307
fd_setevents;
305308
structtimevaltm;
306309
intmax_fd=shub->max_fd;
307310

308311
tm.tv_sec=shub->params->delay/1000;
309312
tm.tv_usec=shub->params->delay %1000*1000;
313+
events=shub->inset;
310314

311315
rc=select(max_fd+1,&events,NULL,NULL,shub->in_buffer_used==0 ?NULL :&tm);
312316
#endif
@@ -320,8 +324,14 @@ void ShubLoop(Shub* shub)
320324
#ifdefUSE_EPOLL
321325
intj;
322326
for (j=0;j<rc;j++) {
323-
{
324-
i=events[j].data.fd;
327+
i=events[j].data.fd;
328+
fprintf(stderr,"events[j].events=%d, events[j].data.fd=%d\n",events[j].events,events[j].data.fd);
329+
if (events[j].events&EPOLLERR) {
330+
if (i!=shub->input&&i!=shub->output) {
331+
notify_disconnect(shub,i);
332+
}
333+
close_socket(shub,i);
334+
}elseif (events[j].events&EPOLLIN) {
325335
#else
326336
for (i=0;i <=max_fd;i++) {
327337
if (FD_ISSET(i,&events)) {
@@ -331,7 +341,7 @@ void ShubLoop(Shub* shub)
331341
if (s<0) {
332342
shub->params->error_handler("Failed to accept socket",SHUB_RECOVERABLE_ERROR);
333343
}else {
334-
ShubAddSocket(shub,i);
344+
ShubAddSocket(shub,s);
335345
}
336346
}elseif (i==shub->output) {/* receive response from server */
337347
/* try to read as much as possible */

‎contrib/multimaster/sockhub/sockhub.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define__SOCKHUB_H__
33

44

5+
#defineUSE_EPOLL 1
6+
57
#ifdefUSE_EPOLL
68
#include<sys/epoll.h>
79
#defineMAX_EVENTS 1024

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp