Skip to content

Commit 5249890

Browse files
committed
Merge pull request #267 from bjori/master
CDRIVER-843 & friends
2 parents f2ee4c3 + b24d1d2 commit 5249890

14 files changed

+564
-131
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ set (HEADERS
126126
${SOURCE_DIR}/src/mongoc/mongoc-opcode.h
127127
${SOURCE_DIR}/src/mongoc/mongoc-read-prefs.h
128128
${SOURCE_DIR}/src/mongoc/mongoc-socket.h
129+
${SOURCE_DIR}/src/mongoc/mongoc-socket-private.h
129130
${SOURCE_DIR}/src/mongoc/mongoc-stream.h
130131
${SOURCE_DIR}/src/mongoc/mongoc-stream-buffered.h
131132
${SOURCE_DIR}/src/mongoc/mongoc-stream-file.h

src/mongoc/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ INST_H_FILES = \
6767
src/mongoc/mongoc-sasl-private.h \
6868
src/mongoc/mongoc-scram-private.h \
6969
src/mongoc/mongoc-socket.h \
70+
src/mongoc/mongoc-socket-private.h \
7071
src/mongoc/mongoc-ssl-private.h \
7172
src/mongoc/mongoc-stream-buffered.h \
7273
src/mongoc/mongoc-stream-file.h \

src/mongoc/mongoc-buffer.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
#include <bson.h>
19-
#include <errno.h>
2019
#include <stdarg.h>
2120

2221
#include "mongoc-error.h"

src/mongoc/mongoc-cluster.c

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "mongoc-config.h"
1919

20-
#include <errno.h>
2120
#ifdef MONGOC_ENABLE_SASL
2221
#include <sasl/sasl.h>
2322
#include <sasl/saslutil.h>
@@ -954,9 +953,9 @@ _mongoc_cluster_run_command (mongoc_cluster_t *cluster,
954953
_mongoc_rpc_swab_to_le(&rpc);
955954

956955
DUMP_IOVEC (((mongoc_iovec_t *)ar.data), ((mongoc_iovec_t *)ar.data), ar.len);
957-
if (!mongoc_stream_writev(node->stream, ar.data, ar.len,
958-
cluster->sockettimeoutms)) {
959-
GOTO(failure);
956+
if (!_mongoc_stream_writev_full (node->stream, ar.data, ar.len,
957+
cluster->sockettimeoutms, error)) {
958+
GOTO (failure);
960959
}
961960

962961
if (!_mongoc_buffer_append_from_stream(&buffer, node->stream, 4,
@@ -2892,21 +2891,11 @@ _mongoc_cluster_sendv (mongoc_cluster_t *cluster,
28922891

28932892
iov = cluster->iov.data;
28942893
iovcnt = cluster->iov.len;
2895-
errno = 0;
28962894

28972895
BSON_ASSERT (cluster->iov.len);
28982896

2899-
if (!mongoc_stream_writev (node->stream, iov, iovcnt,
2900-
cluster->sockettimeoutms)) {
2901-
char buf[128];
2902-
char * errstr;
2903-
errstr = bson_strerror_r(errno, buf, sizeof buf);
2904-
2905-
bson_set_error (error,
2906-
MONGOC_ERROR_STREAM,
2907-
MONGOC_ERROR_STREAM_SOCKET,
2908-
"Failure during socket delivery: %s",
2909-
errstr);
2897+
if (!_mongoc_stream_writev_full (node->stream, iov, iovcnt,
2898+
cluster->sockettimeoutms, error)) {
29102899
_mongoc_cluster_disconnect_node (cluster, node);
29112900
RETURN (0);
29122901
}
@@ -3037,17 +3026,8 @@ _mongoc_cluster_try_sendv (mongoc_cluster_t *cluster,
30373026

30383027
DUMP_IOVEC (iov, iov, iovcnt);
30393028

3040-
if (!mongoc_stream_writev (node->stream, iov, iovcnt,
3041-
cluster->sockettimeoutms)) {
3042-
char buf[128];
3043-
char * errstr;
3044-
errstr = bson_strerror_r(errno, buf, sizeof buf);
3045-
3046-
bson_set_error (error,
3047-
MONGOC_ERROR_STREAM,
3048-
MONGOC_ERROR_STREAM_SOCKET,
3049-
"Failure during socket delivery: %s",
3050-
errstr);
3029+
if (!_mongoc_stream_writev_full (node->stream, iov, iovcnt,
3030+
cluster->sockettimeoutms, error)) {
30513031
_mongoc_cluster_disconnect_node (cluster, node);
30523032
RETURN (0);
30533033
}

src/mongoc/mongoc-iovec.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121

2222
#include <bson.h>
2323

24-
#ifndef _WIN32
24+
#ifdef _WIN32
25+
# include <stddef.h>
26+
#else
2527
# include <sys/uio.h>
2628
#endif
2729

28-
2930
BSON_BEGIN_DECLS
3031

3132

@@ -35,6 +36,11 @@ typedef struct
3536
u_long iov_len;
3637
char *iov_base;
3738
} mongoc_iovec_t;
39+
40+
BSON_STATIC_ASSERT(sizeof(mongoc_iovec_t) == sizeof(WSABUF));
41+
BSON_STATIC_ASSERT(offsetof(mongoc_iovec_t, iov_base) == offsetof(WSABUF, buf));
42+
BSON_STATIC_ASSERT(offsetof(mongoc_iovec_t, iov_len) == offsetof(WSABUF, len));
43+
3844
#else
3945
typedef struct iovec mongoc_iovec_t;
4046
#endif

src/mongoc/mongoc-socket-private.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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_SOCKET_PRIVATE_H
18+
#define MONGOC_SOCKET_PRIVATE_H
19+
20+
#if !defined (MONGOC_INSIDE) && !defined (MONGOC_COMPILATION)
21+
# error "Only <mongoc.h> can be included directly."
22+
#endif
23+
24+
#include "mongoc-socket.h"
25+
26+
BSON_BEGIN_DECLS
27+
28+
struct _mongoc_socket_t
29+
{
30+
#ifdef _WIN32
31+
SOCKET sd;
32+
#else
33+
int sd;
34+
#endif
35+
int errno_;
36+
int domain;
37+
};
38+
39+
40+
BSON_END_DECLS
41+
42+
#endif /* MONGOC_SOCKET_PRIVATE_H */

0 commit comments

Comments
 (0)