ZeroMQ:zmq_recv() v/s zmq_msg_recv() 调用之间有什么区别?
ZeroMQ: what is a difference between zmq_recv() v/s zmq_msg_recv() calls?
zmq_recv
和zmq_msg_recv
除了return的结构外,还有什么区别吗?哪个应该与 ZMQ_PAIR
插座一起使用?
此问题针对 ZeroMQ 版本 4.2.1。
更简单的部分:ZMQ_PAIR
& 所有其他原型都可以同时使用
分离原则有助于所有当前的高级可扩展正式通信模式 ({ PAIR | PULL | REQ | REP | XREP | XREQ | SUB | ... }
) 忽略有关公开供程序员使用的服务的细节 "across them" 并将它们视为一组受支持的外部用例。
这意味着可以使用:简单的 buf []
装备 aRetCODE = zmq_recv(...);
或调用 aRetCODE = zmq_msg_recv(...)
,其中 有点复杂,预烘焙 zmq_msg_t
对象应该准备好并传递给内部处理。
如果在后一个用例中未能很好地完成所有操作,可能会返回一个错误标志 (aRetCODE == -1
) 并在 [=38= 中设置详细信息]errno == EFAULT
-- 这是错误代码的一个实例,解释为:
EFAULT
The message passed to the function was invalid.
所以这两个调用具有完全相同的 return 值逻辑。
区别在于调用签名 - 传递的参数
int zmq_recv ( void *socket, // yes, The Socket
void *buf, // a Buffer[] - byREF-> A STORAGE
size_t len, // a Buffer length
int flags // ZMQ details { ZMQ_NOBLOCK | ... }
);
更简单的一种是直截了当的,几乎是不言自明的。
如上所述,另一个需要更加小心:
zmq_msg_t aMsgSTRUCT; // first: create aMsgSTRUCT
int rc = zmq_msg_init( &aMsgSTRUCT );// next: try intitialise it ( internality )
assert (rc == 0); // test: if things went well ( use this style, even when it has no error-code associated here, with zmq_msg_init() )
rc = zmq_msg_recv( &aMsgSTRUCT, aSocket, ZMQ_NOBLOCK );
assert (rc != -1); // test: if things went well
... // process: rc-bytes in aMsgSTRUCT
.. //
. //
/* ALWAYS: */ zmq_msg_close( &aMsgSTRUCT );// finally: control dispose off
/* Release EACH message,
these are
not re-usable and
require ZeroMQ internalities
to take due care to release
all their allocated resources
*/
zmq_recv
和zmq_msg_recv
除了return的结构外,还有什么区别吗?哪个应该与 ZMQ_PAIR
插座一起使用?
此问题针对 ZeroMQ 版本 4.2.1。
更简单的部分:ZMQ_PAIR
& 所有其他原型都可以同时使用
分离原则有助于所有当前的高级可扩展正式通信模式 ({ PAIR | PULL | REQ | REP | XREP | XREQ | SUB | ... }
) 忽略有关公开供程序员使用的服务的细节 "across them" 并将它们视为一组受支持的外部用例。
这意味着可以使用:简单的 buf []
装备 aRetCODE = zmq_recv(...);
或调用 aRetCODE = zmq_msg_recv(...)
,其中 有点复杂,预烘焙 zmq_msg_t
对象应该准备好并传递给内部处理。
如果在后一个用例中未能很好地完成所有操作,可能会返回一个错误标志 (aRetCODE == -1
) 并在 [=38= 中设置详细信息]errno == EFAULT
-- 这是错误代码的一个实例,解释为:
EFAULT
The message passed to the function was invalid.
所以这两个调用具有完全相同的 return 值逻辑。
区别在于调用签名 - 传递的参数
int zmq_recv ( void *socket, // yes, The Socket
void *buf, // a Buffer[] - byREF-> A STORAGE
size_t len, // a Buffer length
int flags // ZMQ details { ZMQ_NOBLOCK | ... }
);
更简单的一种是直截了当的,几乎是不言自明的。
如上所述,另一个需要更加小心:
zmq_msg_t aMsgSTRUCT; // first: create aMsgSTRUCT
int rc = zmq_msg_init( &aMsgSTRUCT );// next: try intitialise it ( internality )
assert (rc == 0); // test: if things went well ( use this style, even when it has no error-code associated here, with zmq_msg_init() )
rc = zmq_msg_recv( &aMsgSTRUCT, aSocket, ZMQ_NOBLOCK );
assert (rc != -1); // test: if things went well
... // process: rc-bytes in aMsgSTRUCT
.. //
. //
/* ALWAYS: */ zmq_msg_close( &aMsgSTRUCT );// finally: control dispose off
/* Release EACH message,
these are
not re-usable and
require ZeroMQ internalities
to take due care to release
all their allocated resources
*/