use of io.vertx.core.net.impl.NetSocketImpl in project vert.x by eclipse.
the class ClientConnection method createNetSocket.
public NetSocket createNetSocket() {
// connection was upgraded to raw TCP socket
NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, client.getSslHelper(), metrics);
socket.metric(metric());
Map<Channel, NetSocketImpl> connectionMap = new HashMap<>(1);
connectionMap.put(channel, socket);
// Flush out all pending data
endReadAndFlush();
// remove old http handlers and replace the old handler with one that handle plain sockets
ChannelPipeline pipeline = channel.pipeline();
ChannelHandler inflater = pipeline.get(HttpContentDecompressor.class);
if (inflater != null) {
pipeline.remove(inflater);
}
pipeline.remove("codec");
pipeline.replace("handler", "handler", new VertxNetHandler<NetSocketImpl>(channel, socket, connectionMap) {
@Override
public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception {
// remove from the real mapping
pool.removeChannel(channel);
super.exceptionCaught(chctx, t);
}
@Override
public void channelInactive(ChannelHandlerContext chctx) throws Exception {
// remove from the real mapping
pool.removeChannel(channel);
super.channelInactive(chctx);
}
@Override
public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception {
if (msg instanceof HttpContent) {
if (msg instanceof LastHttpContent) {
handleResponseEnd((LastHttpContent) msg);
}
ReferenceCountUtil.release(msg);
return;
}
super.channelRead(chctx, msg);
}
@Override
protected void handleMsgReceived(Object msg) {
ByteBuf buf = (ByteBuf) msg;
conn.handleDataReceived(Buffer.buffer(buf));
}
});
return socket;
}
use of io.vertx.core.net.impl.NetSocketImpl in project vert.x by eclipse.
the class ServerConnection method createNetSocket.
NetSocket createNetSocket() {
NetSocketImpl socket = new NetSocketImpl(vertx, channel, context, server.getSslHelper(), metrics);
socket.metric(metric());
Map<Channel, NetSocketImpl> connectionMap = new HashMap<>(1);
connectionMap.put(channel, socket);
// Flush out all pending data
endReadAndFlush();
// remove old http handlers and replace the old handler with one that handle plain sockets
ChannelPipeline pipeline = channel.pipeline();
ChannelHandler compressor = pipeline.get(HttpChunkContentCompressor.class);
if (compressor != null) {
pipeline.remove(compressor);
}
pipeline.remove("httpDecoder");
if (pipeline.get("chunkedWriter") != null) {
pipeline.remove("chunkedWriter");
}
channel.pipeline().replace("handler", "handler", new VertxNetHandler<NetSocketImpl>(channel, socket, connectionMap) {
@Override
public void exceptionCaught(ChannelHandlerContext chctx, Throwable t) throws Exception {
// remove from the real mapping
server.removeChannel(channel);
super.exceptionCaught(chctx, t);
}
@Override
public void channelInactive(ChannelHandlerContext chctx) throws Exception {
// remove from the real mapping
server.removeChannel(channel);
super.channelInactive(chctx);
}
@Override
public void channelRead(ChannelHandlerContext chctx, Object msg) throws Exception {
if (msg instanceof HttpContent) {
ReferenceCountUtil.release(msg);
return;
}
super.channelRead(chctx, msg);
}
@Override
protected void handleMsgReceived(Object msg) {
ByteBuf buf = (ByteBuf) msg;
conn.handleDataReceived(Buffer.buffer(buf));
}
});
// check if the encoder can be removed yet or not.
if (lastWriteFuture == null) {
channel.pipeline().remove("httpEncoder");
} else {
lastWriteFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
channel.pipeline().remove("httpEncoder");
}
});
}
return socket;
}
Aggregations