Exemplo n.º 1
0
JNIEXPORT jint JNICALL
Java_org_zeromq_czmq_Zsys__1_1close (JNIEnv *env, jclass c, jlong handle, jstring filename, jlong line_nbr)
{
    char *filename_ = (char *) (*env)->GetStringUTFChars (env, filename, NULL);
    jint close_ = (jint) zsys_close ((void *) (intptr_t) handle, filename_, (size_t) line_nbr);
    (*env)->ReleaseStringUTFChars (env, filename, filename_);
    return close_;
}
Exemplo n.º 2
0
Arquivo: zsys.c Projeto: wysman/czmq
//  atexit or manual termination for the process
void
zsys_shutdown (void)
{
    if (!s_initialized) {
        return;
    }
    s_initialized = false;

    //  The atexit handler is called when the main function exits;
    //  however we may have zactor threads shutting down and still
    //  trying to close their sockets. So if we suspect there are
    //  actors busy (s_open_sockets > 0), then we sleep for a few
    //  hundred milliseconds to allow the actors, if any, to get in
    //  and close their sockets.
    ZMUTEX_LOCK (s_mutex);
    size_t busy = s_open_sockets;
    ZMUTEX_UNLOCK (s_mutex);
    if (busy)
        zclock_sleep (200);

    //  No matter, we are now going to shut down
    //  Print the source reference for any sockets the app did not
    //  destroy properly.
    ZMUTEX_LOCK (s_mutex);
    s_sockref_t *sockref = (s_sockref_t *) zlist_pop (s_sockref_list);
    while (sockref) {
        assert (sockref->filename);
        zsys_error ("dangling '%s' socket created at %s:%d",
                    zsys_sockname (sockref->type),
                    sockref->filename, (int) sockref->line_nbr);
        zmq_close (sockref->handle);
        free (sockref);
        sockref = (s_sockref_t *) zlist_pop (s_sockref_list);
    }
    zlist_destroy (&s_sockref_list);
    ZMUTEX_UNLOCK (s_mutex);

    //  Close logsender socket if opened (don't do this in critical section)
    if (s_logsender) {
        zsys_close (s_logsender, NULL, 0);
        s_logsender = NULL;
    }
    if (s_open_sockets == 0)
        zmq_term (s_process_ctx);
    else
        zsys_error ("dangling sockets: cannot terminate ZMQ safely");

    ZMUTEX_DESTROY (s_mutex);

    //  Free dynamically allocated properties
    free (s_interface);
    free (s_logident);

#if defined (__UNIX__)
    closelog ();                //  Just to be pedantic
#endif
}
Exemplo n.º 3
0
void
zsock_destroy_ (zsock_t **self_p, const char *filename, size_t line_nbr)
{
    assert (self_p);
    if (*self_p) {
        zsock_t *self = *self_p;
        assert (zsock_is (self));
        self->tag = 0xDeadBeef;
        int rc = zsys_close (self->handle, filename, line_nbr);
        assert (rc == 0);
        free (self->endpoint);
        free (self);
        *self_p = NULL;
    }
}
Exemplo n.º 4
0
Arquivo: zsys.c Projeto: wysman/czmq
void
zsys_set_logsender (const char *endpoint)
{
    zsys_init ();
    if (endpoint) {
        //  Create log sender if needed
        if (!s_logsender) {
            s_logsender = zsys_socket (ZMQ_PUB, NULL, 0);
            assert (s_logsender);
        }
        //  Bind to specified endpoint
        int rc = zmq_bind (s_logsender, endpoint);
        assert (rc == 0);
    }
    else
    if (s_logsender) {
        zsys_close (s_logsender, NULL, 0);
        s_logsender = NULL;
    }
}
Exemplo n.º 5
0
///
//  Destroy/close a ZMQ socket. You should call this for every socket you
//  create using zsys_socket().
//  *** This is for CZMQ internal use only and may change arbitrarily ***
int QmlZsysAttached::close (void *handle, const QString &filename, size_t lineNbr) {
    return zsys_close (handle, filename.toUtf8().data(), lineNbr);
};
Exemplo n.º 6
0
Arquivo: zsys.c Projeto: wysman/czmq
void
zsys_test (bool verbose)
{
    printf (" * zsys: ");
    if (verbose)
        printf ("\n");

    //  @selftest
    zsys_catch_interrupts ();

    //  Check capabilities without using the return value
    int rc = zsys_has_curve ();

    if (verbose) {
        char *hostname = zsys_hostname ();
        zsys_info ("host name is %s", hostname);
        free (hostname);
        zsys_info ("system limit is %zd ZeroMQ sockets", zsys_socket_limit ());
    }
    zsys_set_io_threads (1);
    zsys_set_max_sockets (0);
    zsys_set_linger (0);
    zsys_set_sndhwm (1000);
    zsys_set_rcvhwm (1000);
    zsys_set_pipehwm (2500);
    assert (zsys_pipehwm () == 2500);

    zsys_set_ipv6 (0);

    rc = zsys_file_delete ("nosuchfile");
    assert (rc == -1);

    bool rc_bool = zsys_file_exists ("nosuchfile");
    assert (rc_bool != true);

    rc = (int) zsys_file_size ("nosuchfile");
    assert (rc == -1);

    time_t when = zsys_file_modified (".");
    assert (when > 0);

    mode_t mode = zsys_file_mode (".");
    assert (S_ISDIR (mode));
    assert (mode & S_IRUSR);
    assert (mode & S_IWUSR);

    zsys_file_mode_private ();
    rc = zsys_dir_create ("%s/%s", ".", ".testsys/subdir");
    assert (rc == 0);
    when = zsys_file_modified ("./.testsys/subdir");
    assert (when > 0);
    assert (!zsys_file_stable ("./.testsys/subdir"));
    rc = zsys_dir_delete ("%s/%s", ".", ".testsys/subdir");
    assert (rc == 0);
    rc = zsys_dir_delete ("%s/%s", ".", ".testsys");
    assert (rc == 0);
    zsys_file_mode_default ();

    int major, minor, patch;
    zsys_version (&major, &minor, &patch);
    assert (major == CZMQ_VERSION_MAJOR);
    assert (minor == CZMQ_VERSION_MINOR);
    assert (patch == CZMQ_VERSION_PATCH);

    char *string = zsys_sprintf ("%s %02x", "Hello", 16);
    assert (streq (string, "Hello 10"));
    free (string);

    char *str64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,.";
    int num10 = 1234567890;
    string = zsys_sprintf ("%s%s%s%s%d", str64, str64, str64, str64, num10);
    assert (strlen (string) == (4 * 64 + 10));
    free (string);

    //  Test logging system
    zsys_set_logident ("czmq_selftest");
    zsys_set_logsender ("inproc://logging");
    void *logger = zsys_socket (ZMQ_SUB, NULL, 0);
    assert (logger);
    rc = zsocket_connect (logger, "inproc://logging");
    assert (rc == 0);
    rc = zmq_setsockopt (logger, ZMQ_SUBSCRIBE, "", 0);
    assert (rc == 0);

    if (verbose) {
        zsys_error ("This is an %s message", "error");
        zsys_warning ("This is a %s message", "warning");
        zsys_notice ("This is a %s message", "notice");
        zsys_info ("This is a %s message", "info");
        zsys_debug ("This is a %s message", "debug");
        zsys_set_logident ("hello, world");
        zsys_info ("This is a %s message", "info");
        zsys_debug ("This is a %s message", "debug");

        //  Check that logsender functionality is working
        char *received = zstr_recv (logger);
        assert (received);
        zstr_free (&received);
    }
    zsys_close (logger, NULL, 0);
    //  @end

    printf ("OK\n");
}
Exemplo n.º 7
0
///
//  Destroy/close a ZMQ socket. You should call this for every socket you
//  create using zsys_socket().
//  *** This is for CZMQ internal use only and may change arbitrarily ***
int QZsys::close (void *handle, const QString &filename, size_t lineNbr)
{
    int rv = zsys_close (handle, filename.toUtf8().data(), lineNbr);
    return rv;
}