~ubuntu-branches/ubuntu/saucy/zeromq3/saucy

« back to all changes in this revision

Viewing changes to perf/remote_thr.cpp

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2012-06-04 21:21:09 UTC
  • Revision ID: package-import@ubuntu.com-20120604212109-b7b3m0rn21o8oo2q
Tags: upstream-3.1.0~beta+dfsg
ImportĀ upstreamĀ versionĀ 3.1.0~beta+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2009-2011 250bpm s.r.o.
 
3
    Copyright (c) 2007-2009 iMatix Corporation
 
4
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
 
5
 
 
6
    This file is part of 0MQ.
 
7
 
 
8
    0MQ is free software; you can redistribute it and/or modify it under
 
9
    the terms of the GNU Lesser General Public License as published by
 
10
    the Free Software Foundation; either version 3 of the License, or
 
11
    (at your option) any later version.
 
12
 
 
13
    0MQ is distributed in the hope that it will be useful,
 
14
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
    GNU Lesser General Public License for more details.
 
17
 
 
18
    You should have received a copy of the GNU Lesser General Public License
 
19
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include "../include/zmq.h"
 
23
#include "../include/zmq_utils.h"
 
24
#include <stdio.h>
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
 
 
28
int main (int argc, char *argv [])
 
29
{
 
30
    const char *connect_to;
 
31
    int message_count;
 
32
    int message_size;
 
33
    void *ctx;
 
34
    void *s;
 
35
    int rc;
 
36
    int i;
 
37
    zmq_msg_t msg;
 
38
 
 
39
    if (argc != 4) {
 
40
        printf ("usage: remote_thr <connect-to> <message-size> "
 
41
            "<message-count>\n");
 
42
        return 1;
 
43
    }
 
44
    connect_to = argv [1];
 
45
    message_size = atoi (argv [2]);
 
46
    message_count = atoi (argv [3]);
 
47
 
 
48
    ctx = zmq_init (1);
 
49
    if (!ctx) {
 
50
        printf ("error in zmq_init: %s\n", zmq_strerror (errno));
 
51
        return -1;
 
52
    }
 
53
 
 
54
    s = zmq_socket (ctx, ZMQ_PUSH);
 
55
    if (!s) {
 
56
        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
 
57
        return -1;
 
58
    }
 
59
 
 
60
    //  Add your socket options here.
 
61
    //  For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
 
62
 
 
63
    rc = zmq_connect (s, connect_to);
 
64
    if (rc != 0) {
 
65
        printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
 
66
        return -1;
 
67
    }
 
68
 
 
69
    for (i = 0; i != message_count; i++) {
 
70
 
 
71
        rc = zmq_msg_init_size (&msg, message_size);
 
72
        if (rc != 0) {
 
73
            printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
 
74
            return -1;
 
75
        }
 
76
#if defined ZMQ_MAKE_VALGRIND_HAPPY
 
77
        memset (zmq_msg_data (&msg), 0, message_size);
 
78
#endif
 
79
 
 
80
        rc = zmq_sendmsg (s, &msg, 0);
 
81
        if (rc < 0) {
 
82
            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
 
83
            return -1;
 
84
        }
 
85
        rc = zmq_msg_close (&msg);
 
86
        if (rc != 0) {
 
87
            printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
 
88
            return -1;
 
89
        }
 
90
    }
 
91
 
 
92
    rc = zmq_close (s);
 
93
    if (rc != 0) {
 
94
        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
 
95
        return -1;
 
96
    }
 
97
 
 
98
    rc = zmq_term (ctx);
 
99
    if (rc != 0) {
 
100
        printf ("error in zmq_term: %s\n", zmq_strerror (errno));
 
101
        return -1;
 
102
    }
 
103
 
 
104
    return 0;
 
105
}