Compatible with older versions of gcc

This commit is contained in:
an-tao 2019-01-29 22:23:54 +08:00
parent 0124a18dbd
commit cbbee440ea
7 changed files with 15 additions and 14 deletions

View File

@ -592,7 +592,7 @@ void doTest(const HttpClientPtr &client, std::promise<int> &pro)
if (result == ReqResult::Ok)
{
auto json = resp->getJsonObject();
if (json && (*json)["result"].asString() == "ok" && (*json)["P1"] == "upload" & (*json)["P2"] == "test")
if (json && (*json)["result"].asString() == "ok" && (*json)["P1"] == "upload" && (*json)["P2"] == "test")
{
outputGood(req);
//std::cout << (*json) << std::endl;
@ -641,4 +641,4 @@ int main(int argc, char *argv[])
//getchar();
loop[0].getLoop()->quit();
loop[1].getLoop()->quit();
}
}

View File

@ -88,7 +88,8 @@ void HttpServer::onConnection(const TcpConnectionPtr &conn)
{
_disconnectWebsocketCallback(requestParser->webSocketConn());
}
conn->getMutableContext()->reset();
//conn->getMutableContext()->reset(); reset() is in c++17
conn->setContext(0);
}
}
_connectionCallback(conn);

View File

@ -307,7 +307,7 @@ int main()
std::string out;
out.resize(inStr.length());
size_t len = out.length();
auto ret=gzipCompress(inStr.c_str(), inStr.length(), out.data(), &len);
auto ret=gzipCompress(inStr.c_str(), inStr.length(), (char *)(out.data()), &len);
if(ret==0)
{
out.resize(len);
@ -322,4 +322,4 @@ int main()
}
return 0;
}
}

View File

@ -81,7 +81,7 @@ DbClientImpl::DbClientImpl(const std::string &connInfo, const size_t connNum, Cl
}
else if (type == ClientType::Sqlite3)
{
_sharedMutexPtr = std::make_shared<std::shared_mutex>();
_sharedMutexPtr = std::make_shared<std::shared_timed_mutex>();
assert(_sharedMutexPtr);
auto loop = _loops.getNextLoop();
loop->runInLoop([this]() {

View File

@ -48,7 +48,7 @@ class DbClientImpl : public DbClient, public std::enable_shared_from_this<DbClie
std::string _connInfo;
size_t _connectNum;
trantor::EventLoopThreadPool _loops;
std::shared_ptr<std::shared_mutex> _sharedMutexPtr;
std::shared_ptr<std::shared_timed_mutex> _sharedMutexPtr;
void execSql(const DbConnectionPtr &conn,
std::string &&sql,

View File

@ -34,7 +34,7 @@ void Sqlite3Connection::onError(const std::string &sql, const std::function<void
}
}
Sqlite3Connection::Sqlite3Connection(trantor::EventLoop *loop, const std::string &connInfo, const std::shared_ptr<std::shared_mutex> &sharedMutex)
Sqlite3Connection::Sqlite3Connection(trantor::EventLoop *loop, const std::string &connInfo, const std::shared_ptr<std::shared_timed_mutex> &sharedMutex)
: DbConnection(loop),
_sharedMutexPtr(sharedMutex)
{
@ -190,14 +190,14 @@ void Sqlite3Connection::execSqlInQueue(const std::string &sql,
if (sqlite3_stmt_readonly(stmt))
{
//Readonly, hold read lock;
std::shared_lock<std::shared_mutex> lock(*_sharedMutexPtr);
std::shared_lock<std::shared_timed_mutex> lock(*_sharedMutexPtr);
r = stmtStep(stmt, resultPtr, columnNum);
stmtPtr.reset();
}
else
{
//Hold write lock
std::unique_lock<std::shared_mutex> lock(*_sharedMutexPtr);
std::unique_lock<std::shared_timed_mutex> lock(*_sharedMutexPtr);
r = stmtStep(stmt, resultPtr, columnNum);
if (r == SQLITE_DONE)
{
@ -263,4 +263,4 @@ void Sqlite3Connection::disconnect()
pro.set_value(1);
});
f.get();
}
}

View File

@ -38,7 +38,7 @@ typedef std::shared_ptr<Sqlite3Connection> Sqlite3ConnectionPtr;
class Sqlite3Connection : public DbConnection, public std::enable_shared_from_this<Sqlite3Connection>
{
public:
Sqlite3Connection(trantor::EventLoop *loop, const std::string &connInfo, const std::shared_ptr<std::shared_mutex> &sharedMutex);
Sqlite3Connection(trantor::EventLoop *loop, const std::string &connInfo, const std::shared_ptr<std::shared_timed_mutex> &sharedMutex);
virtual void execSql(std::string &&sql,
size_t paraNum,
@ -64,8 +64,8 @@ class Sqlite3Connection : public DbConnection, public std::enable_shared_from_th
int stmtStep(sqlite3_stmt *stmt, const std::shared_ptr<Sqlite3ResultImpl> &resultPtr, int columnNum);
trantor::EventLoopThread _loopThread;
std::shared_ptr<sqlite3> _conn;
std::shared_ptr<std::shared_mutex> _sharedMutexPtr;
std::shared_ptr<std::shared_timed_mutex> _sharedMutexPtr;
};
} // namespace orm
} // namespace drogon
} // namespace drogon