[mew-dist 25560] Re: SMTP error handling

Kazu Yamamoto ( 山本和彦 ) kazu at example.com
2004年 10月 25日 (月) 15:28:07 JST


> で、変なのは、即座に connect 失敗することはなくなったんだけど、コネクショ
> ンになぜか時間がかかり、たぶん、alarm で設定した時間たってfailするとい
> うのが出ています。これは、ローカルな環境の問題(VMWare で NAT の裏)とか、
> NetBSDのせいとか、絡んでいるので、ちょっとまだ何とも言えない。

alarm() をセットして connect() するという現在のコードは、あまりにお粗末
なので、non-blocking conncet() を実装してみました。まだ、ハードコーディ
ングが多く、フィードバックできる形ではありませんが、このパッチを当てる
と幸せになるか教えて下さい。

--かず

Index: process.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/process.c,v
retrieving revision 1.442
diff -c -r1.442 process.c
*** process.c	29 Sep 2004 23:43:08 -0000	1.442
--- process.c	25 Oct 2004 06:22:23 -0000
***************
*** 2727,2732 ****
--- 2727,2735 ----
    int is_server = 0, backlog = 5;
    int socktype;
    int family = -1;
+   int flags, try;
+   fd_set rset, wset;
+   struct timeval timeout;
  
    if (nargs == 0)
      return Qnil;
***************
*** 3110,3155 ****
  
  	 This used to be conditioned by HAVE_GETADDRINFO.  Why?  */
  
!       turn_on_atimers (0);
! 
        ret = connect (s, lres->ai_addr, lres->ai_addrlen);
!       xerrno = errno;
! 
!       turn_on_atimers (1);
! 
!       if (ret == 0 || xerrno == EISCONN)
! 	{
! 	  /* The unwind-protect will be discarded afterwards.
! 	     Likewise for immediate_quit.  */
! 	  break;
! 	}
! 
! #ifdef NON_BLOCKING_CONNECT
! #ifdef EINPROGRESS
!       if (is_non_blocking_client && xerrno == EINPROGRESS)
! 	break;
! #else
! #ifdef EWOULDBLOCK
!       if (is_non_blocking_client && xerrno == EWOULDBLOCK)
! 	break;
! #endif
! #endif
! #endif
  
        immediate_quit = 0;
  
-       if (xerrno == EINTR)
- 	goto retry_connect;
-       if (xerrno == EADDRINUSE && retry < 20)
- 	{
- 	  /* A delay here is needed on some FreeBSD systems,
- 	     and it is harmless, since this retrying takes time anyway
- 	     and should be infrequent.  */
- 	  Fsleep_for (make_number (1), Qnil);
- 	  retry++;
- 	  goto retry_connect;
- 	}
- 
        /* Discard the unwind protect closing S.  */
        specpdl_ptr = specpdl + count1;
        emacs_close (s);
--- 3113,3141 ----
  
  	 This used to be conditioned by HAVE_GETADDRINFO.  Why?  */
  
!       flags = fcntl(s, F_GETFL, 0);
!       ret = fcntl(s, F_SETFL, flags | O_NONBLOCK);
!       if (ret < 0) {xerrno = errno; emacs_close (s); s = -1; continue;}
        ret = connect (s, lres->ai_addr, lres->ai_addrlen);
!       if ((ret < 0) && (errno != EINPROGRESS)) {xerrno = errno; emacs_close (s); s = -1; continue;}
!       FD_ZERO(&rset);
!       FD_SET(s,&rset);
!       wset = rset;
!       timeout.tv_sec=0;
!       timeout.tv_usec=100;
! #define TRY 20      
!       for (try = 0; try < TRY; try++) {
! 	      select(s+1, &rset, &wset, NULL, NULL);
! 	      if (FD_ISSET(s, &rset) || FD_ISSET(s, &wset)) break;
!       }
!       if (try == TRY) {xerrno = errno; emacs_close (s); s = -1; continue;}
!       if (fcntl(s, F_SETFL, flags) == -1)
! 	       {xerrno = errno; emacs_close (s); s = -1; continue;}
!       else
! 	      break;
  
        immediate_quit = 0;
  
        /* Discard the unwind protect closing S.  */
        specpdl_ptr = specpdl + count1;
        emacs_close (s);



Mew-dist メーリングリストの案内