Skip to content

Commit c3002b0

Browse files
authored
Merge pull request #18 from antlabs/dev
Dev
2 parents 627d9ea + ee344a5 commit c3002b0

38 files changed

+4635
-582
lines changed

api_epoll.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ const (
3737
etDelWrite = uint32(0)
3838
etResetRead = uint32(0)
3939

40-
// 一次性触发
40+
// 一次性触发, TODO: 这里要看下是否需要,还是垂直触发+overflow fd记录
4141
etReadOneShot = uint32(unix.EPOLLERR | unix.EPOLLHUP | unix.EPOLLRDHUP | unix.EPOLLPRI | unix.EPOLLIN | unix.EPOLLOUT | unix.EPOLLET | unix.EPOLLONESHOT)
4242
etWriteOneShot = uint32(etReadOneShot)
4343
etDelWriteOneShot = uint32(0)
4444
etResetReadOneShot = uint32(etReadOneShot)
45+
46+
processWrite = uint32(unix.EPOLLOUT)
47+
processRead = uint32(unix.EPOLLIN | unix.EPOLLRDHUP | unix.EPOLLHUP | unix.EPOLLERR)
4548
)
4649

4750
type epollState struct {
@@ -56,6 +59,10 @@ type epollState struct {
5659
resetEv uint32
5760
}
5861

62+
func (e *epollState) getMultiEventLoop() *MultiEventLoop {
63+
return e.parent.parent
64+
}
65+
5966
func getReadWriteDeleteReset(oneShot bool, et bool) (uint32, uint32, uint32, uint32) {
6067
if oneShot {
6168
return etReadOneShot, etWriteOneShot, etDelWriteOneShot, etResetReadOneShot
@@ -155,7 +162,7 @@ func (e *epollState) apiPoll(tv time.Duration) (retVal int, err error) {
155162
}
156163

157164
retVal, err = unix.EpollWait(e.epfd, e.events, msec)
158-
e.parent.parent.addPollEvNum()
165+
e.getMultiEventLoop().addPollEvNum()
159166
if err != nil {
160167
if errors.Is(err, unix.EINTR) {
161168
return 0, nil
@@ -179,22 +186,44 @@ func (e *epollState) apiPoll(tv time.Duration) (retVal int, err error) {
179186
continue
180187
}
181188

182-
if ev.Events&(unix.EPOLLIN|unix.EPOLLRDHUP|unix.EPOLLHUP|unix.EPOLLERR) > 0 {
183-
e.parent.parent.addReadEvNum()
189+
if e.getMultiEventLoop().parseInParseLoop {
190+
isRead := ev.Events&processRead > 0
191+
isWrite := ev.Events&processWrite > 0
192+
e.getMultiEventLoop().parseLoop.addTask(int(ev.Fd), func() bool {
193+
if isRead {
194+
err = conn.processWebsocketFrame()
195+
if err != nil {
196+
conn.closeWithLock(err)
197+
return true
198+
}
199+
}
200+
201+
if isWrite {
202+
// 刷新下直接写入失败的数据
203+
conn.flushOrClose()
204+
}
205+
206+
return true
207+
})
208+
continue
209+
}
210+
if ev.Events&processRead > 0 {
211+
e.getMultiEventLoop().addReadEvNum()
184212

185213
// 读取数据,这里要发行下websocket的解析变成流式解析
186214
err = conn.processWebsocketFrame()
187215
if err != nil {
188216
conn.closeWithLock(err)
189217
}
190218
}
191-
if ev.Events&unix.EPOLLOUT > 0 {
192-
e.parent.parent.addWriteEvNum()
219+
if ev.Events&processWrite > 0 {
220+
e.getMultiEventLoop().addWriteEvNum()
193221
// 刷新下直接写入失败的数据
194222
conn.flushOrClose()
195223
}
196224
if ev.Events&(unix.EPOLLERR|unix.EPOLLHUP|unix.EPOLLRDHUP) > 0 {
197225
conn.closeWithLock(io.EOF)
226+
continue
198227
}
199228
}
200229

api_iouring.go

Lines changed: 0 additions & 182 deletions
This file was deleted.

api_iouring_batch.go

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)