use of zmq.Msg in project jeromq by zeromq.
the class StreamEngine method producePingMessage.
private Msg producePingMessage() {
assert (mechanism != null);
Msg msg = new Msg(7 + heartbeatContext.length);
msg.setFlags(Msg.COMMAND);
msg.putShortString("PING");
Wire.putUInt16(msg, options.heartbeatTtl);
msg.put(heartbeatContext);
msg = mechanism.encode(msg);
nextMsg = pullAndEncode;
if (!hasTimeoutTimer && heartbeatTimeout > 0) {
ioObject.addTimer(heartbeatTimeout, HEARTBEAT_TIMEOUT_TIMER_ID);
hasTimeoutTimer = true;
}
return msg;
}
use of zmq.Msg in project jeromq by zeromq.
the class StreamEngine method error.
// Function to handle network disconnections.
private void error(ErrorReason error) {
if (options.rawSocket) {
// For raw sockets, send a final 0-length message to the application
// so that it knows the peer has been disconnected.
Msg terminator = new Msg();
processMsg.apply(terminator);
}
assert (session != null);
socket.eventDisconnected(endpoint, fd);
session.flush();
session.engineError(!handshaking && (mechanism == null || mechanism.status() != Mechanism.Status.HANDSHAKING), error);
unplug();
destroy();
}
use of zmq.Msg in project jeromq by zeromq.
the class StreamEngine method restartInput.
@Override
public void restartInput() {
assert (inputStopped);
assert (session != null);
assert (decoder != null);
Msg msg = decoder.msg();
if (!processMsg.apply(msg)) {
if (errno.is(ZError.EAGAIN)) {
session.flush();
} else {
error(ErrorReason.PROTOCOL);
}
return;
}
boolean decodingSuccess = decodeCurrentInputs();
if (!decodingSuccess && errno.is(ZError.EAGAIN)) {
session.flush();
} else if (ioError) {
error(ErrorReason.CONNECTION);
} else if (!decodingSuccess) {
error(ErrorReason.PROTOCOL);
} else {
inputStopped = false;
ioObject.setPollIn(handle);
session.flush();
// Speculative read.
inEvent();
}
}
use of zmq.Msg in project jeromq by zeromq.
the class StreamEngine method pullAndEncode.
private Msg pullAndEncode() {
assert (mechanism != null);
Msg msg = session.pullMsg();
if (msg == null) {
return null;
}
msg = mechanism.encode(msg);
return msg;
}
use of zmq.Msg in project jeromq by zeromq.
the class V1EncoderTest method testReaderLong.
@Test
public void testReaderLong() {
Msg msg = readLongMessage1();
ValueReference<ByteBuffer> ref = new ValueReference<>();
int outsize = encoder.encode(ref, 0);
assertThat(outsize, is(0));
ByteBuffer out = ref.get();
assertThat(out, nullValue());
encoder.loadMsg(msg);
outsize = encoder.encode(ref, 64);
assertThat(outsize, is(64));
out = ref.get();
int position = out.position();
int limit = out.limit();
assertThat(limit, is(64));
assertThat(position, is(64));
ref.set(null);
outsize = encoder.encode(ref, 64);
assertThat(outsize, is(138));
out = ref.get();
position = out.position();
limit = out.limit();
assertThat(position, is(62));
assertThat(limit, is(200));
}
Aggregations