MongoDB C++ Driver  legacy-1.1.2
Public Member Functions | List of all members
mongo::Socket Class Reference

thin wrapped around file descriptor and system calls todo: ssl More...

#include <sock.h>

Public Member Functions

 Socket (double so_timeout=0, logger::LogSeverity logLevel=logger::LogSeverity::Log())
 In some cases the timeout will actually be 2x this value - eg we do a partial send, then the timeout fires, then we try to send again, then the timeout fires again with no data sent, then we detect that the other side is down. More...
 
bool connect (SockAddr &farEnd)
 The correct way to initialize and connect to a socket is as follows: (1) construct the SockAddr, (2) check whether the SockAddr isValid(), (3) if the SockAddr is valid, a Socket may then try to connect to that SockAddr. More...
 
std::string doSSLHandshake (const char *firstBytes=NULL, int len=0)
 This function calls SSL_accept() if SSL-encrypted sockets are desired. More...
 
uint64_t getSockCreationMicroSec () const
 

Detailed Description

thin wrapped around file descriptor and system calls todo: ssl

Constructor & Destructor Documentation

mongo::Socket::Socket ( double  so_timeout = 0,
logger::LogSeverity  logLevel = logger::LogSeverity::Log() 
)

In some cases the timeout will actually be 2x this value - eg we do a partial send, then the timeout fires, then we try to send again, then the timeout fires again with no data sent, then we detect that the other side is down.

Generally you don't want a timeout, you should be very prepared for errors if you set one.

Member Function Documentation

bool mongo::Socket::connect ( SockAddr farEnd)

The correct way to initialize and connect to a socket is as follows: (1) construct the SockAddr, (2) check whether the SockAddr isValid(), (3) if the SockAddr is valid, a Socket may then try to connect to that SockAddr.

It is critical to check the return value of connect as a false return indicates that there was an error, and the Socket failed to connect to the given SockAddr. This failure may be due to ConnectBG returning an error, or due to a timeout on connection, or due to the system socket deciding the socket is invalid.

std::string mongo::Socket::doSSLHandshake ( const char *  firstBytes = NULL,
int  len = 0 
)

This function calls SSL_accept() if SSL-encrypted sockets are desired.

SSL_accept() waits until the remote host calls SSL_connect(). The return value is the subject name of any client certificate provided during the handshake.

is the first bytes received on the socket used to detect the connection SSL, is the number of bytes

This function may throw SocketException.

uint64_t mongo::Socket::getSockCreationMicroSec ( ) const
inline
Returns
the time when the socket was opened.

The documentation for this class was generated from the following file: