All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webpieces.http2client.impl.Layer3Outgoing Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package org.webpieces.http2client.impl;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

import org.webpieces.http2client.api.Http2Socket;
import org.webpieces.nio.api.channels.TCPChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.webpieces.http2engine.api.client.ClientEngineListener;
import com.webpieces.http2engine.api.error.ShutdownConnection;
import com.webpieces.http2parser.api.dto.lib.Http2Frame;

public class Layer3Outgoing implements ClientEngineListener {
	
	private static final Logger log = LoggerFactory.getLogger(Layer3Outgoing.class);
	private TCPChannel channel;
	
	public Layer3Outgoing(TCPChannel channel, Http2Socket socket) {
		this.channel = channel;
	}

	@Override
	public CompletableFuture sendToSocket(ByteBuffer data) {
		if(log.isTraceEnabled())
			log.trace(channel+"writing out data to socket size="+data.remaining());
		return channel.write(data)
						.thenApply(c -> null);
	}

	public void sendPreface(ByteBuffer buf) {
		channel.write(buf);
	}

	public CompletableFuture connect(InetSocketAddress addr, Layer1Incoming incoming) {
		return channel.connect(addr, incoming);
	}

	public CompletableFuture close() {
		return channel.close();
	}

	@Override
	public void sendControlFrameToClient(Http2Frame lowLevelFrame) {
	}

	@Override
	public void engineClosedByFarEnd() {
	}
	
	@Override
	public void closeSocket(ShutdownConnection reason) {
		channel.close();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy