libev

printf() without '\n' doesn't work in libev [duplicate]

北城余情 提交于 2019-12-29 10:07:38
问题 This question already has answers here : Why does printf not flush after the call unless a newline is in the format string? (10 answers) Closed 3 years ago . Post the code first: #define EV_STANDALONE 1 #include <stdio.h> #include "ev.c" ev_timer timeout_watcher; struct ev_loop* loop; static void timeout_cb (EV_P_ ev_timer *w, int revents) { // puts("timeout"); printf("timeout"); ev_timer_again(loop, w); } int main (void) { printf("hello, world."); loop = EV_DEFAULT; ev_timer_init (&timeout

Is Node.js production-ready on Windows? [closed]

半城伤御伤魂 提交于 2019-12-25 04:07:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . In the new 0.5.1 branch, there is an official Windows executable of Node.js. The Linux version of Node.js uses established libraries

Epoll: does it silently remove fds?

我与影子孤独终老i 提交于 2019-12-24 12:21:54
问题 I've been reading through libev's source code and stumbled upon this comment: a) epoll silently removes fds from the fd set. as nothing tells us that an fd has been removed otherwise, we have to continually "rearm" fds that we suspect might have changed (same problem with kqueue, but much less costly there). I've been doing some tests with epoll (directly using syscalls) on some modern linux kernel and I couldn't reproduce it. I didn't see any problem with "silently disappearing fds". Could

Is libuv just a wrapper on libev on POSIX systems?

梦想与她 提交于 2019-12-22 08:36:36
问题 I am really confused between libev and libuv. Is libuv just a wrapper on libev on POSIX systems? If not where does it differ? 回答1: No longer, since libuv-v0.9 Here is the libuv github issue which tracked the removal of libev from libuv. The reasons for removal are, to quote from the above linked issue: In case any project watchers are wondering, libev served us well but: It only supports level-triggered I/O. On Linux, we want to use edge-triggered mode - it cuts down the number of syscalls by

Is libuv just a wrapper on libev on POSIX systems?

佐手、 提交于 2019-12-22 08:36:04
问题 I am really confused between libev and libuv. Is libuv just a wrapper on libev on POSIX systems? If not where does it differ? 回答1: No longer, since libuv-v0.9 Here is the libuv github issue which tracked the removal of libev from libuv. The reasons for removal are, to quote from the above linked issue: In case any project watchers are wondering, libev served us well but: It only supports level-triggered I/O. On Linux, we want to use edge-triggered mode - it cuts down the number of syscalls by

Libev, How to pass arguments to relevant callbacks

倖福魔咒の 提交于 2019-12-21 06:50:19
问题 I'm trapped in a situation of argument passing in libev. Usually, libev receives packages in a function like *receive_callback* , that's OK, but in practice, we need to dispatch a relative *write_callback* to deal with specific jobs according to the received package. For example: S_RECV_MSG* pstRecvMsg = (S_RECV_MSG*) recv_buff; switch(pstRecvMsg->wMsgType) { case 1: ev_io_init(w, write_callback1, w->fd, EV_WRITE); break; case 2: ev_io_init(w, write_callback2, w->fd, EV_WRITE); break; case 3:

Why use do { } while (0) in macro definition? [duplicate]

假如想象 提交于 2019-12-20 09:02:54
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? I met code like below: #define ev_io_init(ev,cb,fd,events) \ do { \ ev_init ((ev), (cb)); \ ev_io_set ((ev),(fd),(events)); \ } while (0) I want to know why the author use do { } while (0) here. Is there any difference with this? #define ev_io_init(ev,cb,fd,events) { \ ev_init ((ev), (cb)); \ ev_io_set ((ev),(fd),(events)); \ }

Socket网络编程--Libev库学习(3)

僤鯓⒐⒋嵵緔 提交于 2019-12-19 09:00:33
  这一小节继续讲解各个观察器(Watcher).   上一小节已经讲解了ev_io(IO可读可写观察器),ev_stat(文件属性变化观察器),ev_signal(信号处理观察器),ev_timer(定时器),ev_periodic(周期任务处理),ev_child(子进程状态变化观察器)。这一小节准备讲ev_fork(创建的进程时的观察器),ev_async(异步调用观察器),ev_cleanup(event loop退出时触发事件),ev_prepare(每次event loop之前事件),ev_check(每次event loop之后事件),ev_idle(每次event loop空闲触发事件).   ev_async (ev_async当ev_async_send通过watcher调用时调用,触发EV_ASYNC) 1 #include <stdio.h> 2 #include <string.h> 3 #include <unistd.h> 4 #include <stdlib.h> 5 #include <ev.h> 6 7 ev_async async_watcher; 8 9 static void sigint_callback(struct ev_loop *loop,ev_signal * w,int revents) 10 { 11 if(revents

how to check if connection is established when use libev with non-block socket

三世轮回 提交于 2019-12-11 02:07:04
问题 I have some code use libev on how to deal with connection timeout as below (please refer to http://lists.schmorp.de/pipermail/libev/2011q2/001365.html): sd = create_socket() set_socket_nonblock(sd) connect("127.0.0.1", port) // connect to an invalid port ev_io_init(&w_io, connect_cb, sd, EV_WRITE) ev_io_start(...) ev_timer_init(&w_timer, timeout_cb, 5.0, 0) ev_timer_start(...) and in someplace perform ev_run. The connect_cb is called and in this callback function I checked the revents with EV

libev 笔记(一):“事件驱动模型” 的 理解

醉酒当歌 提交于 2019-12-10 22:52:35
libev 是 一种 “事件驱动”的编程框架,所谓“事件驱动”,简单地说就是就是 有什么动作(点按钮、中断),程序就执行什么操作(中断服务函数、回调函数),当然事件不仅限于用于的操作,只要是定义好的,各种突发、预设的各种将要发生的事情,都是事件。这里,我对CPU相对熟悉一些,可以把“事件驱动”理解为 自定义软件中断。这里我们举几个案例来分析: 案例1: 状态机FSM 状态机是一种常用的编程框架,本质上讲,状态机也是一种事件驱动,“状态”就相当于“事件”,不同状态执行不同的代码功能,这里的代码功能就相当于 事件对应的 驱动 功能。 案例2:硬件中断 硬件中断是 最典型的 事件驱动,只不过这里的中断是CPU厂家预设的,当发生某一硬件中断时,执行对应的 中断服务函数,这里的 “中断”就是 “事件”,而 中断服务函数 就是 驱动。 案例3:功能 回调函数 我们在使用 一些 SDK 的时候,很多的SDK 都会提供 接口 和回调函数,这种回调 函数 也是事件驱动模型,只不过这些 事件 是SDK 定义好的,回调函数 是允许用户 自定义的 事件驱动 函数。 libev 提供了基本的 IO 事件、定时器事件、信号事件,这三种事件用的比较多,这里的IO就是针对 文件描述符,在Linux下,一切设备都是 文件,所以 IO 事件可以针对 所有的外设备,比如网口、socket,串口,文件等。定时器