void * zfl_device_socket ( zfl_device_t *self, char *device_name, char *socket_name, int socket_type) { assert (self); assert (device_name); assert (strneq (device_name, "context")); zfl_config_t *config = zfl_config_locate (self->config, device_name); if (!config) return NULL; // No such device void *socket = zmq_socket (self->context, socket_type); if (!socket) return NULL; // Can't create socket if (zfl_device_verbose (self)) printf ("I: Configuring '%s' socket in '%s' device...\n", socket_name, device_name); // Find socket in device int rc = 0; config = zfl_config_locate (config, socket_name); if (config) { config = zfl_config_child (config); while (config && rc == 0) { char *name = zfl_config_name (config); if (streq (name, "bind")) rc = zmq_bind (socket, zfl_config_string (config)); else if (streq (name, "connect")) rc = zmq_connect (socket, zfl_config_string (config)); else if (streq (name, "option")) rc = s_setsockopt (self, socket, config); // // else ignore it, user space setting config = zfl_config_next (config); } } else if (self->verbose) printf ("W: No property found for '%s'\n", socket_name); if (rc) { printf ("E: property failed - %s\n", zmq_strerror (errno)); zmq_close (socket); socket = NULL; } return socket; }
// Starts a device as configured by a JSON or text config file // static void s_start_configured_device (char *filename) { // Create and configure a zfl_device object zfl_device_t *device = zfl_device_new (filename); if (!device) { printf ("E: '%s' can't be read, or has invalid syntax\n", filename); exit (EXIT_FAILURE); } // Find first device char *main_device = zfl_device_locate (device, 0); if (!*main_device) { printf ("E: No device specified, please read http://rfc.zeromq.org/spec:5\n"); exit (EXIT_FAILURE); } // Process device type char *type = zfl_device_property (device, main_device, "type"); int device_type; // 0MQ defined type int frontend_type; // Socket types depending int backend_type; // on the device type s_parse_device_type (type, &device_type, &frontend_type, &backend_type); // Create and configure sockets void *frontend = zfl_device_socket (device, main_device, "frontend", frontend_type); assert (frontend); void *backend = zfl_device_socket (device, main_device, "backend", backend_type); assert (backend); // Start the device now if (zfl_device_verbose (device)) printf ("I: Starting device...\n"); // Will not actually ever return zmq_device (device_type, frontend, backend); zfl_device_destroy (&device); }