bool
_mongoc_cursor_prepare_getmore_command (mongoc_cursor_t *cursor,
                                        bson_t *command)
{
   const char *collection;
   int collection_len;
   int64_t batch_size;
   bool await_data;
   int32_t max_await_time_ms;

   ENTRY;

   _mongoc_cursor_collection (cursor, &collection, &collection_len);

   bson_init (command);
   bson_append_int64 (command, "getMore", 7, mongoc_cursor_get_id (cursor));
   bson_append_utf8 (command, "collection", 10, collection, collection_len);

   batch_size = mongoc_cursor_get_batch_size (cursor);

   /* See find, getMore, and killCursors Spec for batchSize rules */
   if (batch_size) {
      bson_append_int64 (
         command, MONGOC_CURSOR_BATCH_SIZE, MONGOC_CURSOR_BATCH_SIZE_LEN, abs (_mongoc_n_return (cursor)));
   }

   /* Find, getMore And killCursors Commands Spec: "In the case of a tailable
      cursor with awaitData == true the driver MUST provide a Cursor level
      option named maxAwaitTimeMS (See CRUD specification for details). The
      maxTimeMS option on the getMore command MUST be set to the value of the
      option maxAwaitTimeMS. If no maxAwaitTimeMS is specified, the driver
      SHOULD not set maxTimeMS on the getMore command."
    */
   await_data = _mongoc_cursor_get_opt_bool (cursor, MONGOC_CURSOR_TAILABLE) &&
                _mongoc_cursor_get_opt_bool (cursor, MONGOC_CURSOR_AWAIT_DATA);


   if (await_data) {
      max_await_time_ms =
         (int32_t) mongoc_cursor_get_max_await_time_ms (cursor);
      if (max_await_time_ms) {
         bson_append_int32 (
            command, MONGOC_CURSOR_MAX_TIME_MS, MONGOC_CURSOR_MAX_TIME_MS_LEN, max_await_time_ms);
      }
   }

   RETURN (true);
}
Exemplo n.º 2
0
static getmore_type_t
_getmore_type (mongoc_cursor_t *cursor)
{
   mongoc_server_stream_t *server_stream;
   bool use_cmd;
   data_cmd_t *data = (data_cmd_t *) cursor->impl.data;
   if (data->getmore_type != UNKNOWN) {
      return data->getmore_type;
   }
   server_stream = _mongoc_cursor_fetch_stream (cursor);
   if (!server_stream) {
      return UNKNOWN;
   }
   use_cmd = server_stream->sd->max_wire_version >= WIRE_VERSION_FIND_CMD &&
             !_mongoc_cursor_get_opt_bool (cursor, MONGOC_CURSOR_EXHAUST);
   data->getmore_type = use_cmd ? GETMORE_CMD : OP_GETMORE;
   mongoc_server_stream_cleanup (server_stream);
   return data->getmore_type;
}