summaryrefslogtreecommitdiff
path: root/util/net
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-07-06 11:34:07 -0400
committerEliot Horowitz <eliot@10gen.com>2011-07-06 17:50:09 -0400
commit36f0e51d71eb0dd7c5e5f598e0db383c48830382 (patch)
tree9983b34f304eeba62b5d76a4bb711c22260d99f7 /util/net
parent836db45ecf1d6154b226f35823ef51e1a2db773b (diff)
downloadmongo-36f0e51d71eb0dd7c5e5f598e0db383c48830382.tar.gz
net cleaning: re-organizing file
Diffstat (limited to 'util/net')
-rw-r--r--util/net/sock.cpp47
1 files changed, 27 insertions, 20 deletions
diff --git a/util/net/sock.cpp b/util/net/sock.cpp
index a81462d5696..bd860c107fd 100644
--- a/util/net/sock.cpp
+++ b/util/net/sock.cpp
@@ -20,12 +20,12 @@
namespace mongo {
- static mongo::mutex sock_mutex("sock_mutex");
-
static bool ipv6 = false;
void enableIPv6(bool state) { ipv6 = state; }
bool IPv6Enabled() { return ipv6; }
+ // --- SockAddr
+
SockAddr::SockAddr(int sourcePort) {
memset(as<sockaddr_in>().sin_zero, 0, sizeof(as<sockaddr_in>().sin_zero));
as<sockaddr_in>().sin_family = AF_INET;
@@ -97,6 +97,11 @@ namespace mongo {
return false;
}
+ SockAddr unknownAddress( "0.0.0.0", 0 );
+
+
+ // ------ hostname -------------------
+
string hostbyname(const char *hostname) {
string addr = SockAddr(hostname, 0).getAddr();
if (addr == "0.0.0.0")
@@ -105,24 +110,6 @@ namespace mongo {
return addr;
}
-#if defined(_WIN32)
- namespace {
- struct WinsockInit {
- WinsockInit() {
- WSADATA d;
- if ( WSAStartup(MAKEWORD(2,2), &d) != 0 ) {
- out() << "ERROR: wsastartup failed " << errnoWithDescription() << endl;
- problem() << "ERROR: wsastartup failed " << errnoWithDescription() << endl;
- dbexit( EXIT_NTSERVICE_ERROR );
- }
- }
- } winsock_init;
- }
-#endif
-
- SockAddr unknownAddress( "0.0.0.0", 0 );
-
-
string _hostNameCached;
static void _hostNameCachedInit() {
_hostNameCached = getHostName();
@@ -134,6 +121,8 @@ namespace mongo {
return _hostNameCached;
}
+ // --------- SocketException ----------
+
string SocketException::toString() const {
stringstream ss;
ss << _ei.code << " socket exception [" << _type << "] ";
@@ -148,6 +137,24 @@ namespace mongo {
}
+ // ---------- global init -------------
+
+
+#if defined(_WIN32)
+ struct WinsockInit {
+ WinsockInit() {
+ WSADATA d;
+ if ( WSAStartup(MAKEWORD(2,2), &d) != 0 ) {
+ out() << "ERROR: wsastartup failed " << errnoWithDescription() << endl;
+ problem() << "ERROR: wsastartup failed " << errnoWithDescription() << endl;
+ dbexit( EXIT_NTSERVICE_ERROR );
+ }
+ }
+ } winsock_init;
+#endif
+
+
+
} // namespace mongo