GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #30 from normanmaurer/3.2 · netty/netty@ce1643c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/main/java/org/jboss/netty
    • channel
      • ChannelEvent.java
      • ChannelLocal.java
      • SimpleChannelUpstreamHandler.java
      • socket
        • nio
          • NioAcceptedSocketChannel.java
          • NioSocketChannel.java
          • NioWorker.java
          • SocketSendBufferPool.java
        • oio
          • OioAcceptedSocketChannel.java
          • OioWorker.java
    • handler
      • ssl
        • SslHandler.java
      • timeout
        • WriteTimeoutHandler.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/org/jboss/netty/channel/ChannelEvent.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/ChannelEvent.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
* <td>{@code "channelOpen"}</td>
7272
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#OPEN OPEN}, value = {@code true})</td>
7373
* <td>a {@link Channel} is open, but not bound nor connected</td>
74+
* <td><strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong></td>
7475
* </tr>
7576
* <tr>
7677
* <td>{@code "channelClosed"}</td>
@@ -80,7 +81,8 @@
8081
* <tr>
8182
* <td>{@code "channelBound"}</td>
8283
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#BOUND BOUND}, value = {@link SocketAddress})</td>
83-
* <td>a {@link Channel} is open and bound to a local address, but not connected</td>
84+
* <td>a {@link Channel} is open and bound to a local address, but not connected.</td>
85+
* <td><strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong></td>
8486
* </tr>
8587
* <tr>
8688
* <td>{@code "channelUnbound"}</td>
@@ -91,6 +93,7 @@
9193
* <td>{@code "channelConnected"}</td>
9294
* <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#CONNECTED CONNECTED}, value = {@link SocketAddress})</td>
9395
* <td>a {@link Channel} is open, bound to a local address, and connected to a remote address</td>
96+
* <td><strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong></td>
9497
* </tr>
9598
* <tr>
9699
* <td>{@code "writeComplete"}</td>
Collapse file

‎src/main/java/org/jboss/netty/channel/ChannelLocal.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/ChannelLocal.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ChannelLocal() {
5151
* Returns the initial value of the variable. By default, it returns
5252
* {@code null}. Override it to change the initial value.
5353
*/
54-
protected T initialValue(@SuppressWarnings("unused") Channel channel) {
54+
protected T initialValue(Channel channel) {
5555
return null;
5656
}
5757

Collapse file

‎src/main/java/org/jboss/netty/channel/SimpleChannelUpstreamHandler.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/SimpleChannelUpstreamHandler.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public void exceptionCaught(
150150

151151
/**
152152
* Invoked when a {@link Channel} is open, but not bound nor connected.
153+
* <br/>
154+
*
155+
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
153156
*/
154157
public void channelOpen(
155158
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
@@ -159,6 +162,9 @@ public void channelOpen(
159162
/**
160163
* Invoked when a {@link Channel} is open and bound to a local address,
161164
* but not connected.
165+
* <br/>
166+
*
167+
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
162168
*/
163169
public void channelBound(
164170
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
@@ -168,6 +174,9 @@ public void channelBound(
168174
/**
169175
* Invoked when a {@link Channel} is open, bound to a local address, and
170176
* connected to a remote address.
177+
* <br/>
178+
*
179+
* <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong>
171180
*/
172181
public void channelConnected(
173182
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
Collapse file

‎src/main/java/org/jboss/netty/channel/socket/nio/NioAcceptedSocketChannel.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/NioAcceptedSocketChannel.java
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package org.jboss.netty.channel.socket.nio;
1717

18-
import static org.jboss.netty.channel.Channels.*;
18+
import static org.jboss.netty.channel.Channels.fireChannelBound;
19+
import static org.jboss.netty.channel.Channels.fireChannelOpen;
1920

2021
import java.nio.channels.SocketChannel;
2122

@@ -46,8 +47,8 @@ final class NioAcceptedSocketChannel extends NioSocketChannel {
4647
this.bossThread = bossThread;
4748

4849
setConnected();
50+
4951
fireChannelOpen(this);
5052
fireChannelBound(this, getLocalAddress());
51-
fireChannelConnected(this, getRemoteAddress());
5253
}
5354
}
Collapse file

‎src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.jboss.netty.channel.Channel;
3030
import org.jboss.netty.channel.ChannelFactory;
3131
import org.jboss.netty.channel.ChannelFuture;
32-
import org.jboss.netty.channel.ChannelFutureListener;
3332
import org.jboss.netty.channel.ChannelPipeline;
3433
import org.jboss.netty.channel.ChannelSink;
3534
import org.jboss.netty.channel.MessageEvent;
Collapse file

‎src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class NioWorker implements Runnable {
8282

8383
private final SocketReceiveBufferPool recvBufferPool = new SocketReceiveBufferPool();
8484
private final SocketSendBufferPool sendBufferPool = new SocketSendBufferPool();
85-
85+
8686
NioWorker(int bossId, int id, Executor executor) {
8787
this.bossId = bossId;
8888
this.id = id;
@@ -96,6 +96,7 @@ void register(NioSocketChannel channel, ChannelFuture future) {
9696
Selector selector;
9797

9898
synchronized (startStopLock) {
99+
99100
if (!started) {
100101
// Open a selector if this worker didn't start yet.
101102
try {
@@ -160,6 +161,7 @@ public void run() {
160161
}
161162

162163
try {
164+
163165
SelectorUtil.select(selector);
164166

165167
// 'wakenUp.compareAndSet(false, true)' is always evaluated
@@ -790,6 +792,12 @@ public void run() {
790792
}
791793
fireChannelConnected(channel, remoteAddress);
792794
}
795+
796+
// Handle the channelConnected in the worker thread
797+
if (channel instanceof NioAcceptedSocketChannel) {
798+
fireChannelConnected(channel, channel.getRemoteAddress());
799+
800+
}
793801
}
794802
}
795803
}
Collapse file

‎src/main/java/org/jboss/netty/channel/socket/nio/SocketSendBufferPool.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/SocketSendBufferPool.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ public long transferTo(DatagramChannel ch, SocketAddress raddr)
288288
}
289289

290290
public void release() {
291-
// Unpooled.
291+
// Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar
292+
file.releaseExternalResources();
292293
}
293294
}
294295

Collapse file

‎src/main/java/org/jboss/netty/channel/socket/oio/OioAcceptedSocketChannel.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/oio/OioAcceptedSocketChannel.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616
package org.jboss.netty.channel.socket.oio;
1717

18-
import static org.jboss.netty.channel.Channels.*;
18+
import static org.jboss.netty.channel.Channels.fireChannelBound;
19+
import static org.jboss.netty.channel.Channels.fireChannelOpen;
1920

2021
import java.io.IOException;
2122
import java.io.OutputStream;
@@ -60,10 +61,9 @@ class OioAcceptedSocketChannel extends OioSocketChannel {
6061
} catch (IOException e) {
6162
throw new ChannelException("Failed to obtain an OutputStream.", e);
6263
}
63-
64+
6465
fireChannelOpen(this);
6566
fireChannelBound(this, getLocalAddress());
66-
fireChannelConnected(this, getRemoteAddress());
6767
}
6868

6969
@Override
Collapse file

‎src/main/java/org/jboss/netty/channel/socket/oio/OioWorker.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/oio/OioWorker.java
+39-4Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
import java.io.OutputStream;
2121
import java.io.PushbackInputStream;
2222
import java.net.SocketException;
23+
import java.nio.channels.Channels;
2324
import java.nio.channels.ClosedChannelException;
25+
import java.nio.channels.WritableByteChannel;
2426
import java.util.regex.Pattern;
2527

2628
import org.jboss.netty.buffer.ChannelBuffer;
2729
import org.jboss.netty.channel.Channel;
2830
import org.jboss.netty.channel.ChannelFuture;
31+
import org.jboss.netty.channel.FileRegion;
2932

3033
/**
3134
*
@@ -50,7 +53,13 @@ public void run() {
5053
channel.workerThread = Thread.currentThread();
5154
final PushbackInputStream in = channel.getInputStream();
5255

56+
boolean fireConnected = channel instanceof OioAcceptedSocketChannel;
57+
5358
while (channel.isOpen()) {
59+
if (fireConnected) {
60+
fireConnected = false;
61+
fireChannelConnected(channel, channel.getRemoteAddress());
62+
}
5463
synchronized (channel.interestOpsLock) {
5564
while (!channel.isReadable()) {
5665
try {
@@ -113,13 +122,39 @@ static void write(
113122
}
114123

115124
try {
116-
ChannelBuffer a = (ChannelBuffer) message;
117-
int length = a.readableBytes();
118-
synchronized (out) {
119-
a.getBytes(a.readerIndex(), out, length);
125+
int length = 0;
126+
127+
// Add support to write a FileRegion. This in fact will not give any performance gain but at least it not fail and
128+
// we did the best to emulate it
129+
if (message instanceof FileRegion) {
130+
FileRegion fr = (FileRegion) message;
131+
try {
132+
synchronized (out) {
133+
WritableByteChannel bchannel = Channels.newChannel(out);
134+
135+
long i = 0;
136+
while ((i = fr.transferTo(bchannel, length)) > 0) {
137+
length += i;
138+
if (length >= fr.getCount()) {
139+
break;
140+
}
141+
}
142+
}
143+
} finally {
144+
fr.releaseExternalResources();
145+
146+
}
147+
} else {
148+
ChannelBuffer a = (ChannelBuffer) message;
149+
length = a.readableBytes();
150+
synchronized (out) {
151+
a.getBytes(a.readerIndex(), out, length);
152+
}
120153
}
154+
121155
fireWriteComplete(channel, length);
122156
future.setSuccess();
157+
123158
} catch (Throwable t) {
124159
// Convert 'SocketException: Socket closed' to
125160
// ClosedChannelException.
Collapse file

‎src/main/java/org/jboss/netty/handler/ssl/SslHandler.java‎

Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/handler/ssl/SslHandler.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public ChannelFuture handshake() {
370370
* @deprecated Use {@link #handshake()} instead.
371371
*/
372372
@Deprecated
373-
public ChannelFuture handshake(@SuppressWarnings("unused") Channel channel) {
373+
public ChannelFuture handshake(Channel channel) {
374374
return handshake();
375375
}
376376

@@ -394,7 +394,7 @@ public ChannelFuture close() {
394394
* @deprecated Use {@link #close()} instead.
395395
*/
396396
@Deprecated
397-
public ChannelFuture close(@SuppressWarnings("unused") Channel channel) {
397+
public ChannelFuture close(Channel channel) {
398398
return close();
399399
}
400400

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.