本文整理汇总了C++中zmq::socket_t类的典型用法代码示例。如果您正苦于以下问题:C++ socket_t类的具体用法?C++ socket_t怎么用?C++ socket_t使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了socket_t类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: recv
bool recv(zmq::socket_t & socket) {
clear();
while(1) {
zmq::message_t message(0);
try {
if (!socket.recv(&message, 0)) {
return false;
}
} catch (zmq::error_t error) {
//std::cout << "E: " << error.what() << std::endl;
return false;
}
char *data = reinterpret_cast<char*>(message.data());
if (message.size() == 17 && data[0] == 0) {
push_back(encode_uuid(msg_to_string(message)));
} else {
push_back(msg_to_string(message));
}
boost::int64_t more;
size_t more_size = sizeof(more);
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
if (!more) {
break;
}
}
return true;
}
开发者ID:0000-bigtree,项目名称:nscp,代码行数:27,代码来源:zmsg.hpp
示例2: raw_sender
void
raw_sender(zmq::socket_t& s)
{
for (size_t i = 0; i < ITERS; ++i)
{
zmq::message_t msg1(ARRAY_LEN(PART1)-1);
memcpy(msg1.data(), PART1, msg1.size());
s.send(msg1, ZMQ_SNDMORE);
zmq::message_t msg2(ARRAY_LEN(PART2)-1);
memcpy(msg2.data(), PART2, msg2.size());
s.send(msg2, ZMQ_SNDMORE);
zmq::message_t msg3(ARRAY_LEN(PART3)-1);
memcpy(msg3.data(), PART3, msg3.size());
s.send(msg3);
zmq::message_t msg_res;
s.recv(&msg_res, 0);
if (i % 1000 == 0)
{
std::cout << ".";
std::cout.flush();
}
}
}
开发者ID:zmqmessage,项目名称:zmqmessage,代码行数:27,代码来源:PerfTest.cpp
示例3: socket
void OTSocket::Listen(const OTString &strBind)
{
if (NULL != m_pSocket)
delete m_pSocket;
// m_pSocket = NULL;
m_pSocket = new zmq::socket_t(*m_pContext, ZMQ_REP); // RESPONSE socket (Request / Response.)
OT_ASSERT_MSG(NULL != m_pSocket, "OTSocket::Listen: new zmq::socket(context, ZMQ_REP)");
OTString strTemp(strBind); // In case m_strBindPath is what was passed in. (It happens.)
m_strBindPath.Set(strTemp); // In case we have to close/reopen the socket to finish a send/receive.
// ------------------------
// Configure socket to not wait at close time
//
const int linger = 0; // close immediately
m_pSocket->setsockopt (ZMQ_LINGER, &linger, sizeof (linger));
/*
int zmq_setsockopt (void *socket, int option_name, const void *option_value, size_t option_len);
Caution: All options, with the exception of ZMQ_SUBSCRIBE, ZMQ_UNSUBSCRIBE and ZMQ_LINGER, only take effect for subsequent socket bind/connects.
*/
// ------------------------
m_pSocket->bind(strBind.Get());
}
开发者ID:seanmerriam,项目名称:Open-Transactions,代码行数:26,代码来源:xmlrpcxx_server.cpp
示例4: RecvMsg
/*
* return number of bytes received, negative if error, 0 for received nothing,
* which should be treated as error
*/
int32_t RecvMsg(zmq::socket_t &sock, boost::shared_array<uint8_t> &data,
bool *_more){
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt);
}catch(zmq::error_t &e){
LOG(ERROR) << "RecvMsg error = " << e.what();
return -1;
}
if(nbytes == 0) return 0;
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc &e){
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
if(_more != NULL){
int more_recv;
size_t s = sizeof(int);
sock.getsockopt(ZMQ_RCVMORE, &more_recv, &s);
*_more = (more_recv == 1) ? true : false;
}
return len;
}
开发者ID:chonglinsun,项目名称:quiltdb,代码行数:36,代码来源:zmq_util.cpp
示例5: process_frontend
void process_frontend(zmq::socket_t& frontend, int& available_workers) {
zmq::message_t req;
frontend.recv(&req);
zmq::message_t reply(sizeof(available_workers));
memcpy(reply.data(), &available_workers, sizeof(available_workers));
frontend.send(reply);
}
开发者ID:armstrtw,项目名称:deathstar.old,代码行数:7,代码来源:deathstar.status.cpp
示例6: handleOp
void handleOp(zmq::socket_t &socket, int opCode) {
std::string s_req, trace, line;
std::cout<<"Trace: ";
std::getline(std::cin, trace);
Request req;
Id id;
Person person;
Request_Header_Type type;
switch (opCode) {
case 1:
type = Request_Header_Type_LOOKUP;
std::cout<<"id: ";
line.clear();
std::getline(std::cin, line);
id = makeId(fromString<int>(line));
req = makeRequest(type, id, person, false, trace);
break;
case 3:
type = Request_Header_Type_REMOVE;
std::cout<<"id: ";
line.clear();
std::getline(std::cin, line);
id = makeId(fromString<int>(line));
req = makeRequest(type, id, person, false, trace);
break;
case 2:
{
type = Request_Header_Type_INSERT;
std::cout<<"id: ";
line.clear();
std::getline(std::cin, line);
id = makeId(fromString<int>(line));
line.clear();
std::cout<<"Name: ";
std::getline(std::cin, line);
std::string ph, ovr;
std::cout<<"Phone: ";
std::getline(std::cin, ph);
std::cout<<"Overwrite: (y/n) ";
std::getline(std::cin, ovr);
person = makePerson(line, ph);
req = makeRequest(type, id, person, ovr.compare("y") == 0,
trace);
break;
}
};
std::cout<<"Request: "<<requestToString(req);
TRACE(std::cout, "");
req.SerializeToString(&s_req);
zmq::message_t z_req(s_req.size());
memcpy(z_req.data(), (void *)s_req.data(), s_req.size());
socket.send(z_req);
zmq::message_t z_resp;
socket.recv(&z_resp);
std::string s_resp((char *)z_resp.data(), z_resp.size());
Response resp;
resp.ParseFromString(s_resp);
std::cout<<"Response = "<<responseToString(resp);
}
开发者ID:prakharsharma,项目名称:kvproxy,代码行数:59,代码来源:Client.cpp
示例7: process_status_request
// capacity request
void process_status_request(zmq::socket_t& status, int& number_of_workers) {
// null request
zmq::message_t incoming_msg;
status.recv(&incoming_msg);
// send current capacity
zmq::message_t status_msg(sizeof(number_of_workers));
memcpy(status_msg.data(), &number_of_workers, sizeof(number_of_workers));
status.send(status_msg);
}
开发者ID:armstrtw,项目名称:deathstar.core,代码行数:11,代码来源:deathstar.cpp
示例8: s_send
static bool
s_send (zmq::socket_t & socket, const char* buffer, unsigned length, bool zerocopy=false) {
if(zerocopy) {
zmq::message_t message((void *)buffer, length, NULL, NULL);
return socket.send (message);
}else {
zmq::message_t message(length);
memcpy (message.data(),buffer, length);
return socket.send (message);
}
}
开发者ID:GavinHwa,项目名称:LightQ,代码行数:11,代码来源:zhelpers.hpp
示例9: getRequest
bool Server::getRequest (zmq::socket_t &socket, pb::RequestEnvelope &envelope) {
long long more;
size_t sz = sizeof (more);
zmq::message_t request;
socket.recv (&request);
socket.getsockopt (ZMQ_RCVMORE, &more, &sz);
bool isAnotherRequest = more != 0;
envelope.ParseFromArray (request.data(), request.size());
return isAnotherRequest;
}
开发者ID:brobits,项目名称:uRPC,代码行数:12,代码来源:server.cpp
示例10: SendMove
bool ServerInterface::SendMove(enum Tetromino::Move move, int pieceId, zmq::socket_t& commandSocket) const {
std::string const* moveCommandS = m_factory.CreateMoveMessage(move, pieceId);
zmq::message_t moveCommand (moveCommandS->size());
memcpy(static_cast<void*>(moveCommand.data()), moveCommandS->data(),
moveCommandS->size());
delete moveCommandS;
commandSocket.send(moveCommand);
zmq::message_t reply;
commandSocket.recv(&reply);
std::string replyS (static_cast<char const*>(reply.data()), reply.size());
return m_factory.ParseMoveReply(replyS);
}
开发者ID:ahelwer,项目名称:pason2012,代码行数:13,代码来源:server_interface.cpp
示例11: rawSocketSend
void MessageSender::rawSocketSend( zmq::socket_t& a_socket, const std::string& a_name, const unsigned char* a_msg, size_t a_msgSize )
{
bool ok = false;
try
{
ok = a_socket.send( a_name.data(), a_name.size(), ZMQ_SNDMORE );
ok = a_socket.send( a_msg, a_msgSize );
}
catch( const zmq::error_t& ex )
{
//std::cout << __PRETTY_FUNCTION__ << " " << ex.what() << std::endl;
}
}
开发者ID:SorcererX,项目名称:SepiaStream,代码行数:13,代码来源:messagesender.cpp
示例12: s_sendmore
// Sends string as 0MQ string, as multipart non-terminal
static bool
s_sendmore (zmq::socket_t & socket, const std::string & string, bool zerocopy=false) {
zmq::message_t *pmessage = NULL;
if(zerocopy) {
zmq::message_t message ((void *)string.c_str(), string.length(), NULL, NULL);
return socket.send (message, ZMQ_SNDMORE);
}else {
zmq::message_t message(string.size());
memcpy (message.data(), string.data(), string.size());
return socket.send (message, ZMQ_SNDMORE);
}
}
开发者ID:GavinHwa,项目名称:LightQ,代码行数:15,代码来源:zhelpers.hpp
示例13: recv_multipart
void recv_multipart(zmq::socket_t &socket) {
int64_t more=-1;
size_t more_size = sizeof (more);
while(more) {
zmq::message_t response;
socket.recv(&response);
std::string response_str((const char *)response.data(),
response.size());
cout << response_str << endl;
socket.getsockopt(ZMQ_RCVMORE, &more, &more_size);
}
}
开发者ID:plq,项目名称:zmq,代码行数:14,代码来源:zmq.cpp
示例14: process_backend
// relay data from workers to frontend
void process_backend(zmq::socket_t& frontend, zmq::socket_t& backend) {
int64_t more;
size_t moresz;
moresz = sizeof(more);
while(true) {
zmq::message_t worker_msg;
backend.recv(&worker_msg);
backend.getsockopt(ZMQ_RCVMORE, &more, &moresz);
frontend.send(worker_msg, more ? ZMQ_SNDMORE : 0);
if(!more) {
break;
}
}
}
开发者ID:armstrtw,项目名称:deathstar.core,代码行数:16,代码来源:deathstar.cpp
示例15: send
/** Send empty message. */
inline bool send(zmq::socket_t &s, const empty &v, int flags)
{
zmq::message_t msg(0);
IB_FIRST_PART(s.send(msg, flags));
return true;
}
开发者ID:rickesh,项目名称:image-babble,代码行数:8,代码来源:core.hpp
示例16: s_set_id
// Set simple random printable identity on socket
//
static void
s_set_id (zmq::socket_t & socket)
{
char identity [10];
sprintf (identity, "%04X-%04X", within (0x10000), within (0x10000));
socket.setsockopt(ZMQ_IDENTITY, identity, strlen (identity));
}
开发者ID:bosoxbill,项目名称:zguide,代码行数:9,代码来源:zhelpers.hpp
示例17: receive
Message receive(zmq::socket_t& socket)
{
std::vector<std::string> address;
std::string frame = receiveString(socket);
// Do we have an address?
while (frame.compare("") != 0)
{
address.push_back(frame);
frame = receiveString(socket);
}
// address is a stack, so reverse it to get the right way around
std::reverse(address.begin(), address.end());
// We've just read the delimiter, so now get subject
auto subjectString = receiveString(socket);
//the underlying representation is (explicitly) an int so fairly safe
Subject subject = (Subject)detail::unserialise<std::uint32_t>(subjectString);
std::vector<std::string> data;
while (true)
{
int isMore = 0;
size_t moreSize = sizeof(isMore);
socket.getsockopt(ZMQ_RCVMORE, &isMore, &moreSize);
if (!isMore)
break;
data.push_back(receiveString(socket));
}
return Message(address, subject, data);
}
开发者ID:darrnshn,项目名称:stateline,代码行数:29,代码来源:transport.cpp
示例18: send
bool send (zmq::socket_t & socket, std::string const& string)
{
zmq::message_t message(string.size());
std::memcpy(message.data(), string.data(), string.size());
bool rc = socket.send(message);
return (rc);
}
开发者ID:abta,项目名称:MapQuest-Render-Stack,代码行数:7,代码来源:zmq_utils.cpp
示例19: recv
inline bool recv (zmq::socket_t & socket, tile_protocol & tile)
{
zmq::message_t msg;
socket.recv(&msg);
std::string buf(static_cast<char*>(msg.data()),msg.size());
return unserialise(buf, tile);
}
开发者ID:abta,项目名称:MapQuest-Render-Stack,代码行数:7,代码来源:tile_protocol.hpp
示例20: recv_msg_async
// 0 for received nothing
int recv_msg_async(zmq::socket_t &sock, boost::shared_array<uint8_t> &data)
{
zmq::message_t msgt;
int nbytes;
try{
nbytes = sock.recv(&msgt, ZMQ_DONTWAIT);
}catch(zmq::error_t e){
return -1;
}
if(nbytes == 0){
if(zmq_errno() == EAGAIN)
return 0;
else
return -1;
}
size_t len = msgt.size();
uint8_t *dataptr;
try{
dataptr = new uint8_t[len];
}catch(std::bad_alloc e){
return -1;
}
memcpy(dataptr, msgt.data(), len);
data.reset(dataptr);
return len;
}
开发者ID:jinliangwei,项目名称:CommTest,代码行数:30,代码来源:zmq_util.cpp
注:本文中的zmq::socket_t类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论