问题标签 [libuv]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
731 浏览

c - Variable declarations, using libuv

I am trying to learn how to use libuv. I am on a mac OS X and have the library downloaded and installed. I can compile and run small test programs one only starts a callback loop and then exits since there are no watchers, the other creates an idle watcher and exits when the time runs out.

I have been trying to go through the samples for the file io and have been running into problems. The function prototype for the function to obtain a file descriptor is:

I have cut the sample code down to the min that will still have the error.

My declaration of open_req is exactly like the declaration of close_req which appears in the complete code sample and doesn't produce and error. I added the declaration for open_req because the compiler was giving me a "‘open_req’ was not declared in this scope" error. When I added the declaration it changed the error to "invalid conversion from ‘void (*)(uv_fs_t)’ to ‘void (*)(uv_fs_t*)’". I get the same error rather the declaration is inside main or not. If I change the declaration to a pointer declaration

then I get the error:

I am trying to go through the actual libuv code to see if I can figure it out but the code is huge, I am using the "An Introduction to libuv" found here: http://nikhilm.github.com/uvbook/ and that is where the sample code came from.

Is there any other source of sample code that I can use to try and figure out this library? Is there anything obvious that I am doing wrong in my declaration? I am not sure where to look for clarification or examples on how to use libuv.

Edit update In the libuv code, in the uv.h file. I find

one of the things I have been looking for in the code is where this struct is actually defined. I have searched using google for typedef and learned a bit about how typedef is used to make the name so that you don't have to type struct every time that you want to declare an instance of the struct. Though some people seem to think it is a terrible practice and others think it is great. Part of what I removed to get a minimum sample as another declaration of a type us_fs_t called close_req. I copied the format for my declaration directly from that one.

I will see what I can find about pointers to functions, I am only vaguely familiar with them and it at least gives me somewhere to start looking.

I have found the function definition for uv_fs_open.

0 投票
3 回答
150 浏览

c - 指针参数之前的结构类型有什么作用?

我想知道以下语法的作用:

这是一个简单的类型检查还是做更多的事情?为什么类型周围需要括号?

来自http://nikhilm.github.com/uvbook/networking.html#tcp的整个示例:

问候, 博多

更新:

这能行吗?

0 投票
3 回答
322 浏览

c - 不熟悉的 C 语法?

我正在尝试理解其他人编写的 C 代码,并且遇到了一段我不理解所有语法和我不理解的部分的代码,我不知道如何搜索。我将不胜感激有关如何搜索此内容和我可能遇到的其他类似事物的解释或信息,或两者兼而有之。有问题的代码是以下行:

我知道 r 是一个变量,它被声明并初始化为函数“uv_listen()”返回的值,128 是一个文字 int 参数,on_new_connection 必须是一个函数指针,因为这是回调函数的名称被称为。server 是一个自定义类型(uv_tcp_t)的变量,带有 & 是指服务器的地址。我不明白的是“(uv_stream_t *)&server”。看起来这是函数的参数之一。我可以理解返回值作为参数的函数调用,但这看起来不像函数调用。“uv_stream_t”是在他们的代码中定义的另一种自定义类型。

我不知道它是否有助于理解它的含义,但代码行来自编写的示例代码,以帮助理解如何使用 libuv。

0 投票
2 回答
613 浏览

c - 令人费解的行为,malloc 和 free(),与 libuv

使用示例代码了解 libuv 我遇到了一个我不确定的副作用。该代码使用 malloc() 获取内存以存储来自网络上的客户端的数据,然后将相同的数据发送回,只是回显。然后它使用 free 释放内存。这通过回调循环一遍又一遍地重复。获取内存的代码行是:

释放内存的行是:

但是,如果您输入一个长字符串,例如“街上的单词是什么?” 要回显,然后放入较短的字符串,例如旧字符串的“Hi”片段,在较短的字符串回显后将重新出现。例如输出可以是这样的:

街上说什么?嗨嗨你好,他在街上说的话?

由于内存正在被释放,我不确定为什么旧片段会重新出现。我对这个主题的想法是,要么我对 malloc 和 free() 有一些我不了解的地方,要么在库中存在一个错误,它决定了传入数据所需的大小以及在使用更长的字符串后我得到了垃圾作为太大的内存块的一部分。如果是这样的话,那么它是我之前输入的一个片段的事实只是偶然的。这是可能的原因,还是我错过了什么?有没有其他信息。我应该包括澄清吗?

0 投票
1 回答
1907 浏览

node.js - 我可以用 libuv 做自定义事件吗?

我正在尝试使用 libuv,但我需要能够将事件从我的网络线程发送到我的主线程。我猜 libuv 会有自定义事件来处理这类事情,但我找不到它们。

有任何想法吗?谢谢!

0 投票
1 回答
1394 浏览

android - 有什么方法可以用android NDK编译libuv吗?

我们现在正在使用 c/c++ 为 android 客户端开发一些功能。

所以我们将使用 android NDK - r8 来编译我们的代码。

我们也在代码中使用 libuv。

不幸的是,android NDK 无法正确编译 libuv。无法识别以“pthread_”开头的所有术语。

有人有想法或提示吗?非常感谢。

0 投票
2 回答
1317 浏览

libuv - 我在哪里可以找到关于 uv_poll_init 的文档?

我正在查看https://github.com/benfleis/samples/blob/master/libuv/stdio/stdio_poll.c上的 libuv 示例并试图理解它。

我基本上理解它,但我在底部的 uv_poll_init 遇到了一些问题,我找不到任何文档。

有人可以指点我一些关于它的文件吗?

谢谢!

0 投票
1 回答
1295 浏览

c - libuv - 如何使用二进制协议

当通过简单的二进制协议进行通信时,我有客户端-服务器应用程序。当四个字节是数据长度 [datasize] 和 datasize 的数据块大小时,二进制协议有 12 个字节的头(见代码)。

数据流:


标题 | 数据 | 标题 | 数据 |


如何通过 libuv 从客户端接收二进制数据?你知道 libuv 处理二进制数据协议的例子吗?

0 投票
2 回答
2810 浏览

node.js - How do I spawn a child process as a different user on Windows?

Since libuv does not support child_process.spawn's uid option on Windows, how can you spawn a child process that runs as a different user?

0 投票
4 回答
4154 浏览

c - 在 os x 上编译 libuv 的库?

我正在尝试学习一些 libuv,似乎有一本很棒的书可以通过它。但是,这本书并没有解释如何实际编译它。我在从 github 中提取的代码上运行 make,并按照 github ( https://github.com/joyent/libuv ) 上的描述使用 GYP 进行编译。但是我不确定我需要包含什么样的库来编译代码。我试图编译这段代码:

libuv我使用文件夹中的以下命令对其进行了编译:

我得到了以下缺失的符号:

有人可以给我一个关于如何构建 libuv 的快速教程,或者我还需要什么吗?