Solaris 11上的JNI/C套接字连接错误 [英] JNI/C socket connection error on Solaris 11

查看:45
本文介绍了Solaris 11上的JNI/C套接字连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Our application uses several socket connections (to localhost) implemented in c, with one connection using a jni/c socket connection. All of them call the same include to open the socket, and all are successful when we run the application on Solaris 10. Migrating to Solaris 11, we are finding that only the socket connections built in c are working, the one jni/c connection will not. I've added output to see what exactly is being sent to the connect call and it looks like the call is getting everything it needs:

"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正在尝试强制使用该协议,但这也没有任何区别.

Truss output for the failed connection seems to indicate an EINPROGRESS error. Our code is supposed to validate for this possibility, but it does not trigger an if statement that checks to see if the error == EINPROGRESS. It never reaches the second fprintf statement. We have disabled IPv6 on the server, as we thought perhaps java was trying to force this protocol, but this didn't make a difference either.

完全相同的库和可执行文件将在两台服务器上工作,直到进行jni套接字调用为止.从那时起,Solaris 10继续运行,但Solaris 11却没有.

The exact same libraries and executables will work on both servers, right up until the jni socket call is made. From that point on Solaris 10 keeps going but Solaris 11 will not.

以前有人看过吗?请让我知道您还需要看什么,我将其发布.预先感谢!

Has anyone seen this before? Please let me know what else you need to see and I'll post it. Thanks in advance!

推荐答案

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

This code incorrectly assumes fprintf() will never modify 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");

用于errno 状态的POSIX标准(重点是):

The POSIX standard for errno states (emphasis mine):

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()页面fprintf()可以设置errno:

And per the Solaris 11.3 fprintf() man page, fprintf() can set errno:

错误

对于printf()fprintf()dprintf()将失败并且可能失败,请参考fputc(3C)或fputwc(3C).

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

如果出现以下情况,snprintf()函数将失败:

The snprintf() function will fail if:

ELOWFLOW

n的值大于INT_MAX或所需的字节数 保持输出(不包括终止null)大于 INT_MAX.

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.

在以下情况下,所有printf()形式都将失败:

All forms of printf() will fail if:

EILSEQ

与有效字符不对应的宽字符代码 已被检测到.

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

EINVAL

没有足够的论据.

如果出现以下情况,dprintf()函数将失败:

The dprintf() function will fail if:

EBADF

fildes参数不是有效的文件描述符.

The fildes argument is not a valid file descriptor.

printf()fprintf()dprintf()asprintf()功能 在以下情况下可能会由于潜在的malloc(3C)故障而失败:

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

EAGAIN

存储空间暂时不可用.

ENOMEM

可用的存储空间不足.

这篇关于Solaris 11上的JNI/C套接字连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆