Skip to content

Commit cea1629

Browse files
committed
cleanups for PR-177
* moving mongoc_client_pool_get_size() to a private header * code formatting * moving variables to the top of the block for msvc Closes #177
1 parent af85a17 commit cea1629

File tree

5 files changed

+58
-22
lines changed

5 files changed

+58
-22
lines changed

src/mongoc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ INST_H_FILES = \
2424
src/mongoc/mongoc-bulk-operation-private.h \
2525
src/mongoc/mongoc-bulk-operation.h \
2626
src/mongoc/mongoc-client-pool.h \
27+
src/mongoc/mongoc-client-pool-private.h \
2728
src/mongoc/mongoc-client-private.h \
2829
src/mongoc/mongoc-client.h \
2930
src/mongoc/mongoc-cluster-private.h \
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2015 MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef MONGOC_CLIENT_POOL_PRIVATE_H
18+
#define MONGOC_CLIENT_POOL_PRIVATE_H
19+
20+
#if !defined (MONGOC_I_AM_A_DRIVER) && !defined (MONGOC_COMPILATION)
21+
#error "Only <mongoc.h> can be included directly."
22+
#endif
23+
24+
#include <bson.h>
25+
26+
#include "mongoc-client-pool.h"
27+
28+
BSON_BEGIN_DECLS
29+
30+
size_t mongoc_client_pool_get_size(mongoc_client_pool_t *pool);
31+
32+
BSON_END_DECLS
33+
34+
35+
#endif /* MONGOC_CLIENT_POOL_PRIVATE_H */

src/mongoc/mongoc-client-pool.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ mongoc_client_pool_push (mongoc_client_pool_t *pool,
205205
pool->size--;
206206
}
207207

208-
if ((client->cluster.state == MONGOC_CLUSTER_STATE_HEALTHY) ||
208+
if ((client->cluster.state == MONGOC_CLUSTER_STATE_HEALTHY) ||
209209
(client->cluster.state == MONGOC_CLUSTER_STATE_BORN)) {
210210
mongoc_mutex_lock (&pool->mutex);
211211
_mongoc_queue_push_tail (&pool->queue, client);
212212
} else if (_mongoc_cluster_reconnect (&client->cluster, NULL)) {
213213
mongoc_mutex_lock (&pool->mutex);
214214
_mongoc_queue_push_tail (&pool->queue, client);
215-
}else {
215+
} else {
216216
mongoc_client_destroy (client);
217217
mongoc_mutex_lock (&pool->mutex);
218218
pool->size--;
@@ -227,15 +227,15 @@ mongoc_client_pool_push (mongoc_client_pool_t *pool,
227227
size_t
228228
mongoc_client_pool_get_size (mongoc_client_pool_t *pool)
229229
{
230+
size_t size = 0;
231+
230232
ENTRY;
231233

232234
bson_return_if_fail (pool);
233235

234-
size_t size = 0;
235-
236236
mongoc_mutex_lock (&pool->mutex);
237237
size = pool->size;
238238
mongoc_mutex_unlock (&pool->mutex);
239239

240-
RETURN (size);
240+
RETURN (size);
241241
}

src/mongoc/mongoc-client-pool.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void mongoc_client_pool_set_ssl_opts (mongoc_client_pool_t *p
4848
const mongoc_ssl_opt_t *opts);
4949
#endif
5050

51-
size_t mongoc_client_pool_get_size(mongoc_client_pool_t *pool);
5251

5352
BSON_END_DECLS
5453

tests/test-mongoc-client-pool.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <mongoc.h>
2+
#include "mongoc-client-pool-private.h"
23
#include "mongoc-array-private.h"
34

45

@@ -48,29 +49,29 @@ test_mongoc_client_pool_min_size_dispose (void)
4849
mongoc_array_t conns;
4950
int i;
5051

51-
_mongoc_array_init(&conns, sizeof client);
52+
_mongoc_array_init (&conns, sizeof client);
5253

53-
uri = mongoc_uri_new("mongodb://127.0.0.1?maxpoolsize=10&minpoolsize=3");
54-
pool = mongoc_client_pool_new(uri);
54+
uri = mongoc_uri_new ("mongodb://127.0.0.1?maxpoolsize=10&minpoolsize=3");
55+
pool = mongoc_client_pool_new (uri);
5556

5657
for (i = 0; i < 10; i++) {
57-
client = mongoc_client_pool_pop(pool);
58-
assert(client);
59-
_mongoc_array_append_val(&conns, client);
60-
assert(mongoc_client_pool_get_size(pool) == i+1);
58+
client = mongoc_client_pool_pop (pool);
59+
assert (client);
60+
_mongoc_array_append_val (&conns, client);
61+
assert (mongoc_client_pool_get_size (pool) == i + 1);
6162
}
62-
63+
6364
for (i = 0; i < 10; i++) {
64-
client = _mongoc_array_index(&conns,mongoc_client_t *, i);
65-
assert(client);
66-
mongoc_client_pool_push(pool, client);
65+
client = _mongoc_array_index (&conns, mongoc_client_t *, i);
66+
assert (client);
67+
mongoc_client_pool_push (pool, client);
6768
}
6869

69-
assert(mongoc_client_pool_get_size(pool) == 3);
70-
_mongoc_array_clear(&conns);
71-
_mongoc_array_destroy(&conns);
72-
mongoc_uri_destroy(uri);
73-
mongoc_client_pool_destroy(pool);
70+
assert (mongoc_client_pool_get_size (pool) == 3);
71+
_mongoc_array_clear (&conns);
72+
_mongoc_array_destroy (&conns);
73+
mongoc_uri_destroy (uri);
74+
mongoc_client_pool_destroy (pool);
7475
}
7576

7677
void

0 commit comments

Comments
 (0)