Skip to content

Commit f37e784

Browse files
committed
Refactor reactor->write
1 parent 18b5428 commit f37e784

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/network/ReactorThread.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,9 @@ static int swReactorThread_loop_tcp(swThreadParam *param)
13371337

13381338
reactor->ptr = serv;
13391339
reactor->id = reactor_id;
1340+
reactor->thread = 1;
1341+
reactor->sockets = serv->connection_list;
1342+
reactor->max_socket = serv->max_connection;
13401343

13411344
reactor->onFinish = NULL;
13421345
reactor->onTimeout = NULL;

src/reactor/ReactorKqueue.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ static int swReactorKqueue_add(swReactor *reactor, int fd, int fdtype)
127127
return SW_ERR;
128128
}
129129
}
130+
if (swReactor_add(reactor, fd, fdtype) < 0)
131+
{
132+
return SW_ERR;
133+
}
130134

131135
memcpy(&e.udata, &fd_, sizeof(swFd));
132136
swTrace("[THREAD #%ld]EP=%d|FD=%d\n", pthread_self(), this->epfd, fd);
@@ -212,6 +216,10 @@ static int swReactorKqueue_del(swReactor *reactor, int fd)
212216
swWarn("kqueue remove fd[=%d] failed. Error: %s[%d]", fd, strerror(errno), errno);
213217
return SW_ERR;
214218
}
219+
if (swReactor_del(reactor, fd) < 0)
220+
{
221+
return SW_ERR;
222+
}
215223
reactor->event_num = reactor->event_num <= 0 ? 0 : reactor->event_num - 1;
216224
return SW_OK;
217225
}

src/reactor/ReactorPoll.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ static int swReactorPoll_add(swReactor *reactor, int fd, int fdtype)
109109
{
110110
object->events[cur].events |= POLLHUP;
111111
}
112+
if (swReactor_add(reactor, fd, fdtype) < 0)
113+
{
114+
return SW_ERR;
115+
}
112116
reactor->event_num++;
113117
return SW_OK;
114118
}
@@ -149,6 +153,11 @@ static int swReactorPoll_del(swReactor *reactor, int fd)
149153

150154
swTrace("fd=%d", fd);
151155

156+
if (swReactor_del(reactor, fd) < 0)
157+
{
158+
return SW_ERR;
159+
}
160+
152161
for (i = 0; i < reactor->event_num; i++)
153162
{
154163
//找到了

src/reactor/ReactorSelect.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ int swReactorSelect_add(swReactor *reactor, int fd, int fdtype)
9191
swWarn("max fd value is FD_SETSIZE(%d).\n", FD_SETSIZE);
9292
return SW_ERR;
9393
}
94+
if (swReactor_add(reactor, fd, fdtype) < 0)
95+
{
96+
return SW_ERR;
97+
}
9498
swReactorSelect *object = reactor->object;
9599
swFdList_node *ev = sw_malloc(sizeof(swFdList_node));
96100
ev->fd = fd;
@@ -116,6 +120,11 @@ int swReactorSelect_del(swReactor *reactor, int fd)
116120
swFdList_node ev, *s_ev = NULL;
117121
ev.fd = fd;
118122

123+
if (swReactor_del(reactor, fd) < 0)
124+
{
125+
return SW_ERR;
126+
}
127+
119128
LL_SEARCH(object->fds, s_ev, &ev, swReactorSelect_cmp);
120129
if (s_ev == NULL)
121130
{

0 commit comments

Comments
 (0)