comparison src/core/ngx_connection.c @ 7304:5c2ac36fcf56

Added FreeBSD support for "listen ... reuseport".
author Ruslan Ermilov <ru@nginx.com>
date Mon, 02 Jul 2018 13:54:33 +0300
parents d27aa9060c95
children e7b2b907c0f8
comparison
equal deleted inserted replaced
7303:118885f7a577 7304:5c2ac36fcf56
279 #if (NGX_HAVE_REUSEPORT) 279 #if (NGX_HAVE_REUSEPORT)
280 280
281 reuseport = 0; 281 reuseport = 0;
282 olen = sizeof(int); 282 olen = sizeof(int);
283 283
284 #ifdef SO_REUSEPORT_LB
285
286 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT_LB,
287 (void *) &reuseport, &olen)
288 == -1)
289 {
290 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
291 "getsockopt(SO_REUSEPORT_LB) %V failed, ignored",
292 &ls[i].addr_text);
293
294 } else {
295 ls[i].reuseport = reuseport ? 1 : 0;
296 }
297
298 #else
299
284 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT, 300 if (getsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT,
285 (void *) &reuseport, &olen) 301 (void *) &reuseport, &olen)
286 == -1) 302 == -1)
287 { 303 {
288 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, 304 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
290 &ls[i].addr_text); 306 &ls[i].addr_text);
291 307
292 } else { 308 } else {
293 ls[i].reuseport = reuseport ? 1 : 0; 309 ls[i].reuseport = reuseport ? 1 : 0;
294 } 310 }
311 #endif
295 312
296 #endif 313 #endif
297 314
298 if (ls[i].type != SOCK_STREAM) { 315 if (ls[i].type != SOCK_STREAM) {
299 continue; 316 continue;
428 * SO_REUSEPORT on the old socket before opening new ones 445 * SO_REUSEPORT on the old socket before opening new ones
429 */ 446 */
430 447
431 int reuseport = 1; 448 int reuseport = 1;
432 449
450 #ifdef SO_REUSEPORT_LB
451
452 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT_LB,
453 (const void *) &reuseport, sizeof(int))
454 == -1)
455 {
456 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
457 "setsockopt(SO_REUSEPORT_LB) %V failed, "
458 "ignored",
459 &ls[i].addr_text);
460 }
461
462 #else
463
433 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT, 464 if (setsockopt(ls[i].fd, SOL_SOCKET, SO_REUSEPORT,
434 (const void *) &reuseport, sizeof(int)) 465 (const void *) &reuseport, sizeof(int))
435 == -1) 466 == -1)
436 { 467 {
437 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno, 468 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_socket_errno,
438 "setsockopt(SO_REUSEPORT) %V failed, ignored", 469 "setsockopt(SO_REUSEPORT) %V failed, ignored",
439 &ls[i].addr_text); 470 &ls[i].addr_text);
440 } 471 }
472 #endif
441 473
442 ls[i].add_reuseport = 0; 474 ls[i].add_reuseport = 0;
443 } 475 }
444 #endif 476 #endif
445 477
485 517
486 if (ls[i].reuseport && !ngx_test_config) { 518 if (ls[i].reuseport && !ngx_test_config) {
487 int reuseport; 519 int reuseport;
488 520
489 reuseport = 1; 521 reuseport = 1;
522
523 #ifdef SO_REUSEPORT_LB
524
525 if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT_LB,
526 (const void *) &reuseport, sizeof(int))
527 == -1)
528 {
529 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
530 "setsockopt(SO_REUSEPORT_LB) %V failed",
531 &ls[i].addr_text);
532
533 if (ngx_close_socket(s) == -1) {
534 ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
535 ngx_close_socket_n " %V failed",
536 &ls[i].addr_text);
537 }
538
539 return NGX_ERROR;
540 }
541
542 #else
490 543
491 if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, 544 if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT,
492 (const void *) &reuseport, sizeof(int)) 545 (const void *) &reuseport, sizeof(int))
493 == -1) 546 == -1)
494 { 547 {
502 &ls[i].addr_text); 555 &ls[i].addr_text);
503 } 556 }
504 557
505 return NGX_ERROR; 558 return NGX_ERROR;
506 } 559 }
560 #endif
507 } 561 }
508 #endif 562 #endif
509 563
510 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) 564 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
511 565