public byte receive() throws EdbcEx { int msg_id; if (trace.enabled(3)) trace.write(title + ": reading next message"); /* ** Check to see if message header is in the input ** buffer (handles message concatenation). */ while (in.avail() < 8) { short tl_id; /* ** Headers are not split across continued messages. ** Data remaining in the current buffer indicates ** a message processing error. */ if (in.avail() > 0) { if (trace.enabled(1)) trace.write(title + ": invalid header length " + in.avail() + " bytes"); disconnect(); throw EdbcEx.get(E_IO0002_PROTOCOL_ERR); } try { tl_id = in.receive(); } catch (EdbcEx ex) { disconnect(); throw ex; } if (tl_id != JDBC_TL_DT) { if (trace.enabled(1)) trace.write(title + ": invalid TL packet ID 0x" + Integer.toHexString(tl_id)); disconnect(); throw EdbcEx.get(E_IO0002_PROTOCOL_ERR); } } /* ** Read and validate message header. */ if ((msg_id = in.readInt()) != JDBC_MSG_ID) { if (trace.enabled(1)) trace.write(title + ": invalid header ID 0x" + Integer.toHexString(msg_id)); disconnect(); throw EdbcEx.get(E_IO0002_PROTOCOL_ERR); } in_msg_len = in.readShort(); in_msg_id = in.readByte(); in_msg_flg = in.readByte(); if (trace.enabled(2)) trace.write( title + ": received message " + IdMap.map(in_msg_id, MsgConst.msgMap) + " length " + in_msg_len + ((in_msg_flg & JDBC_MSG_EOD) == 0 ? "" : " EOD") + ((in_msg_flg & JDBC_MSG_EOG) == 0 ? "" : " EOG")); return (in_msg_id); } // receive