当前位置: 首页>>代码示例>>C++>>正文


C++ zmq_setsockopt函数代码示例

本文整理汇总了C++中zmq_setsockopt函数的典型用法代码示例。如果您正苦于以下问题:C++ zmq_setsockopt函数的具体用法?C++ zmq_setsockopt怎么用?C++ zmq_setsockopt使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了zmq_setsockopt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Log_init

int Log_init(bstring access_log, bstring log_spec)
{
    int rc = 0;
    LogConfig *config = NULL;

    if(LOG_SOCKET == NULL) 
    {
        check(ZMQ_CTX, "No ZMQ context, cannot start access log.");

        if(Setting_get_int("disable.access_logging", 0))
        {
            log_info("Access log is disabled according to disable.access_logging.");
        } 
        else 
        {
            config = LogConfig_create(access_log, log_spec);
            check(config, "Failed to configure access logging.");

            LOG_SOCKET = zmq_socket(ZMQ_CTX, ZMQ_PUB);
            check(LOG_SOCKET != NULL, "Failed to create access log socket");

#ifdef ZMQ_LINGER
            int opt = 0;
            rc = zmq_setsockopt(LOG_SOCKET, ZMQ_LINGER, &opt, sizeof(opt));
            check(rc == 0, "Could not set the linger option.");
#endif

            rc = zmq_bind(LOG_SOCKET, bdata(log_spec));
            check(rc == 0, "Failed to bind access_log zeromq socket.");

            pthread_create(&LOG_THREAD, NULL, Log_internal_thread, config);
        }
    }

    return 0;
error:

    LogConfig_destroy(config);
    return -1;
}
开发者ID:304471720,项目名称:mongrel2,代码行数:40,代码来源:log.c

示例2: stop_monitor

int zmq::socket_base_t::monitor (const char *addr_, int events_)
{
    if (unlikely (ctx_terminated)) {
        errno = ETERM;
        return -1;
    }
    //  Support deregistering monitoring endpoints as well
    if (addr_ == NULL) {
        stop_monitor ();
        return 0;
    }
    //  Parse addr_ string.
    std::string protocol;
    std::string address;
    if (parse_uri (addr_, protocol, address) || check_protocol (protocol))
        return -1;

    //  Event notification only supported over inproc://
    if (protocol != "inproc") {
        errno = EPROTONOSUPPORT;
        return -1;
    }
    //  Register events to monitor
    monitor_events = events_;
    monitor_socket = zmq_socket (get_ctx (), ZMQ_PAIR);
    if (monitor_socket == NULL)
        return -1;

    //  Never block context termination on pending event messages
    int linger = 0;
    int rc = zmq_setsockopt (monitor_socket, ZMQ_LINGER, &linger, sizeof (linger));
    if (rc == -1)
        stop_monitor ();

    //  Spawn the monitor socket endpoint
    rc = zmq_bind (monitor_socket, addr_);
    if (rc == -1)
         stop_monitor ();
    return rc;
}
开发者ID:HJoYer,项目名称:libzmq,代码行数:40,代码来源:socket_base.cpp

示例3: zmq_setsockopt

void throttleObject::sendLoginRegisterToThrottle(const string& ip,unsigned short manager_port)
{
    if(!m_connectorLoginToThro)
    {        
        managerProPackage::send(m_sendLHRToThrottleHandler, managerProtocol_messageTrans_CONNECTOR
            , managerProtocol_messageType_LOGIN_REQ, ip, manager_port);
        g_manager_logger->info("[login req][connector -> throttle]:{0},{1:d}", m_throttle_ip, m_throttle_managerPort);		
        return;
    }
    for(auto it = m_throSubKey_list.begin(); it != m_throSubKey_list.end(); it++)
    {
        throSubKeyObject* subKeyObject = *it;
        if(subKeyObject == NULL) continue;
        string& key = subKeyObject->get_throSubKey();
        if(key.empty()) continue;
        if(subKeyObject->get_throSubscribed() == false)
        {
            //if don't setsockopt with ZMQ_SUBSCRIBE option,this zmq_socket will recv nothing !!!
            for(auto it=m_recvAdReqVector.begin(); it != m_recvAdReqVector.end(); it++)
            {
                recvAdReq_t *obj = *it;
                int rc = zmq_setsockopt(obj->m_recvAdReqFromThrottleHandler,ZMQ_SUBSCRIBE,key.c_str(),key.size());
                if(rc == 0)
                {
                    subKeyObject->set_throSubscribed(true);
                    g_manager_logger->info("[add ZMQ_SUBSCRIBE]: {0}",key);
                    cout << "[add ZMQ_SUBSCRIBE]: " << key << endl;
                }    
            }
                           
        }
        if(subKeyObject->get_throRegisted() == false)
        {
            managerProPackage::send(m_sendLHRToThrottleHandler, managerProtocol_messageTrans_CONNECTOR
               , managerProtocol_messageType_REGISTER_REQ, key, ip, manager_port);
            g_manager_logger->info("[register req][connector -> throttle]:{0},{1:d}", m_throttle_ip, m_throttle_managerPort);   
            cout << "[register req][connector -> throttle]!" << endl;
        }
    }
}
开发者ID:penghuijun,项目名称:backupSys,代码行数:40,代码来源:throttleManager.cpp

示例4: main

int main(void)
{
    // connect to task ventilator
    void *context = zmq_ctx_new();
    void *receiver = zmq_socket(context, ZMQ_PULL);
    zmq_connect(receiver, "tcp://localhost:5557");

    // connect to weather server
    void *subscriber = zmq_socket(context, ZMQ_SUB);
    zmq_connect(subscriber, "tcp://localhost:5556");
    zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "", 0);

    // Process messages from both sockets
    while (1) {
        char msg[256];
        zmq_pollitem_t items[] = {
                { receiver, 0, ZMQ_POLLIN, 0 },
                { subscriber, 0, ZMQ_POLLIN, 0 },
        };
        zmq_poll(items, 2, -1);
        if (items[0].revents & ZMQ_POLLIN) {
            int size = zmq_recv(receiver, msg, 255, 0);
            if (size != -1) {
                break;
            }
        }
        if (items[1].revents & ZMQ_POLLIN) {
            //int size = zmq_recv(subscriber, msg, 255, 0);
            char *msg = s_recv(subscriber);
            if (msg != NULL) {
                // process weather update
                puts(msg);
                free(msg);
            }
        }
    }
    zmq_close(subscriber);
    zmq_ctx_destroy(context);
    return 0;
}
开发者ID:a524631266,项目名称:Ongoing-Study,代码行数:40,代码来源:mspoller.c

示例5: main

int main(void)
{
        void *context = zmq_ctx_new();

        void *receiver = zmq_socket(context, ZMQ_PULL);
        zmq_connect(receiver, "tcp://localhost:5557");

        void *subscriber = zmq_socket(context, ZMQ_SUB);
        zmq_connect(subscriber, "tcp://localhost:5556");
        zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "10001 ", 6);

        zmq_pollitem_t items[] = {
                {receiver, 0, ZMQ_POLLIN, 0},
                {subscriber, 0, ZMQ_POLLIN, 0},
        };

        while(1) {
                zmq_msg_t message;
                zmq_poll(items, 2, -1);
                if (items[0].revents & ZMQ_POLLIN) {
                        zmq_msg_init(&message);
                        zmq_msg_recv(&message, receiver, 0);

                        printf("receiver: %s\n", (char *)zmq_msg_data(&message));
                        zmq_msg_close(&message);
                }
                if (items[1].revents & ZMQ_POLLIN) {
                        zmq_msg_init(&message);
                        zmq_msg_recv(&message, subscriber, 0);

                        printf("subscribe: %s\n", (char *)zmq_msg_data(&message));
                        zmq_msg_close(&message);
                }
        }

        zmq_close(receiver);
        zmq_close(subscriber);
        zmq_ctx_destroy(context);
        return 0;
}
开发者ID:github188,项目名称:doc-1,代码行数:40,代码来源:msreader.c

示例6: main

int main(int argc, char *argv []) {
    void *context, *socket;
    char *topic, *string;
    int64_t more;
    
    if (argc < 2) {
        fprintf(stderr, "USAGE: zmq_echo <address> [topic]\n");
        return 1;
    }

    context = zmq_init(1);

    printf("connecting to %s...\n", argv[1]);
    socket = zmq_socket(context, ZMQ_SUB);
    zmq_connect(socket, argv[1]);
    
    if (argc > 2) {
        topic = argv[2];
        printf("subscribing to \"%s\" topic...\n", topic);
    } else {
        topic = "";
        printf("subscribing to all topics...\n");
    }
    zmq_setsockopt(socket, ZMQ_SUBSCRIBE, topic, strlen(topic));
    
    printf(">> ");
    fflush(stdout);
    
    while (1) {
        string = zmq_recv_string(socket, &more);
        printf(more ? "%s" : "%s\n>> ", string);
        fflush(stdout);
        free(string);
    }

    zmq_close(socket);
    zmq_term(context);

    return 0;
}
开发者ID:antonrogov,项目名称:zmq-tools,代码行数:40,代码来源:zmq_echo.c

示例7: Java_org_zeromq_ZMQ_00024Socket_setBytesSockopt

/**
 * Called by Java's Socket::setBytesSockopt(int option, byte[] value).
 */
JNIEXPORT void JNICALL Java_org_zeromq_ZMQ_00024Socket_setBytesSockopt (JNIEnv *env,
                                                                        jobject obj,
                                                                        jint option,
                                                                        jbyteArray value)
{
    switch (option) {
#if (ZMQ_VERSION_MAJOR <= 3)
    case ZMQ_IDENTITY:
#endif
    case ZMQ_SUBSCRIBE:
    case ZMQ_UNSUBSCRIBE:
        {
            if (value == NULL) {
                raise_exception (env, EINVAL);
                return;
            }

            void *s = get_socket (env, obj, 1);

            jbyte *optval = env->GetByteArrayElements (value, NULL);
            if (! optval) {
                raise_exception (env, EINVAL);
                return;
            }
            size_t optvallen = env->GetArrayLength (value);
            int rc = zmq_setsockopt (s, option, optval, optvallen);
            int err = zmq_errno();
            env->ReleaseByteArrayElements (value, optval, 0);
            if (rc != 0) {
                raise_exception (env, err);
            }

            return;
        }
    default:
        raise_exception (env, EINVAL);
        return;
    }
}
开发者ID:azinman,项目名称:jzmq,代码行数:42,代码来源:Socket.cpp

示例8: main

int main(void)
{
    struct heartbeat_socket_info * receiver;
    struct heartbeat_socket_info * subscriber;

    receiver = heartbeat_connect_socket(ZMQ_PULL, "tcp://localhost:5557");
    subscriber = heartbeat_connect_socket(ZMQ_SUB, "tcp://localhost:5556");
    zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, "10001", 6);
    char *string1;
    char *string2;

    while (1) {
        char msg[256];
        zmq_pollitem_t items[] = {
            { receiver, 0, ZMQ_POLLIN, 0},
            { subscriber, 0, ZMQ_POLLIN, 0}
        };
        zmq_poll(items, 2, -1);
        if (items[0].revents & ZMQ_POLLIN) {
            string1 = heartbeat_recv_msg(receiver, 0);
            if (strlen(string1) != -1)
            {
            }
            free(string1);
        }

        if (items[1].revents & ZMQ_POLLIN) {
            string2 = heartbeat_recv_msg(subscriber, 0);
            if (strlen(string2) != -1)
            {
            }
            free(string2);
        }
    }
    heartbeat_disconnect_socket(subscriber);
    heartbeat_disconnect_socket(receiver);

    return 0;
}
开发者ID:alexchenfeng,项目名称:hubot,代码行数:39,代码来源:zmq_poll_socket.c

示例9: create_port

void Chat::init(const std::string& my_id)
{
	std::string bind_ep;

	listening_port_ = create_port(my_id);
	bind_ep = std::string("tcp://*:") + boost::lexical_cast<std::string>(listening_port_);

	zmq_ctx_ = g_zmq_ctx.get_zmq_ctx();

	publisher_ = zmq_socket(zmq_ctx_, ZMQ_PUB);
	zmq_bind(publisher_, bind_ep.c_str());

	subscriber_ = zmq_socket(zmq_ctx_, ZMQ_SUB);
	zmq_setsockopt(subscriber_, ZMQ_SUBSCRIBE, "", 0);

	gate_ = zmq_socket(zmq_ctx_, ZMQ_PAIR);
	zmq_bind(gate_, MAGIC_GATE);

	std::string test_msg("hello from ");
	test_msg += my_id;
	zmq_send(publisher_, test_msg.c_str(), test_msg.length(), 0);
}
开发者ID:jinesliang,项目名称:GroupChat,代码行数:22,代码来源:chat.cpp

示例10: redirect_count

//********************************************************************************
// Function: redirect_count
//
// Description: Recieve Control Plane redirect count.
//********************************************************************************
static int32_t redirect_count(void)
{
    void *context = zmq_ctx_new ();
    void *requester = zmq_socket(context, ZMQ_REQ);

    int32_t timeo{};
    zmq_setsockopt(requester, ZMQ_LINGER, (void*) &timeo, sizeof(timeo));

    char buffer[64];
    sprintf(buffer, "tcp://localhost:%d", TCPLANE_SERVICE);
    zmq_connect(requester, buffer);

    sprintf(buffer, "%d", redirectCount);
    zmq_send(requester, buffer, strlen(buffer), 0);

    size_t size = timed_read(requester, buffer, sizeof(buffer), READ_TIMEOUT);
    if(size)
        size = atoi(buffer);    
    zmq_close(requester);
    zmq_ctx_destroy(context);
    return size;
}
开发者ID:BillTheBest,项目名称:laguna,代码行数:27,代码来源:redirectCount.cpp

示例11: main

int main(){
  void *context=zmq_ctx_new();
  void *sink=zmq_socket(context, ZMQ_ROUTER);
  zmq_bind(sink, "inproc://example");

  void *anonymous=zmq_socket(context, ZMQ_REQ);
  zmq_connect(anonymous, "inproc://example");
  s_send(anonymous, "ROUTER uses a generated UUID", 0, NULL);
  s_dump(sink);

  void *identified=zmq_socket(context, ZMQ_REQ);
  zmq_setsockopt(identified, ZMQ_IDENTITY, "PEER2", 5);
  zmq_connect(identified, "inproc://example");
  s_send(identified, "ROUTER socker uses REQ's socker identity", 0, NULL);
  s_dump(sink);

  zmq_close(identified);
  zmq_close(anonymous);
  zmq_close(sink);
  zmq_ctx_destroy(context);
  return 0;
}
开发者ID:solomonwzs,项目名称:zmq_test,代码行数:22,代码来源:id_check.c

示例12: pre_allocate_sock

void pre_allocate_sock (void *zmq_socket, const char *path)
{
    struct sockaddr_un addr;
    addr.sun_family = AF_UNIX;
    strcpy (addr.sun_path, path);

    unlink (path);

    int s_pre = socket (AF_UNIX, SOCK_STREAM, 0);
    assert (s_pre != -1);

    int rc = bind (s_pre, (struct sockaddr *) &addr,
            sizeof (struct sockaddr_un));
    assert (rc == 0);

    rc = listen (s_pre, SOMAXCONN);
    assert (rc == 0);

    rc = zmq_setsockopt (zmq_socket, ZMQ_USE_FD, &s_pre,
            sizeof (s_pre));
    assert(rc == 0);
}
开发者ID:CPlusPlusHome,项目名称:libzmq,代码行数:22,代码来源:test_use_fd_ipc.cpp

示例13: main

int main (int argc, char const *argv[]) {

  void* context = zmq_ctx_new();
  //create a SUB socket
  void* subscriber = zmq_socket(context, ZMQ_SUB);

  const char* filter;
  
  if(argc > 1) {
    filter = argv[1];
  } else {
    filter = "Company1|";
  }
  printf("Collecting stock information from the server.\n");

  int conn = zmq_connect(subscriber, "tcp://localhost:4040");
  // must set a subscription for SUB socket
  conn = zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, filter, strlen(filter));

  int i = 0;
  for(i = 0; i < 10; i++) {
    zmq_msg_t reply;
    zmq_msg_init(&reply);
    // receive the message, previous message is deallocated
    zmq_msg_recv(&reply, subscriber, 0);
    
    int length = zmq_msg_size(&reply);
    char* value = malloc(length + 1);
    memcpy(value, zmq_msg_data(&reply), length);
    zmq_msg_close(&reply);
    printf("%s\n", value);    
    free(value);

  }
  zmq_close(subscriber);
  zmq_ctx_destroy(context);

  return 0;
}
开发者ID:vishalsanfran,项目名称:network-programming,代码行数:39,代码来源:zeroMQ-subscribe.c

示例14: luazmq_skt_set_str_arr

static int luazmq_skt_set_str_arr (lua_State *L, int option_name) {
  zsocket *skt;
  size_t len, tlen, i;
  const char *option_value;
  int ret;

  if(!lua_istable(L, 2)) return luazmq_skt_set_str(L, option_name);

  skt = luazmq_getsocket(L);
  tlen = lua_objlen(L,2);
  for (i = 1; i <= tlen; i++){
    lua_rawgeti(L, 2, i);
    option_value = luaL_checklstring(L, -1, &len);
    ret = zmq_setsockopt(skt->skt, option_name, option_value, len);
    if (ret == -1){
      int n = luazmq_fail(L, skt);
      lua_pushnumber(L, i);
      return n + 1;
    }
  }
  return luazmq_pass(L);
}
开发者ID:ajtulloch,项目名称:lzmq,代码行数:22,代码来源:zsocket.c

示例15: zmq_ctx_new

        bool SubscriberZMQ::_onInit(TUInt port)
        {
            m_context = zmq_ctx_new();
            if (m_context == 0)
            {
                zmqlog("Error occurred during zmq_ctx_new()");
                return false;
            } 
            
            m_socket = zmq_socket(m_context, ZMQ_SUB);
            if (m_socket == 0)
            {
                zmqlog("Error occurred during zmq_socket()");
                clear();
                return false;
            } 
            
            TChar address[100] = {'\0'};
            sprintf(address, "tcp://localhost:%u", port);
            int result = zmq_connect(m_socket, address);

            if (result != 0)
            {
                zmqlog("Error occurred during zmq_init()");
                clear();
                return false;
            }
            
            const TString& subscribeId = getSubscribeId();
            result = zmq_setsockopt (m_socket, ZMQ_SUBSCRIBE, subscribeId.c_str(), subscribeId.length() - 1);
            if (result != 0)
            {
                zmqlog("Error occurred during zmq_setsockopt");
                clear();
                return false;
            }
            
            return true;
        }
开发者ID:gloryofrobots,项目名称:zmq_client_server_test_work,代码行数:39,代码来源:SubscriberZMQ.cpp


注:本文中的zmq_setsockopt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。