bool SocketServer::commonListen() { // ### should be able to customize the backlog enum { Backlog = 128 }; if (::listen(fd, Backlog) < 0) { fprintf(stderr, "::listen() failed with errno: %s\n", Rct::strerror().constData()); serverError(this, ListenError); close(); return false; } if (EventLoop::SharedPtr loop = EventLoop::eventLoop()) { loop->registerSocket(fd, EventLoop::SocketRead, //|EventLoop::SocketWrite, std::bind(&SocketServer::socketCallback, this, std::placeholders::_1, std::placeholders::_2)); if (!SocketClient::setFlags(fd, O_NONBLOCK, F_GETFL, F_SETFL)) { serverError(this, InitializeError); close(); return false; } } return true; }
bool SocketServer::listen(uint16_t port, Mode mode) { close(); isIPv6 = (mode & IPv6); fd = ::socket(isIPv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0); if (fd < 0) { // bad serverError(this, InitializeError); return false; } int e; int flags = 1; #ifdef HAVE_NOSIGPIPE e = ::setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&flags, sizeof(int)); if (e == -1) { serverError(this, InitializeError); close(); return false; } #endif // turn on nodelay flags = 1; e = ::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &flags, sizeof(int)); if (e == -1) { serverError(this, InitializeError); close(); return false; } #ifdef HAVE_CLOEXEC SocketClient::setFlags(fd, FD_CLOEXEC, F_GETFD, F_SETFD); #endif // ### support specific interfaces sockaddr_in addr4; sockaddr_in6 addr6; sockaddr* addr = 0; size_t size = 0; if (isIPv6) { addr = reinterpret_cast<sockaddr*>(&addr6); size = sizeof(sockaddr_in6); memset(&addr6, '\0', sizeof(sockaddr_in6)); addr6.sin6_family = AF_INET6; addr6.sin6_addr = in6addr_any; addr6.sin6_port = htons(port); } else { addr = reinterpret_cast<sockaddr*>(&addr4); size = sizeof(sockaddr_in); memset(&addr4, '\0', sizeof(sockaddr_in)); addr4.sin_family = AF_INET; addr4.sin_addr.s_addr = INADDR_ANY; addr4.sin_port = htons(port); } return commonBindAndListen(addr, size); }
/** * Slot launching the server * Actually creating an instance of Server and push it into a thread * The thread is then started * @brief Controler::runServer */ void Controler::runServer() { port_ = window_->getPort(); mode_ = "server"; qDebug()<<"launching server on port "+ QString::number(port_)+"..."; //update GUI window_->setServerGui(port_); //create a server thread to avoid gui freeze server_ = new Server(this); serverThread_ = new QThread; server_->moveToThread(serverThread_); //action listeners connect(server_,SIGNAL(error(QString)),this,SLOT(serverError(QString))); connect(serverThread_,SIGNAL(started()),server_,SLOT(run())); connect(server_,SIGNAL(finished()),serverThread_,SLOT(quit())); connect(server_,SIGNAL(finished()),serverThread_,SLOT(deleteLater())); connect(serverThread_,SIGNAL(finished()),serverThread_,SLOT(deleteLater())); serverThread_->start(); }
bool SocketServer::listen(const Path &p) { close(); fd = ::socket(PF_UNIX, SOCK_STREAM, 0); if (fd < 0) { // bad serverError(this, InitializeError); return false; } #ifdef HAVE_CLOEXEC SocketClient::setFlags(fd, FD_CLOEXEC, F_GETFD, F_SETFD); #endif sockaddr_un addr; memset(&addr, '\0', sizeof(sockaddr_un)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, p.constData(), sizeof(addr.sun_path)); if (commonBindAndListen(reinterpret_cast<sockaddr*>(&addr), sizeof(sockaddr_un))) { path = p; return true; } return false; }
void SocketServer::socketCallback(int /*fd*/, int mode) { sockaddr_in client4; sockaddr_in6 client6; sockaddr* client = 0; socklen_t size = 0; if (isIPv6) { size = sizeof(client6); client = reinterpret_cast<sockaddr*>(&client6); } else { size = sizeof(client4); client = reinterpret_cast<sockaddr*>(&client4); } int e; if (! ( mode & EventLoop::SocketRead ) ) return; for (;;) { eintrwrap(e, ::accept(fd, client, &size)); if (e == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { return; } serverError(this, AcceptError); close(); return; } //EventLoop::eventLoop()->unregisterSocket( fd ); accepted.push(e); serverNewConnection(this); } }
void Client::showMessage(QString text, ServerMessages::MessageTyp typ) { switch(typ) { case ServerMessages::INFORMATION: { QMessageBox::information(this, tr("Information"), text); break; } case ServerMessages::ERRORMESSAGE: { callTerminated(); QMessageBox::critical(this, tr("Error"), text); emit serverError(); break; } case ServerMessages::WARNING: { QMessageBox::warning(this, tr("Warning"), text); break; } default: { } } }
BtLocalDevice::BtLocalDevice(QObject *parent) : QObject(parent), securityFlags(QBluetooth::NoSecurity) { localDevice = new QBluetoothLocalDevice(this); connect(localDevice, SIGNAL(error(QBluetoothLocalDevice::Error)), this, SIGNAL(error(QBluetoothLocalDevice::Error))); connect(localDevice, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), this, SIGNAL(hostModeStateChanged())); connect(localDevice, SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)), this, SLOT(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing))); connect(localDevice, SIGNAL(deviceConnected(QBluetoothAddress)), this, SLOT(connected(QBluetoothAddress))); connect(localDevice, SIGNAL(deviceDisconnected(QBluetoothAddress)), this, SLOT(disconnected(QBluetoothAddress))); connect(localDevice, SIGNAL(pairingDisplayConfirmation(QBluetoothAddress,QString)), this, SLOT(pairingDisplayConfirmation(QBluetoothAddress,QString))); if (localDevice->isValid()) { deviceAgent = new QBluetoothDeviceDiscoveryAgent(this); connect(deviceAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); connect(deviceAgent, SIGNAL(finished()), this, SLOT(discoveryFinished())); connect(deviceAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(discoveryError(QBluetoothDeviceDiscoveryAgent::Error))); connect(deviceAgent, SIGNAL(canceled()), this, SLOT(discoveryCanceled())); serviceAgent = new QBluetoothServiceDiscoveryAgent(this); connect(serviceAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)), this, SLOT(serviceDiscovered(QBluetoothServiceInfo))); connect(serviceAgent, SIGNAL(finished()), this, SLOT(serviceDiscoveryFinished())); connect(serviceAgent, SIGNAL(canceled()), this, SLOT(serviceDiscoveryCanceled())); connect(serviceAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), this, SLOT(serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error))); socket = new QBluetoothSocket(SOCKET_PROTOCOL, this); connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), this, SLOT(socketStateChanged(QBluetoothSocket::SocketState))); connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socketError(QBluetoothSocket::SocketError))); connect(socket, SIGNAL(connected()), this, SLOT(socketConnected())); connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(readData())); setSecFlags(socket->preferredSecurityFlags()); server = new QBluetoothServer(SOCKET_PROTOCOL, this); connect(server, SIGNAL(newConnection()), this, SLOT(serverNewConnection())); connect(server, SIGNAL(error(QBluetoothServer::Error)), this, SLOT(serverError(QBluetoothServer::Error))); } else { deviceAgent = 0; serviceAgent = 0; socket = 0; server = 0; } }
//***************************************************************************** // //! Initialize Connection Server //! //! \param none //! //! \return none //! //! \brief Waits for a connection where we will // //***************************************************************************** void initServer(void) { char portStr[12]; memset(portStr,0,sizeof(portStr)); // Open Server Socket serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (serverSocket == -1) { serverError(SERV_ERR_SOCKET); wlan_stop(); while(1) { __no_operation(); } } // Open port int port = SERVER_PORT; serverSocketAddr.sa_family = AF_INET; // Set the Port Number serverSocketAddr.sa_data[0] = (port & 0xFF00)>> 8; serverSocketAddr.sa_data[1] = (port & 0x00FF); memset (&serverSocketAddr.sa_data[2], 0, 4); if (bind(serverSocket, &serverSocketAddr, sizeof(sockaddr)) != 0) { serverError(SERV_ERR_BIND); return; } // Start Listening if (listen (serverSocket, 1) != 0) { serverError(SERV_ERR_LISTEN); return; } setCC3000MachineState(CC3000_SERVER_INIT); itoa(port, portStr, DECIMAL_BASE); }
DVRServer::DVRServer(int id, QObject *parent) : QObject(parent), m_configuration(id), m_devicesLoaded(false) { m_api = new ServerRequestManager(this); connect(&m_configuration, SIGNAL(changed()), this, SIGNAL(changed())); connect(m_api, SIGNAL(loginSuccessful()), SLOT(updateCameras())); connect(m_api, SIGNAL(disconnected()), SLOT(disconnectedSlot())); connect(m_api, SIGNAL(loginRequestStarted()), this, SIGNAL(loginRequestStarted())); connect(m_api, SIGNAL(loginSuccessful()), this, SIGNAL(loginSuccessful())); connect(m_api, SIGNAL(serverError(QString)), this, SIGNAL(serverError(QString))); connect(m_api, SIGNAL(loginError(QString)), this, SIGNAL(loginError(QString))); connect(m_api, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(m_api, SIGNAL(statusChanged(int)), this, SIGNAL(statusChanged(int))); connect(m_api, SIGNAL(onlineChanged(bool)), this, SIGNAL(onlineChanged(bool))); connect(&m_refreshTimer, SIGNAL(timeout()), SLOT(updateCameras())); }
bool SocketServer::commonBindAndListen(sockaddr* addr, size_t size) { if (::bind(fd, reinterpret_cast<sockaddr*>(addr), size) < 0) { serverError(this, BindError); close(); return false; } return commonListen(); }
char* cRequestPacket::extract_String() { if (serverError()) return NULL; int length = strlen((char*)&userData[packetPos]); if ((packetPos + length) > userDataLength) return NULL; char* str = new char[length + 1]; strcpy(str, (char*)&userData[packetPos]); packetPos += length + 1; return str; }
void PingPong::startServer() { setMessage(QStringLiteral("Starting the server")); //! [Starting the server] m_serverInfo = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); connect(m_serverInfo, SIGNAL(newConnection()), this, SLOT(clientConnected())); connect(m_serverInfo, SIGNAL(error(QBluetoothServer::Error)), this, SLOT(serverError(QBluetoothServer::Error))); const QBluetoothUuid uuid(serviceUuid); m_serverInfo->listen(uuid, QStringLiteral("PingPong server")); //! [Starting the server] setMessage(QStringLiteral("Server started, waiting for the client. You are the left player.")); // m_role is set to 1 if it is a server m_role = 1; Q_EMIT roleChanged(); }
void RemoteClient::loginResponse(ProtocolResponse *response) { if (response->getResponseCode() == RespOk) { Response_Login *resp = qobject_cast<Response_Login *>(response); if (!resp) { disconnectFromServer(); return; } setStatus(StatusLoggedIn); emit userInfoChanged(resp->getUserInfo()); emit buddyListReceived(resp->getBuddyList()); emit ignoreListReceived(resp->getIgnoreList()); } else { emit serverError(response->getResponseCode()); setStatus(StatusDisconnecting); } }
/*! Create a record-based SIM file access object for \a fileid and attach it to \a parent. The \a service parameter indicates the telephony service to use to access the file, or an empty string to use the default service. For example, \c 6F3C indicates the \i EFsms file. The \a fileid should be the complete hexadecimal path to the file on the SIM. For example, the \i EFsms file is numbered \c 6F3C underneath the \i DFtelecom directory (\c 7F10). Therefore, \a fileid should be \c 7F106F3C. */ QRecordBasedSimFile::QRecordBasedSimFile ( const QString& fileid, const QString& service, QObject *parent ) : QObject( parent ) { d = new QRecordBasedSimFilePrivate(); d->files = new QSimFiles( service, this ); d->fileid = fileid; d->reqid = QUuid::createUuid().toString(); connect( d->files, SIGNAL(error(QString,QTelephony::SimFileError)), this, SLOT(serverError(QString,QTelephony::SimFileError)) ); connect( d->files, SIGNAL(fileInfo(QString,int,int,QTelephony::SimFileType)), this, SLOT(serverFileInfo(QString,int,int)) ); connect( d->files, SIGNAL(readDone(QString,QByteArray,int)), this, SLOT(serverReadDone(QString,QByteArray,int)) ); connect( d->files, SIGNAL(writeDone(QString,int)), this, SLOT(serverWriteDone(QString,int)) ); }
//======================= // PUBLIC //======================= WebServer::WebServer() : QWebSocketServer("pc-restserver", QWebSocketServer::NonSecureMode){ csock = 0; //no current socket connected //Setup all the various settings idletimer = new QTimer(this); idletimer->setInterval(5000); //every 5 seconds idletimer->setSingleShot(true); //Any SSL changes /*QSslConfiguration ssl = this->sslConfiguration(); ssl.setProtocol(QSsl::SecureProtocols); this->setSslConfiguration(ssl);*/ //Setup Connections connect(idletimer, SIGNAL(timeout()), this, SLOT(checkIdle()) ); connect(this, SIGNAL(closed()), this, SLOT(ServerClosed()) ); connect(this, SIGNAL(serverError(QWebSocketProtocol::CloseCode)), this, SLOT(ServerError(QWebSocketProtocol::CloseCode)) ); connect(this, SIGNAL(newConnection()), this, SLOT(NewSocketConnection()) ); connect(this, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(NewConnectError(QAbstractSocket::SocketError)) ); connect(this, SIGNAL(originAuthenticationRequired(QWebSocketCorsAuthenticator*)), this, SLOT(OriginAuthRequired(QWebSocketCorsAuthenticator*)) ); connect(this, SIGNAL(peerVerifyError(const QSslError&)), this, SLOT(PeerVerifyError(const QSslError&)) ); connect(this, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(SslErrors(const QList<QSslError>&)) ); }
void ExistenceChecker::onError(const std::string &address, Kullo::Api::NetworkError error) { setLocked(false); switch (error) { case Kullo::Api::NetworkError::Server: Log.e() << "Server error."; emit serverError(QString::fromStdString(address)); break; case Kullo::Api::NetworkError::Protocol: Log.e() << "Protocol error."; emit protocolError(QString::fromStdString(address)); break; case Kullo::Api::NetworkError::Connection: Log.e() << "Connection error."; emit networkError(QString::fromStdString(address)); break; default: kulloAssert(false); } }
//=================== // PRIVATE //=================== bool WebServer::setupWebSocket(quint16 port){ WSServer = new QWebSocketServer("sysadm-server", QWebSocketServer::SecureMode, this); //SSL Configuration QSslConfiguration config = QSslConfiguration::defaultConfiguration(); QFile CF( QStringLiteral(SSLCERTFILE) ); if(CF.open(QIODevice::ReadOnly) ){ QSslCertificate CERT(&CF,QSsl::Pem); config.setLocalCertificate( CERT ); CF.close(); }else{ qWarning() << "Could not read WS certificate file:" << CF.fileName(); } QFile KF( QStringLiteral(SSLKEYFILE)); if(KF.open(QIODevice::ReadOnly) ){ QSslKey KEY(&KF, QSsl::Rsa, QSsl::Pem); config.setPrivateKey( KEY ); KF.close(); }else{ qWarning() << "Could not read WS key file:" << KF.fileName(); } config.setPeerVerifyMode(QSslSocket::VerifyNone); config.setProtocol(SSLVERSION); WSServer->setSslConfiguration(config); //Setup Connections connect(WSServer, SIGNAL(newConnection()), this, SLOT(NewSocketConnection()) ); connect(WSServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(NewConnectError(QAbstractSocket::SocketError)) ); // -- websocket specific signals connect(WSServer, SIGNAL(closed()), this, SLOT(ServerClosed()) ); connect(WSServer, SIGNAL(serverError(QWebSocketProtocol::CloseCode)), this, SLOT(ServerError(QWebSocketProtocol::CloseCode)) ); connect(WSServer, SIGNAL(originAuthenticationRequired(QWebSocketCorsAuthenticator*)), this, SLOT(OriginAuthRequired(QWebSocketCorsAuthenticator*)) ); connect(WSServer, SIGNAL(peerVerifyError(const QSslError&)), this, SLOT(PeerVerifyError(const QSslError&)) ); connect(WSServer, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(SslErrors(const QList<QSslError>&)) ); connect(WSServer, SIGNAL(acceptError(QAbstractSocket::SocketError)), this, SLOT(ConnectError(QAbstractSocket::SocketError)) ); //Now start the server return WSServer->listen(QHostAddress::Any, port); }
MainWindow::MainWindow(QtSingleApplication &app) : QMainWindow(NULL, MAINWINDOWFLAGS), isLoggingOn(false), isShuttingDown(false), showWelcomeScreen(false), isInviteCodeNeed(false), isMousePressed(false), showClipartWindow(false), widgetIndexBeforeWaiting(-1), contactList(NULL), drawingWindow(NULL), historyWindow(NULL), trayIcon(0), trayMenu(NULL), trayClickTimer(-1), trayConnectingTimer(-1), autoUpdater(this), http(NULL), reply(NULL) { // AEInstallEventHandler( setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint); TimeMeasure t("MainWindow"); progressDialog = NULL; setupUi(this); t.showTimePassedAfterSetupUi(); // connect signals from second copy of the application connect(&app, SIGNAL(messageReceived(const QString & )), this, SLOT(showWindow())); isPlaySounds = ProgramSettings::getPlaySouns(); // Connect infomanager & server connect(INFOMANAGER, SIGNAL(userAccountUpdated()), this, SLOT(onUserAccountUpdated())); connect(INFOMANAGER, SIGNAL(userStatusChanged(UserStatus::UserStatusEnum)), this, SLOT(onUserStatusChanged(UserStatus::UserStatusEnum))); connect(SERVER, SIGNAL(serverError(ServerResponseHandler::ServerError)), this, SLOT(onServerError(ServerResponseHandler::ServerError))); connect(SERVER, SIGNAL(logoutCompleted()), this, SLOT(onLogoutCompleted())); // Connect message manager connect(MESSAGEMANAGER, SIGNAL(privateMessageReceived(qint32, const MessageKey &)), this, SLOT(onPrivateMessageReceived(qint32, const MessageKey &))); connect(MESSAGEMANAGER, SIGNAL(friendsMessageReceived(const MessageKey &)), this, SLOT(onFriendsMessageReceived(const MessageKey &))); connect(MESSAGEMANAGER, SIGNAL(channelMessageReceived(qint32, const MessageKey &)), this, SLOT(onChannelMessageReceived(qint32, const MessageKey &))); connect(MESSAGEMANAGER, SIGNAL(showExceptionDialogSendingMessage(ContactResultCode::ContactResultCodeEnum, qint32)), this, SLOT(onShowExceptionDialogSendingMessage(ContactResultCode::ContactResultCodeEnum, qint32))); // Connect logon connect(logonWidget, SIGNAL(registerNewUser()), this, SLOT(showRegistrationWidget())); connect(logonWidget, SIGNAL(inviteCodeNeeded()), this, SLOT(onInviteCodeNeeded())); connect(logonWidget, SIGNAL(forgotPassword()), this, SLOT(showForgotPasswordWidget())); connect(logonWidget, SIGNAL(logonStarted()), this, SLOT(onLogonStarted())); connect(logonWidget, SIGNAL(logonStopped()), this, SLOT(onLogonStopped())); connect(logonWidget, SIGNAL(successLogon()), this, SLOT(onLogonSuccess())); connect(logonWidget, SIGNAL(showSettings()), this, SLOT(showSettings())); // connect widgets with waiting widget connect(waitingWidget, SIGNAL(cancel()), this, SLOT(cancelWaitingWidget())); connect(logonWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget())); connect(logonWidget, SIGNAL(waitingStop()), this, SLOT(stopWaitingWidget())); connect(registrationWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget())); connect(registrationWidget, SIGNAL(waitingHide()), this, SLOT(cancelWaitingWidget())); connect(forgotPasswordWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget())); connect(forgotPasswordWidget, SIGNAL(waitingStop()), this, SLOT(cancelWaitingWidget())); connect(inviteCodeWidget, SIGNAL(waitingStart()), this, SLOT(showWaitingWidget())); connect(inviteCodeWidget, SIGNAL(waitingStop()), this, SLOT(cancelWaitingWidget())); // Connect invite connect(inviteCodeWidget, SIGNAL(next()), this, SLOT(onInviteCodeAccepted())); connect(inviteCodeWidget, SIGNAL(back()), this, SLOT(showLogonWidget())); // Connect registration connect(registrationWidget, SIGNAL(back()), this, SLOT(onRegistrationBack())); connect(registrationWidget, SIGNAL(registrationSuccess()), this, SLOT(onRegistrationSuccess())); // Connect info connect(infoWidget, SIGNAL(finished()), this, SLOT(showLogonWidget())); // Connect forgot password connect(forgotPasswordWidget, SIGNAL(finished()), this, SLOT(onResetPassword())); connect(forgotPasswordWidget, SIGNAL(back()), this, SLOT(showLogonWidget())); // Connect welcome connect(welcomeWidget, SIGNAL(finished()), this, SLOT(showTvWidget())); // Connect buttons connect(tvCloseButton, SIGNAL(clicked()), this, SLOT(close())); // Connect TVWidget connect(previousButton, SIGNAL(clicked()), tvWidget, SLOT(previousMessage())); connect(tvWidget, SIGNAL(previousMessageAvailable(bool)), previousButton, SLOT(setEnabled(bool))); connect(tvWidget, SIGNAL(previousMessageAvailable(bool)), this, SLOT(showTvWidget())); connect(nextButton, SIGNAL(clicked()), tvWidget, SLOT(nextMessage())); connect(tvWidget, SIGNAL(nextMessageAvailable(bool)), nextButton, SLOT(setEnabled(bool))); connect(tvWidget, SIGNAL(nextMessageAvailable(bool)), this, SLOT(showTvWidget())); connect(tvWidget, SIGNAL(replyRequest(const QImage &)), this, SLOT(onReply(const QImage &))); tvWidget->setChatLabel(tr(ALL_FRIENDS_CHAT_LABEL)); // Init variables & windows autoUpdater.startCheckingPaused(); connect(&autoUpdater, SIGNAL(downloadNewVersion()), this, SLOT(onDownloadNewVersion())); clipartWindow = new ClipartWindow(this); createChildWindows(); loadSettings(); // start logon showLogonWidget(true); logonWidget->start(true); buttonsFrame->hide(); setupTray(); updateWindowTitle(); // show help by pressing F1 QShortcut * showHelpShortCut = new QShortcut(this); showHelpShortCut->setKey(Qt::Key_F1); connect(showHelpShortCut, SIGNAL(activated()), this, SLOT(showHelp())); #ifdef Q_WS_MAC macInit(); #endif }
void Share::slotOcsError(int statusCode, const QString &message) { emit serverError(statusCode, message); }
void QWSServerSocket::init(const QString &file) { #ifndef QT_NO_SXE QByteArray fn = file.toLocal8Bit(); bool result = QUnixSocketServer::listen( fn ); if ( !result ) { QUnixSocketServer::ServerError err = serverError(); switch ( err ) { case InvalidPath: qWarning("QWSServerSocket:: invalid path %s", qPrintable(file)); break; case ResourceError: case BindError: case ListenError: qWarning("QWSServerSocket:: could not listen on path %s", qPrintable(file)); break; default: break; } } #else int backlog = 16; //##### // create socket int s = ::socket(PF_LOCAL, SOCK_STREAM, 0); if (s == -1) { perror("QWSServerSocket::init"); qWarning("QWSServerSocket: unable to create socket."); return; } QByteArray fn = file.toLocal8Bit(); unlink(fn.constData()); // doesn't have to succeed // bind socket struct sockaddr_un a; memset(&a, 0, sizeof(a)); a.sun_family = PF_LOCAL; strncpy(a.sun_path, fn.constData(), sizeof(a.sun_path) - 1); int r = ::bind(s, (struct sockaddr*)&a, SUN_LEN(&a)); if (r < 0) { perror("QWSServerSocket::init"); qWarning("QWSServerSocket: could not bind to file %s", fn.constData()); ::close(s); return; } if (chmod(fn.constData(), 0600) < 0) { perror("QWSServerSocket::init"); qWarning("Could not set permissions of %s", fn.constData()); ::close(s); return; } // listen if (::listen(s, backlog) == 0) { if (!setSocketDescriptor(s)) qWarning( "QWSServerSocket could not set descriptor %d : %s", s, errorString().toLatin1().constData()); } else { perror("QWSServerSocket::init"); qWarning("QWSServerSocket: could not listen to file %s", fn.constData()); ::close(s); } #endif }