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

opt: reduce duplicate code for I/O reactors #590

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions reactor_epoll_default.go → reactor_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux && !poll_opt
// +build linux,!poll_opt
//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && !poll_opt
// +build linux freebsd dragonfly netbsd openbsd darwin
// +build !poll_opt

package gnet

Expand Down Expand Up @@ -53,8 +54,13 @@
err := el.poller.Polling(func(fd int, ev netpoll.IOEvent, flags netpoll.IOFlags) error {
c := el.connections.getConn(fd)
if c == nil {
// Somehow epoll notified with an event for a stale fd that is not in our connection set.
// We need to delete it from the epoll set.
// For kqueue, this might happen when the connection has already been closed,
// the file descriptor will be deleted from kqueue automatically as documented
// in the manual pages.
// For epoll, it somehow notified with an event for a stale fd that is not in
// our connection set. We need to explicitly delete it from the epoll set.
// Also print a warning log for this kind of irregularity.
el.getLogger().Warnf("received event[fd=%d|ev=%d|flags=%d] of a stale connection from event-loop(%d)", fd, ev, flags, el.idx)

Check warning on line 63 in reactor_default.go

View check run for this annotation

Codecov / codecov/patch

reactor_default.go#L63

Added line #L63 was not covered by tests
return el.poller.Delete(fd)
}
return c.processIO(fd, ev, flags)
Expand Down Expand Up @@ -84,8 +90,13 @@
if _, ok := el.listeners[fd]; ok {
return el.accept(fd, ev, flags)
}
// Somehow epoll notified with an event for a stale fd that is not in our connection set.
// We need to delete it from the epoll set.
// For kqueue, this might happen when the connection has already been closed,
// the file descriptor will be deleted from kqueue automatically as documented
// in the manual pages.
// For epoll, it somehow notified with an event for a stale fd that is not in
// our connection set. We need to explicitly delete it from the epoll set.
// Also print a warning log for this kind of irregularity.
el.getLogger().Warnf("received event[fd=%d|ev=%d|flags=%d] of a stale connection from event-loop(%d)", fd, ev, flags, el.idx)
return el.poller.Delete(fd)
}
return c.processIO(fd, ev, flags)
Expand Down
84 changes: 0 additions & 84 deletions reactor_epoll_ultimate.go

This file was deleted.

109 changes: 0 additions & 109 deletions reactor_kqueue_default.go

This file was deleted.

4 changes: 2 additions & 2 deletions reactor_kqueue_ultimate.go → reactor_ultimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build (freebsd || dragonfly || netbsd || openbsd || darwin) && poll_opt
// +build freebsd dragonfly netbsd openbsd darwin
//go:build (linux || freebsd || dragonfly || netbsd || openbsd || darwin) && poll_opt
// +build linux freebsd dragonfly netbsd openbsd darwin
// +build poll_opt

package gnet
Expand Down
Loading