package hh.dejsem.net;

import java.nio.ByteBuffer;

import hh.dejsem.K;
import hh.lib.D;

public class NetSslChbIO extends NetSslChIO {
	/**----------------------------------------------------------
	 * SSL blocking network IO (SSL engine)
	 * ----------------------------------------------------------*/

	NetSslChbIO(D d) throws Exception { super(d); }

	@Override
	void wrapAndPut(ByteBuffer out, ByteBuffer in) throws Exception {
		do {
			wrap(out);
			if(sslOut.position() == 0) break;
			putSslOut();
		} while(needWrap());
		if(needUnwrap()) getAndUnwrap(in, out);
	}

	void terminateServer(ByteBuffer dataIn) throws Exception {
		closeOut();
		getAndUnwrap(dataIn, ByteBuffer.allocate(0));
		closeSocket();
	}

	@Override
	void configureSocket() throws Exception {
		sc.socket().setSoTimeout((int) K.socketTO);
		sc.configureBlocking(true);
	}
}
