EINTR error

EINTR error

总结:本问介绍了EINTR错误产生的原因,以及如何解决,并在最后给出一个实例,通过该实例可以解决调用ioctl产生的EINTR错误。

一. EINTR

1.EINTR错误产生的原因;

当阻塞于某个慢系统调用的一个进程捕获某个信号且相应信号处理函数返回时,该系统调用可能会返回一个EINTR错误。例如:在socket服务器端,设置了信号捕获机制,有子进程当在父进程阻塞于慢系统调用时由父进程捕获到了一个有效信号时,内核会致使accept返回一个EINTR错误(被中断的系统调用)。

2.如何解决:

当碰到EINTR错误的时候,可以采取有一些可以重启的系统调用进行重启,而对于有一些系统调用是不能够重启的。例如:acceptreadwiret

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
分析一下下面这段代码while(1) { revents = 0; #ifndef DISABLE_LIBSSH if (session->ssh_chan != NULL) { /* we are getting data from libssh's channel */ status = ssh_channel_poll_timeout(session->ssh_chan, timeout, 0); if (status > 0) { revents = POLLIN; } } else #endif #ifdef ENABLE_TLS if (session->tls != NULL) { /* we are getting data from TLS session using OpenSSL */ fds.fd = SSL_get_fd(session->tls); fds.events = POLLIN; fds.revents = 0; status = poll(&fds, 1, timeout); revents = (unsigned long int) fds.revents; } else #endif if (session->fd_input != -1) { /* we are getting data from standard file descriptor */ fds.fd = session->fd_input; fds.events = POLLIN; fds.revents = 0; status = poll(&fds, 1, timeout); revents = (unsigned long int) fds.revents; } else { ERROR("Invalid session to receive data."); return (NC_MSG_UNKNOWN); } /* process the result */ if (status == 0) { /* timed out */ DBG_UNLOCK("mut_channel"); pthread_mutex_unlock(session->mut_channel); return (NC_MSG_WOULDBLOCK); } else if (((status == -1) && (errno == EINTR)) #ifndef DISABLE_LIBSSH || (status == SSH_AGAIN) #endif ) { /* poll was interrupted */ continue; } else if (status < 0) { /* poll failed - something wrong happend, close this socket and wait for another request */ DBG_UNLOCK("mut_channel"); pthread_mutex_unlock(session->mut_channel); #ifndef DISABLE_LIBSSH if (status == SSH_EOF) { emsg = "end of file"; } else if (!session->ssh_chan) { emsg = strerror(errno); } else if (session->ssh_sess) { emsg = ssh_get_error(session->ssh_sess); } else { emsg = "description not available"; } #else emsg = strerror(errno); #endif WARN("Input channel error (%s)", emsg); nc_session_close(session, NC_SESSION_TERM_DROPPED); if (nc_info) { pthread_rwlock_wrlock(&(nc_info->lock)); nc_info->stats.sessions_dropped++; pthread_rwlock_unlock(&(nc_info->lock)); } return (NC_MSG_UNKNOWN); } /* status > 0 */ /* check the status of the socket */ /* if nothing to read and POLLHUP (EOF) or POLLERR set */ if ((revents & POLLHUP) || (revents & POLLERR)) { /* close client's socket (it's probably already closed by client */ DBG_UNLOCK("mut_channel"); pthread_mutex_unlock(session->mut_channel); ERROR("Input channel closed"); nc_session_close(session, NC_SESSION_TERM_DROPPED); if (nc_info) { pthread_rwlock_wrlock(&(nc_info->lock)); nc_info->stats.sessions_dropped++; pthread_rwlock_unlock(&(nc_info->lock)); } return (NC_MSG_UNKNOWN); } /* we have something to read */ break; }
最新发布
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冀博

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值