1 /*
2 * Copyright 2024 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16 package io.netty.channel.kqueue;
17
18 import io.netty.channel.IoEvent;
19
20 /**
21 * {@link IoEvent} to use with {@link KQueueIoHandler}.
22 */
23 public final class KQueueIoEvent implements IoEvent {
24 private int ident;
25 private short filter;
26 private short flags;
27 private int fflags;
28 private long data;
29 private long udata;
30
31 /**
32 * Creates a new {@link KQueueIoEvent}.
33 *
34 * @param ident the identifier for this event.
35 * @param filter the filter for this event.
36 * @param flags the general flags.
37 * @param fflags filter-specific flags.
38 * @return {@link KQueueIoEvent}.
39 * @deprecated use {@link #newEvent(int, short, short, int, long, long)}
40 */
41 @Deprecated
42 public static KQueueIoEvent newEvent(int ident, short filter, short flags, int fflags) {
43 return new KQueueIoEvent(ident, filter, flags, fflags, 0, 0);
44 }
45
46 /**
47 * Creates a new {@link KQueueIoEvent}.
48 *
49 * @param ident the identifier for this event.
50 * @param filter the filter for this event.
51 * @param flags the general flags.
52 * @param fflags filter-specific flags.
53 * @param data the data
54 * @param udata the user defined data that is passed through.
55 * @return {@link KQueueIoEvent}.
56 */
57 public static KQueueIoEvent newEvent(int ident, short filter, short flags, int fflags, long data, long udata) {
58 return new KQueueIoEvent(ident, filter, flags, fflags, data, udata);
59 }
60
61 private KQueueIoEvent(int ident, short filter, short flags, int fflags, long data, long udata) {
62 this.ident = ident;
63 this.filter = filter;
64 this.flags = flags;
65 this.fflags = fflags;
66 this.data = data;
67 this.udata = udata;
68 }
69
70 KQueueIoEvent() {
71 this(0, (short) 0, (short) 0, 0, 0, 0);
72 }
73
74 // Only used internally for re-use.
75 void update(int ident, short filter, short flags, int fflags, long data, long udata) {
76 this.ident = ident;
77 this.filter = filter;
78 this.flags = flags;
79 this.fflags = fflags;
80 this.data = data;
81 this.udata = udata;
82 }
83
84 /**
85 * Returns the identifier for this event.
86 *
87 * @return ident.
88 */
89 public int ident() {
90 return ident;
91 }
92
93 /**
94 * Returns the filter for this event.
95 *
96 * @return filter.
97 */
98 public short filter() {
99 return filter;
100 }
101
102 /**
103 * Returns the general flags.
104 *
105 * @return flags.
106 */
107 public short flags() {
108 return flags;
109 }
110
111 /**
112 * Returns filter-specific flags.
113 *
114 * @return fflags.
115 */
116 public int fflags() {
117 return fflags;
118 }
119
120 /**
121 * Returns filter-specific data.
122 *
123 * @return data.
124 */
125 public long data() {
126 return data;
127 }
128
129 /**
130 * Returns user specified data.
131 *
132 * @return udata.
133 */
134 public long udata() {
135 return udata;
136 }
137
138 @Override
139 public String toString() {
140 return "KQueueIoEvent{" +
141 "ident=" + ident +
142 ", filter=" + filter +
143 ", flags=" + flags +
144 ", fflags=" + fflags +
145 ", data=" + data +
146 ", udata=" + udata +
147 '}';
148 }
149 }