/[imapfilter]/imapfilter/socket.c
ViewVC logotype

Diff of /imapfilter/socket.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by lefcha, Thu Nov 8 17:52:06 2001 UTC revision 1.6 by lefcha, Fri Nov 9 10:14:21 2001 UTC
# Line 177  int close_connection(void) Line 177  int close_connection(void)
177   */   */
178  int socket_read(char *buf)  int socket_read(char *buf)
179  {  {
180      int flags, e;      int flags, r, s;
181      fd_set fds;      fd_set fds;
182      struct timeval tv;      struct timeval tv;
183    
184      memset(buf, 0, RESPONSE_BUF);      memset(buf, 0, RESPONSE_BUF);
185    
186      tv.tv_sec = 20;      tv.tv_sec = 30;
187      tv.tv_usec = 0;      tv.tv_usec = 0;
188    
189      flags = fcntl(sock, F_GETFL, 0);      flags = fcntl(sock, F_GETFL, 0);
# Line 192  int socket_read(char *buf) Line 192  int socket_read(char *buf)
192      FD_ZERO(&fds);      FD_ZERO(&fds);
193      FD_SET(sock, &fds);      FD_SET(sock, &fds);
194    
     if ((select(sock + 1, &fds, NULL, NULL, &tv) > 0)  
         && FD_ISSET(sock, &fds)) {  
   
195  #ifdef SSL_TLS  #ifdef SSL_TLS
196          if (ssl)      if (ssl) {
197              e = SSL_read(ssl, buf, RESPONSE_BUF - 1);          if (SSL_pending(ssl) || ((s = select(sock + 1, &fds, NULL, NULL, &tv)) > 0
198          else                                   && FD_ISSET(sock, &fds)))
199                r = SSL_read(ssl, buf, RESPONSE_BUF - 1);
200        } else
201  #endif  #endif
202              e = read(sock, buf, RESPONSE_BUF - 1);          if ((s = select(sock + 1, &fds, NULL, NULL, &tv)) > 0
203                && FD_ISSET(sock, &fds))
204            r = read(sock, buf, RESPONSE_BUF - 1);
205    
206        fcntl(sock, F_SETFL, flags);
207    
208          fcntl(sock, F_SETFL, flags);      if (s <= 0)
209            fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n",
210                  strerror(errno));
211    
212  #ifdef SSL_TLS  #ifdef SSL_TLS
213          if (ssl) {      if (ssl) {
214              if (e <= 0)          if (r <= 0)
                 fatal(ERROR_NETWORK, "imapfilter: reading data; %s",  
                       ERR_error_string(e, NULL));  
         } else  
 #endif  
         if (e == -1)  
215              fatal(ERROR_NETWORK, "imapfilter: reading data; %s",              fatal(ERROR_NETWORK, "imapfilter: reading data; %s",
216                    strerror(errno));                    ERR_error_string(r, NULL));
217        } else
218          return 0;  #endif
219      }      if (r == -1)
220      fcntl(sock, F_SETFL, flags);          fatal(ERROR_NETWORK, "imapfilter: reading data; %s",
221                  strerror(errno));
     fatal(ERROR_NETWORK, "imapfilter: waiting input from socket; %s\n",  
           strerror(errno));  
222    
223      return ERROR_NETWORK;       /* NEVER REACHED. */      return 0;
224  }  }
225    
226    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26