4 Star 3 Fork 4

Gitee 极速下载/Tiny-httpd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/Huangtuzhi/Tinyhttpd
克隆/下载
starter.cpp 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
Huangtuzhi 提交于 10年前 . a
#include "starter.h"
#include <vector>
#include <iostream>
#include <QNetworkInterface>
#include <QStringList>
#include <QHostAddress>
Starter* Starter::m_instance = NULL;
Starter& Starter::instance()
{
if (m_instance == NULL)
m_instance = new Starter();
return *m_instance;
}
void Starter::startInstance(int port)
{
ServerThread* server_thread = new ServerThread();
threads.push_back(server_thread);
server_thread->setAddress(QHostAddress::Any);
server_thread->setPort(port);
server_thread->start();
}
bool Starter::start()
{
//监听多端口,每个端口都启动服务器进程
bool ok;
QString t_port = Settings::instance().value("httpd/port").toString();
QStringList port_list = t_port.split("|");
//多线程监听
for(int i = 0; i < port_list.size(); i++)
{
int port = port_list[i].toInt(&ok,10);
startInstance(port);
}
return true;
}
bool Starter::stop()
{
for(auto t:threads)
{
t->exit();
t->wait();
}
return true;
}
QString Starter::getIPAddress()
{
QString ipAddress;
QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
for (int i = 0; i < ipAddressesList.size(); ++i) {
if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
ipAddressesList.at(i).toIPv4Address()) {
ipAddress = ipAddressesList.at(i).toString();
break;
}
}
if (ipAddress.isEmpty())
ipAddress = QHostAddress(QHostAddress::LocalHost).toString();
return ipAddress;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C/C++
1
https://gitee.com/mirrors/Tiny-httpd.git
git@gitee.com:mirrors/Tiny-httpd.git
mirrors
Tiny-httpd
Tiny-httpd
master

搜索帮助