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.buffer.ByteBufAllocator;
19  import io.netty.channel.Channel;
20  import io.netty.channel.ChannelOption;
21  import io.netty.channel.DefaultChannelConfig;
22  import io.netty.channel.MessageSizeEstimator;
23  import io.netty.channel.RecvByteBufAllocator;
24  import io.netty.channel.WriteBufferWaterMark;
25  
26  import java.util.Map;
27  
28  abstract class IOUringChannelConfig extends DefaultChannelConfig {
29      private volatile boolean pollInFirst = true;
30      private volatile boolean ioseqAsync;
31  
32      IOUringChannelConfig(Channel channel) {
33          super(channel);
34      }
35  
36      IOUringChannelConfig(Channel channel, RecvByteBufAllocator allocator) {
37          super(channel, allocator);
38      }
39  
40      @Override
41      public Map<ChannelOption<?>, Object> getOptions() {
42          return getOptions(super.getOptions(), IoUringChannelOption.POLLIN_FIRST, IoUringChannelOption.IOSQE_ASYNC);
43      }
44  
45      @SuppressWarnings("unchecked")
46      @Override
47      public <T> T getOption(ChannelOption<T> option) {
48          if (option == IoUringChannelOption.POLLIN_FIRST) {
49              return (T) Boolean.valueOf(pollInFirst);
50          }
51          if (option == IoUringChannelOption.IOSQE_ASYNC) {
52              return (T) Boolean.valueOf(ioseqAsync);
53          }
54          return super.getOption(option);
55      }
56  
57      @Override
58      public <T> boolean setOption(ChannelOption<T> option, T value) {
59          validate(option, value);
60  
61          if (option == IoUringChannelOption.POLLIN_FIRST) {
62              setPollInFirst((Boolean) value);
63          } else if (option == IoUringChannelOption.IOSQE_ASYNC) {
64              setIoseqAsync((Boolean) value);
65          } else {
66              return super.setOption(option, value);
67          }
68  
69          return true;
70      }
71  
72      boolean getPollInFirst() {
73          return pollInFirst;
74      }
75  
76      void setPollInFirst(boolean pollInFirst) {
77          this.pollInFirst = pollInFirst;
78      }
79  
80      boolean getIoseqAsync() {
81          return ioseqAsync;
82      }
83  
84      void setIoseqAsync(boolean ioseqAsync) {
85          this.ioseqAsync = ioseqAsync;
86      }
87  
88      @Override
89      public IOUringChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis) {
90          super.setConnectTimeoutMillis(connectTimeoutMillis);
91          return this;
92      }
93  
94      @Override
95      @Deprecated
96      public IOUringChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead) {
97          super.setMaxMessagesPerRead(maxMessagesPerRead);
98          return this;
99      }
100 
101     @Override
102     public IOUringChannelConfig setWriteSpinCount(int writeSpinCount) {
103         super.setWriteSpinCount(writeSpinCount);
104         return this;
105     }
106 
107     @Override
108     public IOUringChannelConfig setAllocator(ByteBufAllocator allocator) {
109         super.setAllocator(allocator);
110         return this;
111     }
112 
113     @Override
114     public IOUringChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator) {
115         super.setRecvByteBufAllocator(allocator);
116         return this;
117     }
118 
119     @Override
120     public IOUringChannelConfig setAutoRead(boolean autoRead) {
121         super.setAutoRead(autoRead);
122         return this;
123     }
124 
125     @Override
126     public IOUringChannelConfig setAutoClose(boolean autoClose) {
127         super.setAutoClose(autoClose);
128         return this;
129     }
130 
131     @Override
132     @Deprecated
133     public IOUringChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark) {
134         super.setWriteBufferHighWaterMark(writeBufferHighWaterMark);
135         return this;
136     }
137 
138     @Override
139     @Deprecated
140     public IOUringChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark) {
141         super.setWriteBufferLowWaterMark(writeBufferLowWaterMark);
142         return this;
143     }
144 
145     @Override
146     public IOUringChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark) {
147         super.setWriteBufferWaterMark(writeBufferWaterMark);
148         return this;
149     }
150 
151     @Override
152     public IOUringChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator) {
153         super.setMessageSizeEstimator(estimator);
154         return this;
155     }
156 }