libuv

How does the UV_RUN_NOWAIT mode work in libuv?

与世无争的帅哥 提交于 2019-12-04 20:42:29
问题 When running an event loop in libuv using the uv_run function, there's a "mode" parameter that is used with the following values: UV_RUN_DEFAULT UV_RUN_ONCE UV_RUN_NOWAIT The first two are obvious. UV_RUN_DEFAULT runs the event loop until there are no more events, and UV_RUN_ONCE processing a single event from the loop. However, UV_RUN_NOWAIT doesn't seem to be a separate mode, but rather a flag that can be ORed with one of the other two values. By default, this function blocks until events

libuv的典型应用——CTP的Node.js封装

梦想的初衷 提交于 2019-12-04 14:41:06
写过CTP的同学可能不多,这是一个期货接口。没听说过的也无妨。 C++多线程回调 CTP 提供了若干个父类供开发者继承,里面的回调都是通过覆盖父类的纯虚函数实现。 当SDK有事件发生的时候,就会调用这些定义的回调函数。 class CThostFtdcTraderSpi { public: virtual void OnFrontConnected(){}; virtual void OnFrontDisconnected(int nReason){}; 编写一个这样的程序是十分痛苦的,因为回调函数的执行是在某个工作线程中。所以很容易引起并发读写的问题。代码会变得十分复杂。 编写过Node.js的同学一定以及十分习惯Node的单线程模式,回调函数执行的时候虽然有点“不同步”,但好歹是在一个线程中,所以定义域里面的变量可以随便使用。用惯这种方便的编程方式的同学,如果去接触一下C++那种多线程回调,一定会抓狂的。 那么如何让CTP开发也能很舒服呢?或者干脆将CTP封装成Node的原生模块,然后在Node中调用,岂不妙哉。 这时候协调C++多线程和Nodejs单线程的关键角色就登场了,这就是libuv。 #include <uv.h> uv_async_t async_t; uv_async_init(uv_default_loop(),&async_t,NULL);

Relationship between event loop,libuv and v8 engine

谁说我不能喝 提交于 2019-12-04 10:53:02
问题 I am learning through the architecture of Node.js. I have following questions. Is event loop a part of libuv or v8? Is event queue a part of event loop? are event queue generated by libuv or v8 engine or event loop itself? What is the connection between libuv and v8 engine? If event loop is single threaded, does libuv come into picture to create multiple threads to handle File I/O? Does browsers have event loop mechanism or just Node.js does? 回答1: The event loop is, first and foremost, a high

libuv undefined reference to uv_loop_new

放肆的年华 提交于 2019-12-04 03:31:27
问题 After compiling, I am trying to run libuv sample program: #include <stdio.h> #include <uv.h> int main() { uv_loop_t *loop = uv_loop_new(); printf("Now quitting.\n"); uv_run(loop, UV_RUN_DEFAULT); return 0; } But, when try to run, I get the following error: **/tmp/ccHTpspB.o: In function `main': main.c:(.text+0x9): undefined reference to `uv_loop_new' main.c:(.text+0x28): undefined reference to `uv_run' collect2: error: ld returned 1 exit status** Where did I go wrong ? PS: It doesn't work

How to do async file io in qt?

◇◆丶佛笑我妖孽 提交于 2019-12-03 21:29:22
I was wondering how to achieve async file io in qt? Is this even achievable in vanilla qt or would someone need to use another library (libuv for example) to achieve something like this? I was looking at QDataStream but even though it is a "stream" it isn't non blocking. I guess one solution would be to make a custom QIODevice that uses libuv internally which can then be used with QDataStream but not sure where to start. Any ideas? Thanks for any help provided. I would implement a thread that will handle the I/O. You can connect the appropriate sig/slots to "invoke" the IO from your main

How does the UV_RUN_NOWAIT mode work in libuv?

白昼怎懂夜的黑 提交于 2019-12-03 13:11:08
When running an event loop in libuv using the uv_run function, there's a "mode" parameter that is used with the following values: UV_RUN_DEFAULT UV_RUN_ONCE UV_RUN_NOWAIT The first two are obvious. UV_RUN_DEFAULT runs the event loop until there are no more events, and UV_RUN_ONCE processing a single event from the loop. However, UV_RUN_NOWAIT doesn't seem to be a separate mode, but rather a flag that can be ORed with one of the other two values. By default, this function blocks until events are done processing, and UV_RUN_NOWAIT makes it nonblocking, but any documentation I can find on it ends

Does the .pipe() perform a memcpy in node.js?

笑着哭i 提交于 2019-12-03 12:52:08
This is a conceptual query regarding system level optimisation. My understanding by reading the NodeJS Documentation is that pipes are handy to perform flow control on streams. Background: I have microphone stream coming in and I wanted to avoid an extra copy operation to conserve overall system MIPS. I understand that for audio streams this is not a great deal of MIPS being spent even if there was a memcopy under the hood, but I also have an extension planned to stream in camera frames at 30fps and UHD resolution. Making multiple copies of UHD resolution pixel data at 30fps is super

How do I pump window messages in a nodejs addon?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 09:40:54
问题 In a Windows nodejs addon, I've created a window for the purpose of receiving messages. Handle<Value> MakeMessageWindow(const Arguments &args) { // exposed to JS ... CreateWindow(L"ClassName", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, 0); ... } I have a wndproc function. Local<Function> wndProc; LRESULT APIENTRY WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // pack up the arguments into Local<Value> argv wndProc->Call(Context::GetCurrent()->Global(), 3, argv); } Now I need to

Relationship between event loop,libuv and v8 engine

限于喜欢 提交于 2019-12-03 07:05:06
I am learning through the architecture of Node.js. I have following questions. Is event loop a part of libuv or v8? Is event queue a part of event loop? are event queue generated by libuv or v8 engine or event loop itself? What is the connection between libuv and v8 engine? If event loop is single threaded, does libuv come into picture to create multiple threads to handle File I/O? Does browsers have event loop mechanism or just Node.js does? The event loop is, first and foremost, a high-level concept that's a fundamental part of the JavaScript programming model. Practically, every V8 embedder

C optimization: conditional store to avoid dirtying a cache line

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 05:55:06
In the libuv source , I found this code: /* The if statement lets the compiler compile it to a conditional store. * Avoids dirtying a cache line. */ if (loop->stop_flag != 0) loop->stop_flag = 0; Can someone explain this a bit? What exactly is a cache line? Also, I guess a conditional store is some Assembler instruction which checks something and if succeeded, writes some value. Right? When does such construct makes sense? I guess not always, because otherwise the compiler would just always use the conditional store, right? A cache is organized in blocks of fast memory that, for historical