use of zmq.Msg in project jeromq by zeromq.
the class Channel method xrecv.
@Override
protected Msg xrecv() {
if (pipe == null) {
// Initialize the output parameter to be a 0-byte message.
errno.set(ZError.EAGAIN);
return null;
}
// Drop any messages with more flag
Msg msg = pipe.read();
while (msg != null && msg.hasMore()) {
// drop all frames of the current multi-frame message
msg = pipe.read();
while (msg != null && msg.hasMore()) {
msg = pipe.read();
}
// get the new message
if (msg != null) {
msg = pipe.read();
}
}
if (msg == null) {
errno.set(ZError.EAGAIN);
return null;
}
lastIn = pipe;
return msg;
}
use of zmq.Msg in project jeromq by zeromq.
the class XSub method sendSubscription.
private boolean sendSubscription(byte[] data, int size, Pipe pipe) {
// Create the subscription message.
Msg msg = new Msg(size + 1);
msg.put((byte) 1).put(data, 0, size);
// Send it to the pipe.
boolean sent = pipe.write(msg);
return sent;
}
use of zmq.Msg in project jeromq by zeromq.
the class Rep method xrecv.
@Override
protected Msg xrecv() {
// If we are in middle of sending a reply, we cannot receive next request.
if (sendingReply) {
errno.set(ZError.EFSM);
}
Msg msg;
// to the reply pipe.
if (requestBegins) {
while (true) {
msg = super.xrecv();
if (msg == null) {
return null;
}
if (msg.hasMore()) {
// Empty message part delimits the traceback stack.
boolean bottom = (msg.size() == 0);
// Push it to the reply pipe.
boolean rc = super.xsend(msg);
assert (rc);
if (bottom) {
break;
}
} else {
// If the traceback stack is malformed, discard anything
// already sent to pipe (we're at end of invalid message).
super.rollback();
}
}
requestBegins = false;
}
// Get next message part to return to the user.
msg = super.xrecv();
if (msg == null) {
return null;
}
// If whole request is read, flip the FSM to reply-sending state.
if (!msg.hasMore()) {
sendingReply = true;
requestBegins = true;
}
return msg;
}
use of zmq.Msg in project jeromq by zeromq.
the class Pipe method processHiccup.
@Override
protected void processHiccup(YPipeBase<Msg> pipe) {
// migrated to this thread.
assert (outpipe != null);
outpipe.flush();
Msg msg;
while ((msg = outpipe.read()) != null) {
if (!msg.hasMore()) {
msgsWritten--;
}
}
// Plug in the new outpipe.
assert (pipe != null);
outpipe = pipe;
outActive = true;
// If appropriate, notify the user about the hiccup.
if (state == State.ACTIVE) {
sink.hiccuped(this);
}
}
use of zmq.Msg in project jeromq by zeromq.
the class FQ method recvPipe.
public Msg recvPipe(Errno errno, ValueReference<Pipe> pipe) {
// Round-robin over the pipes to get the next message.
while (active > 0) {
// Try to fetch new message. If we've already read part of the message
// subsequent part should be immediately available.
final Pipe currentPipe = pipes.get(current);
final Msg msg = currentPipe.read();
final boolean fetched = msg != null;
// the 'current' pointer.
if (fetched) {
if (pipe != null) {
pipe.set(currentPipe);
}
more = msg.hasMore();
if (!more) {
lastIn = currentPipe;
// happens when multiple threads receive messages
assert (active > 0);
current = (current + 1) % active;
}
return msg;
}
// we should get the remaining parts without blocking.
assert (!more);
active--;
Collections.swap(pipes, current, active);
if (current == active) {
current = 0;
}
}
// No message is available. Initialize the output parameter
// to be a 0-byte message.
errno.set(ZError.EAGAIN);
return null;
}
Aggregations