Re: [zeromq-dev] Newbie questions
That should be how it's used, yes. The parameter is optional, so if you don't submit a method/function there, you will have to take care of deleting yourself. From: zeromq-dev-boun...@lists.zeromq.org [mailto:zeromq-dev-boun...@lists.zeromq.org] On Behalf Of Alex du Plessis Sent: Freitag, 01. April 2011 15:53 To: ZeroMQ Mailing list Subject: [zeromq-dev] Newbie questions Hello list, I'm a complete newbie in the use and application of Zeromq so I am sure my questions will sound quite inane and downright stupid. I apologise in advance. I stumbled on ZeroMQ early this week while googling for a decent message system that is'nt implemented in Java. I use FPC(FreePascal) and Lazarus (both Open Source products) as my programming platform and intend to write a binding as well as component/s to enable the use of ZeroMQ with FPC. Unfortunately, I am not very C proficient, so I am also doing a crash course in C/C++ at the moment. I have already started the port and I'm ironing out the wrinkles in my interface unit .So much for the intro, here's my question: >From the api documentation on the web it seems that the variable ffn of type >zmq_free_fn as defined in the parameters of zmq_msg_init_data is a user >supplied function and one needs to pass a pointer to a function that will free >the message data. Is this correct? Regards ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
[zeromq-dev] ZGuide C++ Updates
Added Paranoid Pirate pattern and fixed some errors. Hope the patch file works, had some problems with git. Cheers Andreas 0001-zguide-cpp-updates.patch Description: 0001-zguide-cpp-updates.patch ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
Re: [zeromq-dev] [PATCH] add zmq::version to C++ API
Passing those parameters by reference gives you additional safety for the call. Additionally, in C++ lessons given to me, parameters by reference, especially for basic data types such as integers, were a sign for in/out parameters Andreas -Original Message- From: zeromq-dev-boun...@lists.zeromq.org [mailto:zeromq-dev-boun...@lists.zeromq.org] On Behalf Of Martin Sustrik Sent: Dienstag, 15. März 2011 11:08 To: ZeroMQ development list Subject: Re: [zeromq-dev] [PATCH] add zmq::version to C++ API On 03/15/2011 10:39 AM, Pieter Hintjens wrote: > Please find attached patch. Thanks. Is there any reason why the arguments are passed by references rather then by pointers? It makes the fact that they are actually out parameters not obvious: int major, minor, patch; zmq::version (major, minor, patch); vs. int major, minor, patch; zmq::version (&major, &minor, &patch); Martin ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
[zeromq-dev] C++-Guide: Updates and added suisnail translation
Hi, Got some (hopefully helpful) changes for the C++ version of the guide. They're all tested, I hope I didn't miss anything. General: "std::string * s_recv()" -> "std::string s_recv()" + update in all uses General: moved nanosleep as s_sleep(int ms) to zhelpers.hpp as seen in zhelpers.h General: moved s_clock() to zhelpers.h as seen in zhelpers.h lruqueue.cpp changing worker_queue from std::string*[] to std::queue suisnail.cpp C++ translation cheers, Andreas 0001-Signed-off-by-Andreas-Hoelzlwimmer-andreas.hoelzlwim.patch Description: 0001-Signed-off-by-Andreas-Hoelzlwimmer-andreas.hoelzlwim.patch ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
[zeromq-dev] zmsg C++ Translation
As I'm going for some Guide Chapter 4 C++ Translations, here's the Translation of zmsg.h into C++. zmsg.hpp Description: zmsg.hpp ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev
[zeromq-dev] Lazy Pirate Server/Client C++ Translation
Got the Lazy Pirate C++ Translations for Server and Client Thanks to Charles Remes for helping. Hope Attachments work here :) Br Andreas Hoelzlwimmer // // Lazy Pirate client // Use zmq_poll to do a safe request-reply // To run, start piserver and then randomly kill/restart it // #include "zhelpers.hpp" #define REQUEST_TIMEOUT 2500// msecs, (> 1000!) #define REQUEST_RETRIES 3 // Before we abandon // Helper function that returns a new configured socket // connected to the Hello World server // static zmq::socket_t * s_client_socket(zmq::context_t & context) { printf("I: connecting to server...\n"); zmq::socket_t * client = new zmq::socket_t(context, ZMQ_REQ); client->connect("tcp://localhost:"); // Configure socket to not wait at close time int linger = 0; client->setsockopt(ZMQ_LINGER, &linger, sizeof(linger)); return client; } int main() { zmq::context_t context(1); zmq::socket_t * client = s_client_socket(context); printf("I: connecting to server...\n"); int sequence = 0; int retries_left = REQUEST_RETRIES; while (retries_left) { // We send a request, then we work to get a reply char request[10]; sprintf(request, "%d", ++sequence); s_send(*client, request); sleep(1); int expect_reply = 1; while (expect_reply) { // Poll socket for a reply, with timeout zmq::pollitem_t items[] = { { *client, 0, ZMQ_POLLIN, 0 } }; zmq::poll(&items[0], 1, REQUEST_TIMEOUT * 1000); // If we got a reply, process it if (items[0].revents & ZMQ_POLLIN) { // We got a reply from the server, must match sequence std::string *reply = s_recv(*client); if (atoi(reply->c_str()) == sequence) { printf("I: server replied OK (%s)\n", reply->c_str()); retries_left = REQUEST_RETRIES; expect_reply = 0; } else printf("E: malformed reply from server: %s\n", reply->c_str()); delete reply; } else if (--retries_left == 0) { printf("E: server seems to be offline, abandoning\n"); break; } else { printf("W: no response from server, retrying...\n"); // Old socket will be confused; close it and open a new one delete client; client = s_client_socket(context); // Send request again, on new socket s_send(*client, request); } } } return 0; } // // Lazy Pirate server // Binds REQ socket to tcp://*: // Like hwserver except: // - echoes request as-is // - randomly runs slowly, or exits to simulate a crash. // #include "zhelpers.hpp" int main () { srandom ((unsigned) time (NULL)); zmq::context_t context(1); zmq::socket_t server(context, ZMQ_REP); server.bind("tcp://*:"); int cycles = 0; while (1) { std::string *request = s_recv (server); cycles++; // Simulate various problems, after a few cycles if (cycles > 3 && within (3) == 0) { printf ("I: simulating a crash\n"); break; } else if (cycles > 3 && within (3) == 0) { printf ("I: simulating CPU overload\n"); sleep (5); } printf ("I: normal request (%s)\n", request->c_str()); sleep (1); // Do some heavy work s_send (server, *request); delete request; } return 0; } ___ zeromq-dev mailing list zeromq-dev@lists.zeromq.org http://lists.zeromq.org/mailman/listinfo/zeromq-dev