0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

Unix socket support (must use --nohttpinterface for now) SERVER-866

This commit is contained in:
Mathias Stearn 2010-04-02 19:24:59 -04:00
parent b6744bbde6
commit a9382d41f0
4 changed files with 29 additions and 10 deletions

View File

@ -446,7 +446,11 @@ namespace mongo {
ip = hostbyname(ip.c_str());
} else {
port = CmdLine::DefaultDBPort;
ip = hostbyname( serverAddress.c_str() );
if (serverAddress.find( "/" ) == string::npos){
ip = hostbyname( serverAddress.c_str() );
} else {
ip = serverAddress;
}
}
if( ip.empty() ) {
stringstream ss;

View File

@ -65,7 +65,7 @@ connect = function( url , user , pass ){
if ( user && ! pass )
throw "you specified a user and not a password. either you need a password, or you're using the old connect api";
var idx = url.indexOf( "/" );
var idx = url.lastIndexOf( "/" );
var db;

View File

@ -55,6 +55,9 @@ namespace mongo {
log() << "ERROR: listen(): invalid socket? " << OUTPUT_ERRNO << endl;
return false;
}
if (me.getType() == AF_UNIX){
unlink(me.getAddr().c_str());
}
prebindOptions( sock );
if ( ::bind(sock, me.raw(), me.addressSize) != 0 ) {
log() << "listen(): bind() failed " << OUTPUT_ERRNO << " for port: " << port << endl;
@ -89,7 +92,8 @@ namespace mongo {
log() << "Listener: accept() returns " << s << " " << OUTPUT_ERRNOX(x) << endl;
continue;
}
disableNagle(s);
if (from.getType() != AF_UNIX)
disableNagle(s);
if ( ! cmdLine.quiet ) log() << "connection accepted from " << from.toString() << " #" << ++connNumber << endl;
accepted( new MessagingPort(s, from) );
}
@ -233,7 +237,8 @@ namespace mongo {
return false;
}
disableNagle(sock);
if (farEnd.getType() != AF_UNIX)
disableNagle(sock);
#ifdef SO_NOSIGPIPE
// osx

View File

@ -270,12 +270,22 @@ namespace mongo {
}
inline SockAddr::SockAddr(const char * iporhost , int port) {
string ip = hostbyname( iporhost );
memset(as<sockaddr_in>().sin_zero, 0, sizeof(as<sockaddr_in>().sin_zero));
as<sockaddr_in>().sin_family = AF_INET;
as<sockaddr_in>().sin_port = htons(port);
as<sockaddr_in>().sin_addr.s_addr = inet_addr(ip.c_str());
addressSize = sizeof(sockaddr_in);
if (strchr(iporhost, '/')){
#ifdef _WIN32
uassert(13080, "no unix socket support on windows", false);
#endif
uassert(13079, "path to unix socket too long", strlen(iporhost) < sizeof(as<sockaddr_un>().sun_path));
as<sockaddr_un>().sun_family = AF_UNIX;
strcpy(as<sockaddr_un>().sun_path, iporhost);
addressSize = sizeof(sockaddr_un);
} else {
string ip = hostbyname( iporhost );
memset(as<sockaddr_in>().sin_zero, 0, sizeof(as<sockaddr_in>().sin_zero));
as<sockaddr_in>().sin_family = AF_INET;
as<sockaddr_in>().sin_port = htons(port);
as<sockaddr_in>().sin_addr.s_addr = inet_addr(ip.c_str());
addressSize = sizeof(sockaddr_in);
}
}
inline string getHostName() {