Skip to content

Commit

Permalink
Simplify KQueueIoOps as we don't need to pass the ident (#14055)
Browse files Browse the repository at this point in the history
Motivation:

We can simplify KqueueIops as we don't need to pass the ident with it.
The ident is already known by the KQueueIoRegistration as part of the
KqueueIoHandle.

Modifications:

Remove ident from KQueueIoOps

Result:

Simplify API
  • Loading branch information
normanmaurer committed May 16, 2024
1 parent 1102847 commit ec8b34d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ abstract class AbstractKQueueChannel extends AbstractChannel implements UnixChan
remote = fd.remoteAddress();
}

readEnabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_READ, Native.EV_ADD_CLEAR_ENABLE, 0);
writeEnabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_WRITE, Native.EV_ADD_CLEAR_ENABLE, 0);
readDisabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_READ, Native.EV_DELETE_DISABLE, 0);
writeDisabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_WRITE, Native.EV_DELETE_DISABLE, 0);
readEnabledOps = KQueueIoOps.newOps(Native.EVFILT_READ, Native.EV_ADD_CLEAR_ENABLE, 0);
writeEnabledOps = KQueueIoOps.newOps(Native.EVFILT_WRITE, Native.EV_ADD_CLEAR_ENABLE, 0);
readDisabledOps = KQueueIoOps.newOps(Native.EVFILT_READ, Native.EV_DELETE_DISABLE, 0);
writeDisabledOps = KQueueIoOps.newOps(Native.EVFILT_WRITE, Native.EV_DELETE_DISABLE, 0);
}

AbstractKQueueChannel(Channel parent, BsdSocket fd, SocketAddress remote) {
Expand All @@ -110,10 +110,10 @@ abstract class AbstractKQueueChannel extends AbstractChannel implements UnixChan
this.remote = remote;
local = fd.localAddress();

readEnabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_READ, Native.EV_ADD_CLEAR_ENABLE, 0);
writeEnabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_WRITE, Native.EV_ADD_CLEAR_ENABLE, 0);
readDisabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_READ, Native.EV_DELETE_DISABLE, 0);
writeDisabledOps = KQueueIoOps.newOps(fd().intValue(), Native.EVFILT_WRITE, Native.EV_DELETE_DISABLE, 0);
readEnabledOps = KQueueIoOps.newOps(Native.EVFILT_READ, Native.EV_ADD_CLEAR_ENABLE, 0);
writeEnabledOps = KQueueIoOps.newOps(Native.EVFILT_WRITE, Native.EV_ADD_CLEAR_ENABLE, 0);
readDisabledOps = KQueueIoOps.newOps(Native.EVFILT_READ, Native.EV_DELETE_DISABLE, 0);
writeDisabledOps = KQueueIoOps.newOps(Native.EVFILT_WRITE, Native.EV_DELETE_DISABLE, 0);
}

@Override
Expand Down Expand Up @@ -189,8 +189,7 @@ protected void doDeregister() throws Exception {
}

private void clearRdHup0() {
submit(KQueueIoOps.newOps(fd().intValue(),
Native.EVFILT_SOCK, Native.EV_DELETE_DISABLE, Native.NOTE_RDHUP));
submit(KQueueIoOps.newOps(Native.EVFILT_SOCK, Native.EV_DELETE_DISABLE, Native.NOTE_RDHUP));
}

private void submit(KQueueIoOps ops) {
Expand Down Expand Up @@ -229,9 +228,7 @@ protected void doRegister(ChannelPromise promise) {
// the Runnable on the new EventLoop.
readReadyRunnablePending = false;

int ident = fd().intValue();
submit(KQueueIoOps.newOps(
ident, Native.EVFILT_SOCK, Native.EV_ADD, Native.NOTE_RDHUP));
submit(KQueueIoOps.newOps(Native.EVFILT_SOCK, Native.EV_ADD, Native.NOTE_RDHUP));

// Add the write event first so we get notified of connection refused on the client side!
if (writeFilterEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,6 @@ private final class DefaultKqueueIoRegistration extends AtomicBoolean implements
@Override
public long submit(IoOps ops) {
KQueueIoOps kQueueIoOps = cast(ops);
if (kQueueIoOps.ident() != handle.ident()) {
throw new IllegalArgumentException("ident does not match KQueueIoHandle.ident()");
}
if (!isValid()) {
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,30 @@
* that is used by {@link KQueueIoHandler} and so for kqueue based transports.
*/
public final class KQueueIoOps implements IoOps {
private int ident;
private short filter;
private short flags;
private int fflags;
private long data;
private final short filter;
private final short flags;
private final int fflags;
private final long data;

/**
* Creates a new {@link KQueueIoOps}.
*
* @param ident the identifier for this event.
* @param filter the filter for this event.
* @param flags the general flags.
* @param fflags filter-specific flags.
* @return {@link KQueueIoOps}.
*/
public static KQueueIoOps newOps(int ident, short filter, short flags, int fflags) {
return new KQueueIoOps(ident, filter, flags, fflags, 0);
public static KQueueIoOps newOps(short filter, short flags, int fflags) {
return new KQueueIoOps(filter, flags, fflags, 0);
}

private KQueueIoOps(int ident, short filter, short flags, int fflags, long data) {
this.ident = ident;
private KQueueIoOps(short filter, short flags, int fflags, long data) {
this.filter = filter;
this.flags = flags;
this.fflags = fflags;
this.data = data;
}

KQueueIoOps() {
this(0, (short) 0, (short) 0, 0, 0);
}

/**
* Returns the identifier for this event.
*
* @return ident.
*/
public int ident() {
return ident;
}

/**
* Returns the filter for this event.
*
Expand Down Expand Up @@ -101,8 +85,7 @@ public long data() {
@Override
public String toString() {
return "KQueueIoOps{" +
"ident=" + ident +
", filter=" + filter +
"filter=" + filter +
", flags=" + flags +
", fflags=" + fflags +
", data=" + data +
Expand Down

0 comments on commit ec8b34d

Please sign in to comment.