From 58f1ee7ff0057675bbf14d10c0b9c69e706601c1 Mon Sep 17 00:00:00 2001 From: Daniel Swarbrick Date: Sun, 21 Oct 2012 22:59:51 +0200 Subject: [PATCH] mod_cdr_mongodb: add post-v0.6 patch to driver to support Unix domain sockets --- .../mod_cdr_mongodb/driver/src/env_posix.c | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/mod/event_handlers/mod_cdr_mongodb/driver/src/env_posix.c b/src/mod/event_handlers/mod_cdr_mongodb/driver/src/env_posix.c index f1020ca80d..ab0e166cf9 100644 --- a/src/mod/event_handlers/mod_cdr_mongodb/driver/src/env_posix.c +++ b/src/mod/event_handlers/mod_cdr_mongodb/driver/src/env_posix.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,36 @@ int mongo_env_set_socket_op_timeout( mongo *conn, int millis ) { return MONGO_OK; } +int mongo_env_unix_socket_connect( mongo *conn, const char *sock_path ) { + struct sockaddr_un addr; + int status, len; + + conn->connected = 0; + + conn->sock = socket( AF_UNIX, SOCK_STREAM, 0 ); + + if ( conn->sock < 0 ) { + conn->sock = 0; + return MONGO_ERROR; + } + + addr.sun_family = AF_UNIX; + strncpy( addr.sun_path, sock_path, sizeof(addr.sun_path) - 1 ); + len = sizeof( addr ); + + status = connect( conn->sock, (struct sockaddr *) &addr, len ); + if( status < 0 ){ + mongo_env_close_socket( conn->sock ); + conn->sock = 0; + conn->err = MONGO_CONN_FAIL; + return MONGO_ERROR; + } + + conn->connected = 1; + + return MONGO_OK; +} + int mongo_env_socket_connect( mongo *conn, const char *host, int port ) { char port_str[NI_MAXSERV]; int status; @@ -107,6 +138,10 @@ int mongo_env_socket_connect( mongo *conn, const char *host, int port ) { struct addrinfo *ai_list = NULL; struct addrinfo *ai_ptr = NULL; + if ( port < 0 ) { + return mongo_env_unix_socket_connect( conn, host ); + } + conn->sock = 0; conn->connected = 0; sprintf(port_str,"%d",port);