Search in sources :

Example 6 with ProxyBufferImpl

use of io.mycat.proxy.buffer.ProxyBufferImpl in project Mycat2 by MyCATApache.

the class MySQLClientSession method writeCurrentProxyPacket.

/**
 * newCurrentProxyPacket的配套方法,把该方法构造的报文写入通道
 */
public void writeCurrentProxyPacket(MySQLPacket ogrin, int packetId) throws IOException {
    ProxyBufferImpl mySQLPacket1 = (ProxyBufferImpl) ogrin;
    ByteBuffer buffer = mySQLPacket1.currentByteBuffer();
    int packetEndPos = buffer.position();
    int payloadLen = buffer.position() - 4;
    if (payloadLen < MySQLPacketSplitter.MAX_PACKET_SIZE) {
        ogrin.putFixInt(0, 3, payloadLen);
        ogrin.putByte(3, (byte) packetId);
        ProxyBuffer packet1 = (ProxyBuffer) ogrin;
        packet1.channelWriteStartIndex(0);
        packet1.channelWriteEndIndex(packetEndPos);
        writeToChannel();
    } else {
        throw new MycatException("unsupport max packet {}", MySQLPacketSplitter.MAX_PACKET_SIZE);
    }
}
Also used : ProxyBufferImpl(io.mycat.proxy.buffer.ProxyBufferImpl) MycatException(io.mycat.MycatException) ProxyBuffer(io.mycat.beans.mysql.packet.ProxyBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ProxyBufferImpl (io.mycat.proxy.buffer.ProxyBufferImpl)6 MycatException (io.mycat.MycatException)3 MySQLPacket (io.mycat.beans.mysql.packet.MySQLPacket)3 ProxyBuffer (io.mycat.beans.mysql.packet.ProxyBuffer)2 ByteBuffer (java.nio.ByteBuffer)2 ResultSetCallBack (io.mycat.proxy.callback.ResultSetCallBack)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1