我正在用C++编写一个多线程的websocket服务器.
当我尝试集成我的HTTP解析器时,MKFAHTTPRequest Request( std::string( Buffer ) );在执行期间完全跳过.
我已经清理了项目并添加了-Wall和-Werror(它应该告诉我这Request是一个未使用的变量,但它没有).
void operator()(){
while( true ){
if( m_Socket->is_open() ){
char Buffer[1024];
boost::system::error_code Error;
std::cout << "MKFAConnection::operator()() - Reading..." << std::endl;
m_Socket->read_some( boost::asio::buffer( Buffer, sizeof( Buffer ) ), Error );
if( !Error ){
// This line is getting skipped!?!?!?
MKFAHttpRequest Request( std::string( Buffer ) );
m_Socket->write_some( boost::asio::buffer( std::string( "Hello World" ) ) );
} else break;
} else break;
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的Ajax功能的一部分.由于某种原因,我无法弄清楚,我能够提醒() responseText但不能返回 responseText.有人可以帮忙吗?我需要在另一个函数中使用该值.
http.onreadystatechange = function(){
if( http.readyState == 4 && http.status == 200 ){
return http.responseText;
}
}
Run Code Online (Sandbox Code Playgroud) 我有两个表practice,并且facility具有通过链接表建立的一对多关系facility_practice。
我想要一个将关系的“许多”部分聚合到 json 数组中的结果。以下查询产生所需的结果:
询问
select
practice.id
, practice.name
, practice.code
, json_arrayagg(json_object(
"id", facility.id
, "name", facility.name
, "code", facility.code
)) as facility_json
from practice
left join facility_practice
on facility_practice.practice_id = practice.id
left join facility
on facility.id = facility_practice.facility_id
where practice.id = 1
group by practice.id;
Run Code Online (Sandbox Code Playgroud)
结果
+----+------+-------+---------------------------------------------------------------------------------------------+
| id | name | code | facility_json |
+----+------+-------+---------------------------------------------------------------------------------------------+
| 1 | Test | NA | [{"id": 1, "code": "NA", "name": "Test"}, {"id": 15, …Run Code Online (Sandbox Code Playgroud) 我试图用C++连接到MongoDB.以下代码实际上编译.但是,当我尝试运行程序时,我遇到了分段错误.
这是我在gdb中运行它后得到的结果(源代码或makefile没有变化):
Starting program: /home/nathanw/devel/Linux/mkfarina-cpp/mkfarina
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff69ae700 (LWP 13314)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff69ae700 (LWP 13314)]
0x00007ffff6d79034 in pthread_mutex_unlock () from /lib/x86_64-linux-gnu/libpthread.so.0
Run Code Online (Sandbox Code Playgroud)
#0 0x00007ffff6d79034 in pthread_mutex_unlock () from /lib/x86_64-linux-gnu/libpthread.so.0
#1 0x00007ffff7bca948 in boost::detail::thread_data_base::~thread_data_base() () from /usr/local/lib/libboost_thread.so.1.52.0
#2 0x000000000046c74b in boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf1<void, mongo::BackgroundJob, boost::shared_ptr<mongo::BackgroundJob::JobStatus> >, boost::_bi::list2<boost::_bi::value<mongo::BackgroundJob*>, boost::_bi::value<boost::shared_ptr<mongo::BackgroundJob::JobStatus> > > > >::~thread_data() ()
#3 0x00007ffff7bc7d39 in thread_proxy () from /usr/local/lib/libboost_thread.so.1.52.0 …Run Code Online (Sandbox Code Playgroud) 我对C++语言有些新意.我正在编写一个用于记录到文件的实用程序类.它工作得很漂亮,但现在我想通过使它更方便使用来增强它(例如将字符串流传递给日志功能).
这是我一直在尝试的,但它没有奏效.
定义:
void LogStream( std::stringstream i_Log ){
m_FileHandle << i_Log << std::endl;
}
呼叫:
m_LogObject->LogStream( "MKLBSearchEngine::Search( " << x << ", " << i_Filter << " ) - No Results Found" );
我有一堆对象需要将它们的状态以 json 表示形式发送到服务器。目前它的工作原理如下:
MyClass.prototype.GetJSON(){
return '{"title":"' + m_Title + '","description":"' + m_Desc + '"}';
};
Run Code Online (Sandbox Code Playgroud)
和我一起工作的人建议我做这样的事情:
MyClass.prototype.GetJSON(){
return JSON.stringify( {title:m_Title, description:m_Desc} );
};
Run Code Online (Sandbox Code Playgroud)
这样做有什么优点/缺点?它比我已经在做的事情效率更高/更低吗?
c++ ×3
javascript ×2
ajax ×1
alert ×1
g++ ×1
gcc ×1
group-by ×1
json ×1
logging ×1
mongodb ×1
mysql ×1
parameters ×1
responsetext ×1
return ×1
skip ×1
stringify ×1
stringstream ×1
view ×1