View Javadoc
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.uring;
17  
18  import io.netty.channel.IoEvent;
19  import io.netty.channel.IoRegistration;
20  
21  import java.nio.ByteBuffer;
22  
23  /**
24   * {@link IoEvent} that will be produced as an result of a {@link IoUringIoOps}.
25   */
26  public final class IoUringIoEvent implements IoEvent {
27  
28      private byte opcode;
29      private int res;
30      private int flags;
31      private long userData;
32      private ByteBuffer extraCqeData;
33  
34      /**
35       * Create a new instance
36       *
37       * @param res       the result.
38       * @param flags     the flags
39       * @param opcode    the op code
40       * @param data      the user data that was given as part of the submission.
41       * @deprecated use {@link #IoUringIoEvent(int,int,byte,long)} instead.
42       */
43      @Deprecated
44      public IoUringIoEvent(int res, int flags, byte opcode, short data) {
45          this(res, flags, opcode, (long) data);
46      }
47  
48      /**
49       * Create a new instance
50       *
51       * @param res       the result.
52       * @param flags     the flags
53       * @param opcode    the op code
54       * @param userData  the user data that was given as part of the submission.
55       */
56      public IoUringIoEvent(int res, int flags, byte opcode, long userData) {
57          this.res = res;
58          this.flags = flags;
59          this.opcode = opcode;
60          this.userData = userData;
61      }
62  
63      // Used internally to reduce object creation
64      void update(int res, int flags, byte opcode, long userData, ByteBuffer extraCqeData) {
65          this.res = res;
66          this.flags = flags;
67          this.opcode = opcode;
68          this.userData = userData;
69          this.extraCqeData = extraCqeData;
70      }
71  
72      /**
73       * Returns the result.
74       *
75       * @return  the result
76       */
77      public int res() {
78          return res;
79      }
80  
81      /**
82       * Returns the flags.
83       *
84       * @return flags
85       */
86      public int flags() {
87          return flags;
88      }
89  
90      /**
91       * Returns the op code of the {@link IoUringIoOps}.
92       *
93       * @return  opcode
94       */
95      public byte opcode() {
96          return opcode;
97      }
98  
99      /**
100      * Returns the data that is passed as part of {@link IoUringIoOps}.
101      *
102      * @return  data.
103      * @deprecated use {@link #userData()} instead.
104      */
105     @Deprecated
106     public short data() {
107         return (short) userData;
108     }
109 
110     /**
111      * Returns the user data that was passed as part of the submission.
112      *
113      * @return  user data.
114      */
115     public long userData() {
116         return userData;
117     }
118 
119     /**
120      * Returns the extra data for the CQE. This will only be non-null of the ring was setup with
121      * {@code IORING_SETUP_CQE32}. As this {@link ByteBuffer} maps into the shared completion queue its important
122      * to not hold any reference to it outside of the {@link IoUringIoHandle#handle(IoRegistration, IoEvent)} method.
123      *
124      * @return extra data for the CQE or {@code null}.
125      */
126     public ByteBuffer extraCqeData() {
127         return extraCqeData;
128     }
129 
130     @Override
131     public String toString() {
132         return "IOUringIoEvent{" +
133                 "opcode=" + opcode +
134                 ", res=" + res +
135                 ", flags=" + flags +
136                 ", userData=" + userData +
137                 '}';
138     }
139 }