Example #1
0
JNIEXPORT jlong JNICALL
Java_org_zeromq_czmq_Zsock__1_1newReq (JNIEnv *env, jclass c, jstring endpoint)
{
    char *endpoint_ = (char *) (*env)->GetStringUTFChars (env, endpoint, NULL);
    jlong new_req_ = (jlong) (intptr_t) zsock_new_req (endpoint_);
    (*env)->ReleaseStringUTFChars (env, endpoint, endpoint_);
    return new_req_;
}
Example #2
0
static int reader_pipe_event(zloop_t *loop, zsock_t *reader, void *arg) {
    int ret = 0;
    ticket_printer_t *self = (ticket_printer_t *) arg;
    zmsg_t *request = zmsg_recv(self->pipe);
    if (!request) {
        return -1;
    }
    char *command = zmsg_popstr(request);
    if (self->verbose) {
        zsys_debug("ticket printer: API command %s", command);
    }
    if (streq(command, "$TERM")) {
        self->event = EVENT_TERM;
        s_state_machine(self);
        ret = -1;
    } else if (streq(command, "VERBOSE")) {
        self->verbose = true;
        if (self->hid_printer != NULL)
            boca_hid_set_verbose(self->hid_printer, self->verbose);
#ifdef __WIN32__
        if (self->serial_printer != NULL)
            boca_serial_set_verbose(self->serial_printer, self->verbose);
#endif
    } else if (streq(command, "START")) {
        char *ticket_store_endpoint = zmsg_popstr(request);
        self->ticket_store_req = zsock_new_req(ticket_store_endpoint);
        zsys_info("ticket printer: ticket printer is using ticket store %s", ticket_store_endpoint);
        zstr_free(&ticket_store_endpoint);
        self->event = EVENT_TICKET_STORE_READY;
        s_state_machine(self);
        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETPRINTERSTORE")) {
        char *printer_store_ep = zmsg_popstr(request);
        self->printer_store_req = zsock_new_req(printer_store_ep);
        zstr_free(&printer_store_ep);
        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETDIAGNOSTIC")) {
        self->diagnostic = true;
    }
    zstr_free(&command);
    zmsg_destroy(&request);
    return ret;
}
Example #3
0
int main(int argc, const char *argv[]) {
    zsock_t *sock = zsock_new_req("tcp://127.0.0.1:5555");
    int count = 10000;

    zpoller_t *poller = zpoller_new(sock, NULL);
    while (count--) {
        zmsg_t *request = zmsg_new();
        zmsg_pushstr(request, "HELLO");
        zmsg_pushstr(request, "com.tw.echo");
        zmsg_pushstr(request, MDPC_CLIENT);
        zmsg_send(&request, sock);

        zmsg_t *msg = zmsg_recv(sock);
        zsys_info("GET RESPONSE: %d ", count);
        zmsg_print(msg);
        zmsg_destroy(&msg);
    }
    zsock_destroy(&sock);
    return 0;
}
Example #4
0
///
//  Create a REQ socket. Default action is connect.
QZsock* QZsock::newReq (const QString &endpoint, QObject *qObjParent)
{
    return new QZsock (zsock_new_req (endpoint.toUtf8().data()), qObjParent);
}
Example #5
0
/* ================ client_thread_main() ================ */
void client_thread_main(zsock_t *pipe, void *user_data)
{
    client_t *client = (client_t*)user_data;
    int id = client->id;
    UNUSED const char *file_data = client->file_data;
    UNUSED uint32_t file_size = client->file_size;

    trace_log("Client %d Ready.", id);

    zsock_signal(pipe, 0);

    char sz_id[16];
    sprintf(sz_id, "%d", id);

    message_send_status(pipe, MSG_STATUS_ACTOR_READY);

    zsock_t *sock_client = zsock_new_req(client->endpoint);
    if ( sock_client == NULL ){
        error_log("Connect broker failed. Client %d", client->id);
        return;
    }

    uint32_t file_count = 0;
    while ( true ){

        char key[NAME_MAX];
        client_rebuild_data_key(client, file_count, key);

        int retries = 0;
        while ( retries++ < RETRIES ) {

            int rc = 0;
            if ( client->op_code == 1 ) {
                rc = upload_data(sock_client, key, file_data, file_size);
            } else if ( client->op_code == 2 ) {
                rc = download_data(sock_client, key);
            } else if ( client->op_code == 3 ) {
                rc = delete_data(sock_client, key);
            }
            if ( rc == -2 ) break;
            if ( rc == 0 ) break;

            notice_log("Retry %d/%d...", retries, RETRIES);
            zclock_sleep(1000);
        }

        /* ---------------- Check exit loop ---------------- */

        file_count++;
        if ( file_count % 100 == 1 || file_count + 5 >= client->total_files ){
            info_log("Client %d Send message %d/%d", client->id, file_count, client->total_files);
        }
        if ( file_count >= client->total_files )
            break;
    }

    message_send_status(pipe, MSG_STATUS_ACTOR_OVER);

    zsock_destroy(&sock_client);

    trace_log("Client %d Exit.", id);

}
Example #6
0
int main(int argc, char *argv[]) {
  printf("Organizer started.\n");
  zsock_t *executer_sock = zsock_new_req("tcp://127.0.0.1:98789");

  while (1) {
    char cmd[50] = {0};
    printf("What do you want? ");
    scanf("%s", &cmd);

    if (streq(cmd, "teleport")) {
      char target[50] = {0}, name[50] = {0};
      printf("Which? Where? ");
      scanf("%s %s", &name, &target);

      /*printf("Name: %s\tTarget: %s\n", name, target);*/
      OEMsg oem = OEMSG__INIT;
      Teleport tpm = TELEPORT__INIT;
      void *buf;
      unsigned len;

      tpm.vm_name = name;
      tpm.target_ip = target;
      oem.teleport = &tpm;
      oem.type = OEMSG__TYPE__TELEPORT;
      len = oemsg__get_packed_size(&oem);

      buf = malloc(len);
      oemsg__pack(&oem, buf);

      /*printf(buf);*/

      zframe_t *frame = zframe_new(buf, len);
      zframe_send(&frame, executer_sock, 0);
      /*zstr_send(executer_sock, buf);*/
      memset(buf, 0, len * (sizeof buf[0]));
      free(buf);

      char *smsg;
      smsg = zstr_recv(executer_sock);
      free(smsg);
    } else if (streq(cmd, "start")) {
      char name[50] = {0};
      printf("Which? ");
      scanf("%s", &name);

      OEMsg oem = OEMSG__INIT;
      Start sm = START__INIT;
      void *buf;
      unsigned len;

      sm.vm_name = name;
      oem.start = &sm;
      oem.type = OEMSG__TYPE__START;
      len = oemsg__get_packed_size(&oem);

      buf = malloc(len);
      oemsg__pack(&oem, buf);

      /*printf(buf);*/

      zframe_t *frame = zframe_new(buf, len);
      zframe_send(&frame, executer_sock, 0);
      /*zstr_send(executer_sock, buf);*/
      memset(buf, 0, len * (sizeof buf[0]));
      free(buf);

      char *smsg;
      smsg = zstr_recv(executer_sock);
      free(smsg);

    } else if (streq(cmd, "exit")) {
      break;
    } else {
      break;
    }
  }

  zsock_destroy(&executer_sock);
  return 0;
}
Example #7
0
File: qzmq.c Project: jaeheum/qzmq
Z K1(zsocknewreq){R ptr(zsock_new_req(xs));}
Example #8
0
static int pipe_loop_handler(zloop_t *loop, zsock_t *pipe, void *arg) {
    int ret = 0;
    client_proxy_t *self = arg;
    zmsg_t *request = zmsg_recv(pipe);
    if (!request) {
        return ret;
    }
    char *command = zmsg_popstr(request);
    if (self->verbose) {
        zsys_debug("client proxy: API command %s", command);
    }
    if (streq(command, "START")) {
        char *endpoint = zmsg_popstr(request);
        self->rep = zsock_new_rep(endpoint);
        assert(self->rep);
        zsys_info("client proxy: is listening on %s", endpoint);
        zloop_reader(self->loop, self->rep, reader_rep_event, self);
        zstr_free(&endpoint);

        char *pub_ep = zmsg_popstr(request);
        self->pub = zsock_new_pub(pub_ep);
        assert(self->pub);
        zsys_info("client proxy: is publishing on %s", pub_ep);
        zstr_free(&pub_ep);

        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETTICKETSTORE")) {
        char *ep = zmsg_popstr(request);
        self->ticket_store_req = zsock_new_req(ep);
        assert(self->ticket_store_req);
        zsys_info("client proxy: ticket api using %s", ep);
        zstr_free(&ep);

        char *pub_ep = zmsg_popstr(request);
        self->ticket_store_sub = zsock_new_sub(pub_ep, "");
        zloop_reader(self->loop, self->ticket_store_sub, reader_internal_sub_event, self);
        zsys_info("client proxy: republishing messages from %s", pub_ep);
        zstr_free(&pub_ep);

        zsock_signal(self->pipe, 0);
    } else if (streq(command, "SETPRINTERSTORE")) {
        char *ep = zmsg_popstr(request);
        self->printer_store_req = zsock_new_req(ep);
        assert(self->printer_store_req);
        zsys_info("client proxy: printer api is ready from %s", ep);
        zstr_free(&ep);

        char *subep = zmsg_popstr(request);
        self->printer_store_sub = zsock_new_sub(subep, "");
        zloop_reader(self->loop, self->printer_store_sub, reader_internal_sub_event, self);
        zsys_info("client proxy: republishing message from %s", subep);
        zstr_free(&subep);
        zsock_signal(self->pipe, 0);
    }
    else if (streq(command, "$TERM")) {
        ret = -1;
    } else if (streq(command, "VERBOSE")) {
        self->verbose = true;
    }
    zstr_free(&command);
    zmsg_destroy(&request);
    return ret;
}
Example #9
0
///
//  Create a REQ socket. Default action is connect.
QmlZsock *QmlZsockAttached::constructReq (const QString &endpoint) {
    QmlZsock *qmlSelf = new QmlZsock ();
    qmlSelf->self = zsock_new_req (endpoint.toUtf8().data());
    return qmlSelf;
};
Example #10
0
///
//  Create a REQ socket. Default action is connect.
QmlZsock *QmlZsockAttached::newReq (const QString &endpoint) {
    QmlZsock *retQ_ = new QmlZsock ();
    retQ_->self = zsock_new_req (endpoint.toUtf8().data());
    return retQ_;
};