void
test_mongo_connection_set_timeout (void)
{
  mongo_connection c, *conn;

  c.fd = -1;

  ok (mongo_connection_set_timeout (NULL, 100) == FALSE,
      "mongo_connection_set_timeout() should fail with a NULL connection");
  ok (mongo_connection_set_timeout (&c, -1) == FALSE,
      "mongo_connection_set_timeout() should fail with a negative timeout");
  ok (mongo_connection_set_timeout (&c, 100) == FALSE,
      "mongo_connection_set_timeout() should fail with an invalid FD");

  begin_network_tests (0);

  conn = mongo_connect (config.primary_host, config.primary_port);

  /* No verification here, as some systems may or may not support
     this, thus, failing in a test is not fatal. */
  mongo_connection_set_timeout (conn, 100);

  mongo_disconnect (conn);

  end_network_tests ();
}
Beispiel #2
0
static gboolean
afmongodb_dd_connect(MongoDBDestDriver *self, gboolean reconnect)
{
  if (reconnect && self->conn)
    return TRUE;

  self->conn = mongo_sync_connect_recovery_cache(self->recovery_cache, FALSE);

  if (!self->conn)
    {
      msg_error ("Error connecting to MongoDB", evt_tag_str("driver", self->super.super.super.id), NULL);
      return FALSE;
    }

  mongo_connection_set_timeout((mongo_connection*) self->conn, SOCKET_TIMEOUT_FOR_MONGO_CONNECTION_IN_MILLISECS);

  mongo_sync_conn_set_safe_mode(self->conn, self->safe_mode);


  if (self->user || self->password)
    {
      if (!mongo_sync_cmd_authenticate (self->conn, self->db,
                                        self->user, self->password))
        {
          msg_error("MongoDB authentication failed", evt_tag_str("driver", self->super.super.super.id), NULL);
          return FALSE;
        }
    }

  return TRUE;
}
Beispiel #3
0
NEOERR* mmg_init(char *host, int port, int ms, mmg_conn **db)
{
    if (!host) return nerr_raise(NERR_ASSERT, "paramter null");

    mmg_conn *ldb;

    mtc_noise("connect to %s %d %d ...", host, port, ms);
    
    *db = NULL;
    ldb = calloc(1, sizeof(mmg_conn));
    if (!ldb) return nerr_raise(NERR_NOMEM, "calloc for connection");

    ldb->con = mongo_sync_connect(host, port, true);
    if (!ldb->con) return nerr_raise(NERR_DB, "sync connect: %s", strerror(errno));
    mongo_sync_conn_set_auto_reconnect(ldb->con, true);
    if (ms > 0) mongo_connection_set_timeout((mongo_connection*)ldb->con, ms);

    *db = ldb;

    return STATUS_OK;
}