ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/s_bsd.c
(Generate patch)

Comparing ircd-hybrid/trunk/src/s_bsd.c (file contents):
Revision 2426 by michael, Tue Jul 30 17:20:47 2013 UTC vs.
Revision 2725 by michael, Sun Dec 29 13:01:00 2013 UTC

# Line 52 | Line 52 | static const char *comm_err_str[] = { "C
52    "Error during DNS lookup", "connect timeout", "Error during connect()",
53    "Comm Error" };
54  
55 struct Callback *setup_socket_cb = NULL;
56
55   static void comm_connect_callback(fde_t *, int);
56   static PF comm_connect_timeout;
57   static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *);
# Line 139 | Line 137 | report_error(int level, const char* text
137   *
138   * Set the socket non-blocking, and other wonderful bits.
139   */
140 < static void *
141 < setup_socket(va_list args)
140 > static void
141 > setup_socket(int fd)
142   {
145  int fd = va_arg(args, int);
143    int opt = 1;
144  
145    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
# Line 153 | Line 150 | setup_socket(va_list args)
150   #endif
151  
152    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
156
157  return NULL;
158 }
159
160 /*
161 * init_comm()
162 *
163 * Initializes comm subsystem.
164 */
165 void
166 init_comm(void)
167 {
168  setup_socket_cb = register_callback("setup_socket", setup_socket);
169  init_netio();
153   }
154  
155   /*
# Line 252 | Line 235 | static void
235   ssl_handshake(int fd, struct Client *client_p)
236   {
237    X509 *cert = NULL;
238 <  int ret = SSL_accept(client_p->localClient->fd.ssl);
238 >  int ret = 0;
239 >
240 >  if ((ret = SSL_accept(client_p->localClient->fd.ssl)) <= 0)
241 >  {
242 >    if ((CurrentTime - client_p->localClient->firsttime) > 30)
243 >    {
244 >      exit_client(client_p, client_p, "Timeout during SSL handshake");
245 >      return;
246 >    }
247 >
248 >    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
249 >    {
250 >      case SSL_ERROR_WANT_WRITE:
251 >        comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
252 >                       (PF *) ssl_handshake, client_p, 30);
253 >        return;
254 >
255 >      case SSL_ERROR_WANT_READ:
256 >        comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
257 >                       (PF *) ssl_handshake, client_p, 30);
258 >        return;
259 >
260 >      default:
261 >        exit_client(client_p, client_p, "Error during SSL handshake");
262 >        return;
263 >    }
264 >  }
265  
266    if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
267    {
# Line 279 | Line 288 | ssl_handshake(int fd, struct Client *cli
288      X509_free(cert);
289    }
290  
282  if (ret <= 0)
283  {
284    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
285    {
286      case SSL_ERROR_WANT_WRITE:
287        comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
288                       (PF *) ssl_handshake, client_p, 0);
289        return;
290
291      case SSL_ERROR_WANT_READ:
292        comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
293                       (PF *) ssl_handshake, client_p, 0);
294        return;
295
296      default:
297        exit_client(client_p, client_p, "Error during SSL handshake");
298        return;
299    }
300  }
301
291    start_auth(client_p);
292   }
293   #endif
# Line 712 | Line 701 | comm_open(fde_t *F, int family, int sock
701    if (fd < 0)
702      return -1; /* errno will be passed through, yay.. */
703  
704 <  execute_callback(setup_socket_cb, fd);
704 >  setup_socket(fd);
705  
706    /* update things in our fd tracking */
707    fd_open(F, fd, 1, note);
# Line 753 | Line 742 | comm_accept(struct Listener *lptr, struc
742    pn->ss_len = addrlen;
743   #endif
744  
745 <  execute_callback(setup_socket_cb, newfd);
745 >  setup_socket(newfd);
746  
747    /* .. and return */
748    return newfd;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)