void HTTPAcceptor::bind() { if (_rep) { MessageLoaderParms parms("Common.HTTPAcceptor.ALREADY_BOUND", "HTTPAcceptor already bound"); throw BindFailedException(parms); } _rep = new HTTPAcceptorRep(_connectionType); // bind address _bind(); }
void CIMServer::bind() { PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::bind()"); if (_acceptors.size() == 0) { MessageLoaderParms mlp = MessageLoaderParms( "Server.CIMServer.BIND_FAILED", "No CIM Server connections are enabled."); throw BindFailedException(mlp); } for (Uint32 i=0; i<_acceptors.size(); i++) { _acceptors[i]->bind(); } PEG_METHOD_EXIT(); }
/** _bind - creates a new server socket and bind socket to the port address. If PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET is not defined, the port number is ignored and a domain socket is bound. */ void HTTPAcceptor::_bind() { #ifdef PEGASUS_OS_PASE AutoPtr<PaseCcsid> ccsid; #endif PEGASUS_ASSERT(_rep != 0); // Create address: memset(_rep->address, 0, _rep->address_size); if (_connectionType == LOCAL_CONNECTION) { #ifndef PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET // // Make sure the local domain socket can be owned by the cimserver // user. Otherwise, the bind may fail with a vague "bind failed" // error. // #ifdef PEGASUS_OS_PASE // PASE domain socket needs ccsid 819 int orig_ccsid; orig_ccsid = _SETCCSID(-1); if (orig_ccsid == -1) { PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, "HTTPAcceptor::_bind: Can not get current PASE CCSID."); orig_ccsid = 1208; } ccsid.reset(new PaseCcsid(819, orig_ccsid)); #endif if (System::exists(PEGASUS_LOCAL_DOMAIN_SOCKET_PATH)) { if (!System::removeFile(PEGASUS_LOCAL_DOMAIN_SOCKET_PATH)) { throw CannotRemoveFile(PEGASUS_LOCAL_DOMAIN_SOCKET_PATH); } } reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_family = AF_UNIX; strcpy(reinterpret_cast<struct sockaddr_un*>(_rep->address)->sun_path, PEGASUS_LOCAL_DOMAIN_SOCKET_PATH); #else PEGASUS_ASSERT(false); #endif } #ifdef PEGASUS_ENABLE_IPV6 else if (_connectionType == IPV6_CONNECTION) { reinterpret_cast<struct sockaddr_in6*>(_rep->address)->sin6_addr = in6addr_any; reinterpret_cast<struct sockaddr_in6*>(_rep->address)->sin6_family = AF_INET6; reinterpret_cast<struct sockaddr_in6*>(_rep->address)->sin6_port = htons(_portNumber); } #endif else if(_connectionType == IPV4_CONNECTION) { reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_addr.s_addr = INADDR_ANY; reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_family = AF_INET; reinterpret_cast<struct sockaddr_in*>(_rep->address)->sin_port = htons(_portNumber); } else { PEGASUS_ASSERT(false); } // Create socket: if (_connectionType == LOCAL_CONNECTION) { _rep->socket = Socket::createSocket(AF_UNIX, SOCK_STREAM, 0); } #ifdef PEGASUS_ENABLE_IPV6 else if (_connectionType == IPV6_CONNECTION) { _rep->socket = Socket::createSocket(PF_INET6, SOCK_STREAM, IPPROTO_TCP); } #endif else if (_connectionType == IPV4_CONNECTION) { _rep->socket = Socket::createSocket(PF_INET, SOCK_STREAM, IPPROTO_TCP); } else { PEGASUS_ASSERT(false); } if (_rep->socket < 0) { delete _rep; _rep = 0; MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_CREATE_SOCKET", "Failed to create socket"); throw BindFailedException(parms); } Socket::disableBlocking(_rep->socket); // set the close-on-exec bit for this file handle. // any unix that forks needs this bit set. #if !defined PEGASUS_OS_TYPE_WINDOWS && !defined(PEGASUS_OS_VMS) int sock_flags; if ((sock_flags = fcntl(_rep->socket, F_GETFD, 0)) < 0) { PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, "HTTPAcceptor::_bind: fcntl(F_GETFD) failed"); } else { sock_flags |= FD_CLOEXEC; if (fcntl(_rep->socket, F_SETFD, sock_flags) < 0) { PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, "HTTPAcceptor::_bind: fcntl(F_SETFD) failed"); } } #endif // // Set the socket option SO_REUSEADDR to reuse the socket address so // that we can rebind to a new socket using the same address when we // need to resume the cimom as a result of a timeout during a Shutdown // operation. // int opt=1; if (setsockopt(_rep->socket, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(opt)) < 0) { delete _rep; _rep = 0; MessageLoaderParms parms("Common.HTTPAcceptor.FAILED_SET_SOCKET_OPTION", "Failed to set socket option"); throw BindFailedException(parms); } // // Bind socket to port: // if (::bind(_rep->socket, _rep->address, _rep->address_size) < 0) { MessageLoaderParms parms( "Common.HTTPAcceptor.FAILED_BIND_SOCKET_DETAIL", "Failed to bind socket on port $0: $1.", _portNumber, PEGASUS_SYSTEM_NETWORK_ERRORMSG_NLS); delete _rep; _rep = 0; throw BindFailedException(parms); } // // Get the actual port value used if the caller specified a port value of 0. // if (_portNumber == 0) { sockaddr_in buf; SocketLength bufSize = sizeof(buf); if (getsockname(_rep->socket, reinterpret_cast<sockaddr *>(&buf), &bufSize) == 0 ) { _portNumber = ntohs(buf.sin_port); } } // // Change permissions on Linux local domain socket to allow writes by // others. // #if !defined(PEGASUS_DISABLE_LOCAL_DOMAIN_SOCKET) && \ (defined(PEGASUS_PLATFORM_LINUX_GENERIC_GNU) || \ defined(PEGASUS_OS_ZOS) || \ defined(PEGASUS_OS_PASE)) if (_connectionType == LOCAL_CONNECTION) { if (::chmod(PEGASUS_LOCAL_DOMAIN_SOCKET_PATH, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH ) < 0 ) { MessageLoaderParms parms( "Common.HTTPAcceptor.FAILED_SET_LDS_FILE_OPTION", "Failed to set permission on local domain socket {0}: {1}.", PEGASUS_LOCAL_DOMAIN_SOCKET_PATH, PEGASUS_SYSTEM_ERRORMSG_NLS ); delete _rep; _rep = 0; throw BindFailedException(parms); } } #endif // Set up listening on the given socket: //int const _maxConnectionQueueLength = 15; if (::listen(_rep->socket, _maxConnectionQueueLength) < 0) { MessageLoaderParms parms( "Common.HTTPAcceptor.FAILED_LISTEN_SOCKET", "Failed to listen on socket {0}: {1}.", (int)_rep->socket,PEGASUS_SYSTEM_NETWORK_ERRORMSG_NLS ); delete _rep; _rep = 0; throw BindFailedException(parms); } // Register to receive SocketMessages on this socket: if (-1 == ( _entry_index = _monitor->solicitSocketMessages( _rep->socket, SocketMessage::READ | SocketMessage::EXCEPTION, getQueueId(), MonitorEntry::TYPE_ACCEPTOR))) { delete _rep; _rep = 0; MessageLoaderParms parms( "Common.HTTPAcceptor.FAILED_SOLICIT_SOCKET_MESSAGES", "Failed to solicit socket messaeges"); throw BindFailedException(parms); } }
MessageQueueService::MessageQueueService( const char *name, Uint32 queueID, Uint32 capabilities, Uint32 mask) : Base(name, true, queueID), _mask(mask), _die(0), _threads(0), _incoming(true, 0), _incoming_queue_shutdown(0) { _capabilities = (capabilities | module_capabilities::async); _default_op_timeout.tv_sec = 30; _default_op_timeout.tv_usec = 100; max_threads_per_svc_queue = MAX_THREADS_PER_SVC_QUEUE; // if requested threads gt MAX_THREADS_PER_SVC_QUEUE_LIMIT // then set to MAX_THREADS_PER_SVC_QUEUE_LIMIT if (max_threads_per_svc_queue > MAX_THREADS_PER_SVC_QUEUE_LIMIT) { max_threads_per_svc_queue = MAX_THREADS_PER_SVC_QUEUE_LIMIT; } // if requested threads eq 0 (unlimited) // then set to MAX_THREADS_PER_SVC_QUEUE_LIMIT if (max_threads_per_svc_queue == 0) { max_threads_per_svc_queue = MAX_THREADS_PER_SVC_QUEUE_DEFAULT; } // cout << "MAX_THREADS_PER_SVC_QUEUE = " << MAX_THREADS_PER_SVC_QUEUE << endl; // cout << "max_threads_per_svc_queue set to = " << max_threads_per_svc_queue << endl; AutoMutex autoMut(_meta_dispatcher_mutex); if (_meta_dispatcher == 0) { _stop_polling = 0; PEGASUS_ASSERT(_service_count.value() == 0); _meta_dispatcher = new cimom(); if (_meta_dispatcher == NULL) { throw NullPointer(); } // _thread_pool = new ThreadPool(initial_cnt, "MessageQueueService", // minimum_cnt, maximum_cnt, deallocateWait); // _thread_pool = new ThreadPool(0, "MessageQueueService", 0, 0, deallocateWait); } _service_count++; if (false == register_service(name, _capabilities, _mask)) { //l10n //throw BindFailedException("MessageQueueService Base Unable to register with Meta Dispatcher"); MessageLoaderParms parms("Common.MessageQueueService.UNABLE_TO_REGISTER", "MessageQueueService Base Unable to register with Meta Dispatcher"); throw BindFailedException(parms); } _polling_list.insert_last(this); }