Skip to content

Commit

Permalink
Refactoring of MDP APIs done
Browse files Browse the repository at this point in the history
  • Loading branch information
hintjens committed Mar 3, 2011
1 parent 729066b commit 184521f
Show file tree
Hide file tree
Showing 56 changed files with 802 additions and 65 deletions.
13 changes: 13 additions & 0 deletions examples/Ada/interrupt.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the interrupt example into Ada yet. Be the first to create
interrupt in Ada and get one free Internet! If you're the author of the Ada
binding, this is a great way to get people to use 0MQ in Ada.

To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:

* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.

Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/Ada/mdcliapi.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdcliapi example into Ada yet. Be the first to create
mdcliapi in Ada and get one free Internet! If you're the author of the Ada
binding, this is a great way to get people to use 0MQ in Ada.

To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:

* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.

Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/Ada/mdwrkapi.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdwrkapi example into Ada yet. Be the first to create
mdwrkapi in Ada and get one free Internet! If you're the author of the Ada
binding, this is a great way to get people to use 0MQ in Ada.

To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:

* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.

Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/Basic/interrupt.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the interrupt example into Basic yet. Be the first to create
interrupt in Basic and get one free Internet! If you're the author of the Basic
binding, this is a great way to get people to use 0MQ in Basic.

To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:

* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.

Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/Basic/mdcliapi.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdcliapi example into Basic yet. Be the first to create
mdcliapi in Basic and get one free Internet! If you're the author of the Basic
binding, this is a great way to get people to use 0MQ in Basic.

To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:

* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.

Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/Basic/mdwrkapi.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdwrkapi example into Basic yet. Be the first to create
mdwrkapi in Basic and get one free Internet! If you're the author of the Basic
binding, this is a great way to get people to use 0MQ in Basic.

To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:

* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.

Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/C#/interrupt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the interrupt example into C# yet. Be the first to create
interrupt in C# and get one free Internet! If you're the author of the C#
binding, this is a great way to get people to use 0MQ in C#.
To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:
* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.
Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/C#/mdcliapi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdcliapi example into C# yet. Be the first to create
mdcliapi in C# and get one free Internet! If you're the author of the C#
binding, this is a great way to get people to use 0MQ in C#.
To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:
* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.
Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/C#/mdwrkapi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdwrkapi example into C# yet. Be the first to create
mdwrkapi in C# and get one free Internet! If you're the author of the C#
binding, this is a great way to get people to use 0MQ in C#.
To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:
* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.
Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/C++/interrupt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the interrupt example into C++ yet. Be the first to create
interrupt in C++ and get one free Internet! If you're the author of the C++
binding, this is a great way to get people to use 0MQ in C++.
To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:
* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.
Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/C++/mdcliapi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdcliapi example into C++ yet. Be the first to create
mdcliapi in C++ and get one free Internet! If you're the author of the C++
binding, this is a great way to get people to use 0MQ in C++.
To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:
* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.
Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
13 changes: 13 additions & 0 deletions examples/C++/mdwrkapi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
No-one has translated the mdwrkapi example into C++ yet. Be the first to create
mdwrkapi in C++ and get one free Internet! If you're the author of the C++
binding, this is a great way to get people to use 0MQ in C++.
To submit a new translation email it to zeromq-dev@lists.zeromq.org. Please:
* Stick to identical functionality and naming used in examples so that readers
can easily compare languages.
* You MUST place your name as author in the examples so readers can contact you.
* You MUST state in the email that you license your code under the MIT/X11
license.
Subscribe to the email list at http://lists.zeromq.org/mailman/listinfo/zeromq-dev.
1 change: 0 additions & 1 deletion examples/C/build
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ elif [ -f $1.c ]; then
else
echo "syntax: build all | clean"
fi

61 changes: 30 additions & 31 deletions examples/C/mdcliapi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* =========================================================================
mdcliapi.h
mdcliapi.c
Majordomo Protocol Client API
Implements the MDP/Worker spec at http://rfc.zeromq.org/spec:7.
Expand All @@ -25,33 +25,8 @@
=========================================================================
*/

#ifndef __MDCLIAPI_H_INCLUDED__
#define __MDCLIAPI_H_INCLUDED__
#include "mdcliapi.h"

#include "zmsg.h"
#include "mdp.h"

// Reliability parameters
#define REQUEST_TIMEOUT 2500 // msecs, (> 1000!)
#define REQUEST_RETRIES 3 // Before we abandon

#ifdef __cplusplus
extern "C" {
#endif

// Opaque class structure
typedef struct _mdcli_t mdcli_t;

mdcli_t *
mdcli_new (char *broker, int verbose);
void
mdcli_destroy (mdcli_t **self_p);
zmsg_t *
mdcli_send (mdcli_t *self, char *service, zmsg_t *request);

#ifdef __cplusplus
}
#endif

// Structure of our class
// We access these properties only via class methods
Expand All @@ -61,6 +36,8 @@ struct _mdcli_t {
void *context;
void *client; // Socket to broker
int verbose; // Print activity to stdout
int timeout; // Request timeout
int retries; // Request retries
};


Expand Down Expand Up @@ -97,6 +74,8 @@ mdcli_new (char *broker, int verbose)
self->broker = strdup (broker);
self->context = zmq_init (1);
self->verbose = verbose;
self->timeout = 2500; // msecs, (> 1000!)
self->retries = 3; // Before we abandon

s_catch_signals ();
s_connect_to_broker (self);
Expand All @@ -121,6 +100,27 @@ mdcli_destroy (mdcli_t **self_p)
}
}

// --------------------------------------------------------------------------
// Set request timeout

void
mdcli_set_timeout (mdcli_t *self, int timeout)
{
assert (self);
self->timeout = timeout;
}


// --------------------------------------------------------------------------
// Set request retries

void
mdcli_set_retries (mdcli_t *self, int retries)
{
assert (self);
self->retries = retries;
}


// --------------------------------------------------------------------------
// Send request to broker and get reply by hook or crook
Expand All @@ -129,7 +129,8 @@ mdcli_destroy (mdcli_t **self_p)
zmsg_t *
mdcli_send (mdcli_t *self, char *service, zmsg_t *request)
{
int retries_left = REQUEST_RETRIES;
assert (self);
int retries_left = self->retries;
while (retries_left && !s_interrupted) {
// Prefix request with protocol frames
// Frame 1: "MDPCxy" (six bytes, MDP/Client x.y)
Expand All @@ -146,7 +147,7 @@ mdcli_send (mdcli_t *self, char *service, zmsg_t *request)
while (!s_interrupted) {
// Poll socket for a reply, with timeout
zmq_pollitem_t items [] = { { self->client, 0, ZMQ_POLLIN, 0 } };
zmq_poll (items, 1, REQUEST_TIMEOUT * 1000);
zmq_poll (items, 1, self->timeout * 1000);

// If we got a reply, process it
if (items [0].revents & ZMQ_POLLIN) {
Expand Down Expand Up @@ -190,5 +191,3 @@ mdcli_send (mdcli_t *self, char *service, zmsg_t *request)
printf ("W: interrupt received, killing client...\n");
return NULL;
}

#endif
56 changes: 56 additions & 0 deletions examples/C/mdcliapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* =========================================================================
mdcliapi.h
Majordomo Protocol Client API
Implements the MDP/Worker spec at http://rfc.zeromq.org/spec:7.
-------------------------------------------------------------------------
Copyright (c) 1991-2011 iMatix Corporation <www.imatix.com>
Copyright other contributors as noted in the AUTHORS file.
This file is part of the ZeroMQ Guide: http://zguide.zeromq.org
This is free software; you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABIL-
ITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=========================================================================
*/

#ifndef __MDCLIAPI_H_INCLUDED__
#define __MDCLIAPI_H_INCLUDED__

#include "zmsg.h"
#include "mdp.h"

#ifdef __cplusplus
extern "C" {
#endif

// Opaque class structure
typedef struct _mdcli_t mdcli_t;

mdcli_t *
mdcli_new (char *broker, int verbose);
void
mdcli_destroy (mdcli_t **self_p);
void
mdcli_set_timeout (mdcli_t *self, int timeout);
void
mdcli_set_retries (mdcli_t *self, int retries);
zmsg_t *
mdcli_send (mdcli_t *self, char *service, zmsg_t *request);

#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions examples/C/mdclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Uses the mdcli API to hide all MDP aspects
//
#include "mdcliapi.h"
#include "mdcliapi.c"

int main (void)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/C/mdworker.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Majordomo Protocol worker example
// Uses the mdwrk API to hide all MDP aspects
//
#include "mdwrkapi.h"
#include "mdwrkapi.c"

int main (void)
{
Expand Down
Loading

0 comments on commit 184521f

Please sign in to comment.