Skip to content

Commit f24e4f0

Browse files
authored
Merge pull request #32380 from mrsaldana/netty-transport-http-readOnlySocketExpose
Netty support for Read-Only Socket
2 parents 04ebd2e + 67978cc commit f24e4f0

File tree

3 files changed

+622
-3
lines changed

3 files changed

+622
-3
lines changed

dev/com.ibm.ws.transport.http/src/com/ibm/ws/http/netty/inbound/NettyTCPReadRequestContext.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023, 2025 IBM Corporation and others.
2+
* Copyright (c) 2023, 2026 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -11,7 +11,10 @@
1111

1212
import java.io.EOFException;
1313
import java.io.IOException;
14+
import java.net.InetAddress;
15+
import java.net.InetSocketAddress;
1416
import java.net.Socket;
17+
import java.net.SocketAddress;
1518
import java.net.SocketTimeoutException;
1619
import java.nio.ByteBuffer;
1720
import java.util.Objects;
@@ -34,6 +37,9 @@
3437
import com.ibm.wsspi.tcpchannel.TCPReadRequestContext;
3538

3639
import io.netty.channel.Channel;
40+
import io.netty.channel.socket.SocketChannel;
41+
import io.netty.channel.socket.nio.NioSocketChannel;
42+
import io.openliberty.http.netty.channel.ReadOnlySocket;
3743

3844
/**
3945
*
@@ -61,6 +67,8 @@ public class NettyTCPReadRequestContext implements TCPReadRequestContext {
6167

6268
private VirtualConnection vc = null;
6369

70+
private volatile Socket cachedSocket;
71+
6472
public NettyTCPReadRequestContext(NettyTCPConnectionContext connectionContext, Channel nettyChannel) {
6573

6674
this.connectionContext = connectionContext;
@@ -85,7 +93,10 @@ public TCPConnectionContext getInterface() {
8593

8694
@Override
8795
public Socket getSocket() {
88-
throw new UnsupportedOperationException("Can not get the socket from a Netty connection!");
96+
if(cachedSocket == null){
97+
cachedSocket = new ReadOnlySocket(nettyChannel);
98+
}
99+
return cachedSocket;
89100
}
90101

91102
/**
@@ -412,5 +423,4 @@ public void setBuffer(WsByteBuffer buf) {
412423
public void setVC(VirtualConnection vc) {
413424
this.vc = vc;
414425
}
415-
416426
}

0 commit comments

Comments
 (0)