gpt4 book ai didi

sockets - Solaris 11 上的 JNI/C 套接字连接错误

转载 作者:行者123 更新时间:2023-12-03 12:03:30 24 4
gpt4 key购买 nike

我们的应用程序使用了几个用 c 实现的套接字连接(到 localhost),其中一个连接使用 jni/c 套接字连接。它们都调用相同的 include 来打开套接字,当我们在 Solaris 10 上运行应用程序时,它们都成功了。
迁移到 Solaris 11,我们发现只有 c 中内置的套接字连接有效,一个 jni/c 连接不起作用。我添加了输出以查看发送到 connect 调用的确切内容,看起来该调用正在获取所需的一切:

"sock_connect: socket status: 0, sock_d: 27, serv_addr: ***.***.***.***, sizeof: 16"

So for the call below, sock_d = 27
serv_addr = (it returns a good IP, but my PM said he'd kill me if I put the actual IP)
sizeof(serv_addr) = 16
which should be all the parameters connect() needs in the code snippet below.

.
.
.
.
status = connect(sock_d, (struct sockaddr *)&serv_addr, sizeof(serv_addr));

if (status < 0){
fprintf(stderr, "sock_connect 4: after connect errno: %i, error %sn", errno, strerror(errno));
if (errno == EINPROGRESS){
fprintf(stderr, "sock_connect, errno == EINPROGRESS\n");
.
.
.

失败连接的桁架输出似乎表明 EINPROGRESS错误。我们的代码应该验证这种可能性,但它不会触发 if 语句来检查 error == EINPROGRESS 是否存在。 .它永远不会达到第二个 fprintf陈述。我们已经在服务器上禁用了 IPv6,因为我们认为 java 可能试图强制使用此协议(protocol),但这也没有什么不同。

完全相同的库和可执行文件将在两台服务器上运行,直到进行 jni 套接字调用。从那时起,Solaris 10 继续运行,但 Solaris 11 不会。

有没有人见过这个?请让我知道您还需要看什么,我会发布它。提前致谢!

最佳答案

此代码错误地假定 fprintf()永远不会修改errno :

if (status < 0){
fprintf(stderr, "sock_connect 4: after connect errno: %i, error %sn", errno, strerror(errno));
if (errno == EINPROGRESS){
fprintf(stderr, "sock_connect, errno == EINPROGRESS\n");

POSIX standard for errno 状态(强调我的):

The value of errno shall be defined only after a call to a function for which it is explicitly stated to be set and until it is changed by the next function call or if the application assigns it a value.



根据 Solaris 11.3 fprintf() man page , fprintf()可以设置 errno :

错误

For the conditions under which printf(), fprintf(), and dprintf() will fail and may fail, refer to fputc(3C) or fputwc(3C).

The snprintf() function will fail if:

EOVERFLOW

The value of n is greater than INT_MAX or the number of bytes needed to hold the output excluding the terminating null is greater than INT_MAX.

All forms of printf() will fail if:

EILSEQ

A wide-character code that does not correspond to a valid character has been detected.

EINVAL

There are insufficient arguments.

The dprintf() function will fail if:

EBADF

The fildes argument is not a valid file descriptor.

The printf(), fprintf(), dprintf(), and asprintf() functions may fail due to an underlying malloc(3C) failure if:

EAGAIN

Storage space is temporarily unavailable.

ENOMEM

Insufficient storage space is available.

关于sockets - Solaris 11 上的 JNI/C 套接字连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49701612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com