您现在的位置: 爱51代码网 >> 范文 >> 文章正文
setsockopt failed: EBADF (Bad file number)

 finally {
                Log.i("bai", " finally socket finally  isConnected : "+ socket.isConnected());
                Log.i("bai", "socket info : "+ socket.toString() );
                Log.i("bai", "socket isConnected : "+ socket.isConnected());
                  if (null != socket) {
                      try {
//                          if(dis != null) {
//                              dis.close();
//                          }
                          Log.i("bai", "socket isConnected null != socket: "+ socket.isConnected());
                          Log.i("bai", "socket.isClosed(): "+ socket.isClosed());
                          socket.setSoTimeout(0);
                      } catch(SocketException se) {
                          Log.i("bai",se.getMessage());
                          throw new PushException(se, ErrorType.Err_Read);
                      } catch(IOException ie) {
                          throw new PushException(ie, ErrorType.Err_Read);
                      }
                   }
            }

这个finally是在read socket结束时执行,不过让人奇怪的是在socket不为空,还连接着的情况下,我设置socket永不超时就发现了setsockopt failed: EBADF (Bad file number)问题,导致socket异常关闭。网上也没找到详细资料,请各位道友帮忙看下,very thank you!!!
08-22 08:34:11.452: I/bai(6466): [SocketRead_08:29:07-227] finally socket finally  isConnected : true(pushagent/SSLPushChannel.java:344)
08-22 08:34:11.452: I/bai(6466): [SocketRead_08:29:07-227]socket info : Socket[address=/122.11.38.26,port=5223,localPort=60280](pushagent/SSLPushChannel.java:345)
08-22 08:34:11.452: I/bai(6466): [SocketRead_08:29:07-227]socket isConnected : true(pushagent/SSLPushChannel.java:346)
08-22 08:34:11.452: I/bai(6466): [SocketRead_08:29:07-227]socket isConnected null != socket: true(pushagent/SSLPushChannel.java:352)
08-22 08:34:11.452: I/bai(6466): [SocketRead_08:29:07-227]socket.isClosed(): false(pushagent/SSLPushChannel.java:353)
08-22 08:34:11.462: I/bai(6466): [SocketRead_08:29:07-227]setsockopt failed: EBADF (Bad file number)(pushagent/SSLPushChannel.java:356)
08-22 08:34:11.462: I/bai(6466): [ 08-22 08:34:11.471  6466:0x19ad
直接socket.close不行吗?为何还要加socket.setSoTimeout(0);呢?

如果要终止socket输入或者输出,可以加上:
 
if(null != socket && socket.isConnected)
{
socket.shutdownInput();
socket.shutdownOutput();
}
原因是由于java 每次GC时,垃圾回收器会将session重用中的ParcelFileDescriptor 参数被回收,导致push连接的SSLsocket成为假连接,此时socket.isConnected()=true。但是实际上socket连接已经成为不可用的或者说是坏掉的,合理保存下次参数再在下次使用就可以了。

  • 上一篇文章:

  • 下一篇文章: 没有了
  • 最新文章 热点文章 相关文章
    redhat 2.6 (santigo 5.6) vsftp
    shell如何实现自动填写操作执行下
    linux shell 文件配置sh:color:
    shell script语法一定要加path吗
    SecureCRT如何访问虚拟机vmWare中
    C#如何读取WINDOWS的放大系数
    cximge的图如何存入数据库并提取
    DBGRID控件显示查询结果文本类型
    TChart控件如何把表中右边的系列
    fastreport提示没有找到fr_class
    C#如何读取WINDOWS的放大系数
    cximge的图如何存入数据库并提取
    linux下编译faac及faad2提示 rec
    accept无法获取客户端ip
    TClientDataSet如何避免多人更新
    如何用delphi代码修改XML节点
    vc++ pvoid *用delphi怎么表达
    GIS用百度行政区域的经纬度直接画
    不小心卸载了.net 4 extend,vs2
    C#byte【】里的数转换成string时
    QString has no member name
    QT方向键实现QComBox控件下拉
    qt布局管理器的嵌套和大小调
    qt窗口因为子线程wait()而sh
    Qt unicode转换db2312后显示
    Qt线程里面如何给一个结构体
     



    设为首页 | 加入收藏 | 网站地图 | 友情链接 |