简体   繁体   English

libuv:uv_tcp_connect返回的int是什么?

[英]libuv: what's the int returned by uv_tcp_connect?

Consider the documentation of uv_tcp_connect . 考虑uv_tcp_connect文档
Here is the declaration of the function: 这是函数的声明:

int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, const struct sockaddr* addr, uv_connect_cb cb);

It accepts a callback and returns an integer. 它接受一个回调并返回一个整数。
Usually, the other functions in libuv returns an error code (0 in case of no errors). 通常, libuv中的其他函数返回错误代码(如果没有错误, 返回0)。
I guess also this one works the same way. 我猜这也是一样的。

What is unclear to me (and undocumented as well) is: in case of a return value not equal to 0, will the callback be invoked anyway? 我不清楚(也没有记录)的是:如果返回值不等于0,则无论如何都会调用回调函数?
In other terms, does a return value different from 0 mean that the operation won't be performed at all or it is guaranteed that the callback is invoked? 换句话说,返回值是否不同于0是否意味着将根本不执行该操作,或者是否保证调用了回调?

Unfortunately, it seems that it is not documented what the return value actually is. 不幸的是,似乎没有记录实际的返回值。

In case it returns non-zero result it will not call a callback. 如果返回非零结果,则不会调用回调。

You can check this thread for more details: 您可以检查此线程以获取更多详细信息:

https://github.com/libuv/libuv/issues/391 https://github.com/libuv/libuv/issues/391

See the error handling section in the documentation. 请参阅文档中的错误处理部分 An error (return < 0) means no operation will be performed and no callback will be called. 错误(返回<0)表示将不执行任何操作,也不会调用回调。

From reading the source : 从阅读源

  • The return value is a (negative) error code, 0 means all went fine. 返回值是一个(负)错误代码,0表示一切正常。
  • The code with non-zero return paths don't reference the callback, so I don't think it will be invoked on error. 返回路径非零的代码不会引用回调,因此我认为不会在错误时调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM