use of zmq.Msg in project jeromq by zeromq.
the class ZFrame method recvFrame.
/**
* Receive a new frame off the socket, Returns newly-allocated frame, or
* null if there was no input waiting, or if the read was interrupted.
* @param socket
* Socket to read from
* @param flags
* Pass flags to 0MQ socket.recv call
* @return
* received frame, else null
*/
public static ZFrame recvFrame(Socket socket, int flags) {
final SocketBase base = socket.base();
zmq.Msg msg = base.recv(flags);
if (msg == null) {
// Check to see if there was an error in recv
socket.mayRaise();
return null;
}
ZFrame frame = new ZFrame(msg);
frame.setGroup(msg.getGroup());
return frame;
}
use of zmq.Msg in project jeromq by zeromq.
the class StreamEngine method mechanismReady.
private void mechanismReady() {
if (options.heartbeatInterval > 0) {
ioObject.addTimer(options.heartbeatInterval, HEARTBEAT_IVL_TIMER_ID);
hasHeartbeatTimer = true;
}
if (options.recvIdentity) {
Msg identity = mechanism.peerIdentity();
boolean rc = session.pushMsg(identity);
if (!rc && errno.is(ZError.EAGAIN)) {
// so we can just bail out of the identity set.
return;
}
assert (rc);
session.flush();
}
nextMsg = pullAndEncode;
processMsg = writeCredential;
// Compile metadata.
assert (metadata == null);
metadata = new Metadata();
// If we have a peer_address, add it to metadata
if (peerAddress != null && !peerAddress.address().isEmpty()) {
metadata.set(Metadata.PEER_ADDRESS, peerAddress.address());
}
// Add ZAP properties.
metadata.set(mechanism.zapProperties);
// Add ZMTP properties.
metadata.set(mechanism.zmtpProperties);
if (metadata.isEmpty()) {
metadata = null;
}
}
use of zmq.Msg in project jeromq by zeromq.
the class StreamEngine method writeCredential.
private boolean writeCredential(Msg msg) {
assert (mechanism != null);
assert (session != null);
Blob credential = mechanism.getUserId();
if (credential != null && credential.size() > 0) {
Msg cred = new Msg(credential.size());
cred.put(credential.data(), 0, credential.size());
cred.setFlags(Msg.CREDENTIAL);
boolean rc = session.pushMsg(cred);
if (!rc) {
return false;
}
}
processMsg = decodeAndPush;
return decodeAndPush.apply(msg);
}
use of zmq.Msg in project jeromq by zeromq.
the class V2Decoder method allocate.
@Override
protected Msg allocate(int size) {
Msg msg = super.allocate(size);
msg.setFlags(msgFlags);
return msg;
}
use of zmq.Msg in project jeromq by zeromq.
the class ReqSpecTest method messageFormat.
private void messageFormat(Ctx ctx, String address, int bindType, int connectType) throws IOException, InterruptedException {
// Server socket will accept connections
SocketBase req = ZMQ.socket(ctx, bindType);
assertThat(req, notNullValue());
boolean rc = ZMQ.bind(req, address);
assertThat(rc, is(true));
SocketBase router = ZMQ.socket(ctx, connectType);
assertThat(router, notNullValue());
String host = (String) ZMQ.getSocketOptionExt(req, ZMQ.ZMQ_LAST_ENDPOINT);
assertThat(host, notNullValue());
rc = ZMQ.connect(router, host);
assertThat(rc, is(true));
// Send a multi-part request.
sendSeq(req, "ABC", "DEF");
// Receive peer identity
Msg msg = ZMQ.recv(router, 0);
assertThat(msg, notNullValue());
assertThat(msg.size() > 0, is(true));
Msg peerId = msg;
int more = ZMQ.getSocketOption(router, ZMQ.ZMQ_RCVMORE);
assertThat(more, is(1));
// Receive the rest.
recvSeq(router, null, "ABC", "DEF");
// Send back a single-part reply.
int ret = ZMQ.send(router, peerId, ZMQ.ZMQ_SNDMORE);
assertThat(ret, is(peerId.size()));
sendSeq(router, null, "GHI");
// Receive reply.
recvSeq(req, "GHI");
ZMQ.closeZeroLinger(req);
ZMQ.closeZeroLinger(router);
// Wait for disconnects.
ZMQ.msleep(100);
}
Aggregations