OLD | NEW |
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | 5 |
6 /* | 6 /* |
7 * This file defines _PR_MapOptionName(). The purpose of putting | 7 * This file defines _PR_MapOptionName(). The purpose of putting |
8 * _PR_MapOptionName() in a separate file is to work around a Winsock | 8 * _PR_MapOptionName() in a separate file is to work around a Winsock |
9 * header file problem on Windows NT. | 9 * header file problem on Windows NT. |
10 * | 10 * |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 break; | 78 break; |
79 #else | 79 #else |
80 PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 ); | 80 PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 ); |
81 return PR_FAILURE; | 81 return PR_FAILURE; |
82 #endif | 82 #endif |
83 } | 83 } |
84 case PR_SockOpt_Reuseaddr: | 84 case PR_SockOpt_Reuseaddr: |
85 case PR_SockOpt_Keepalive: | 85 case PR_SockOpt_Keepalive: |
86 case PR_SockOpt_NoDelay: | 86 case PR_SockOpt_NoDelay: |
87 case PR_SockOpt_Broadcast: | 87 case PR_SockOpt_Broadcast: |
| 88 case PR_SockOpt_Reuseport: |
88 { | 89 { |
89 #ifdef WIN32 /* Winsock */ | 90 #ifdef WIN32 /* Winsock */ |
90 BOOL value; | 91 BOOL value; |
91 #else | 92 #else |
92 PRIntn value; | 93 PRIntn value; |
93 #endif | 94 #endif |
94 length = sizeof(value); | 95 length = sizeof(value); |
95 rv = _PR_MD_GETSOCKOPT( | 96 rv = _PR_MD_GETSOCKOPT( |
96 fd, level, name, (char*)&value, &length); | 97 fd, level, name, (char*)&value, &length); |
97 if (PR_SUCCESS == rv) | 98 if (PR_SUCCESS == rv) |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 break; | 230 break; |
230 #else | 231 #else |
231 PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 ); | 232 PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 ); |
232 return PR_FAILURE; | 233 return PR_FAILURE; |
233 #endif | 234 #endif |
234 } | 235 } |
235 case PR_SockOpt_Reuseaddr: | 236 case PR_SockOpt_Reuseaddr: |
236 case PR_SockOpt_Keepalive: | 237 case PR_SockOpt_Keepalive: |
237 case PR_SockOpt_NoDelay: | 238 case PR_SockOpt_NoDelay: |
238 case PR_SockOpt_Broadcast: | 239 case PR_SockOpt_Broadcast: |
| 240 case PR_SockOpt_Reuseport: |
239 { | 241 { |
240 #ifdef WIN32 /* Winsock */ | 242 #ifdef WIN32 /* Winsock */ |
241 BOOL value; | 243 BOOL value; |
242 #else | 244 #else |
243 PRIntn value; | 245 PRIntn value; |
244 #endif | 246 #endif |
245 value = (data->value.reuse_addr) ? 1 : 0; | 247 value = (data->value.reuse_addr) ? 1 : 0; |
246 rv = _PR_MD_SETSOCKOPT( | 248 rv = _PR_MD_SETSOCKOPT( |
247 fd, level, name, (char*)&value, sizeof(value)); | 249 fd, level, name, (char*)&value, sizeof(value)); |
248 break; | 250 break; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 #endif | 407 #endif |
406 | 408 |
407 #ifndef TCP_NODELAY /* don't delay to coalesce data */ | 409 #ifndef TCP_NODELAY /* don't delay to coalesce data */ |
408 #define TCP_NODELAY _PR_NO_SUCH_SOCKOPT | 410 #define TCP_NODELAY _PR_NO_SUCH_SOCKOPT |
409 #endif | 411 #endif |
410 | 412 |
411 #ifndef TCP_MAXSEG /* maxumum segment size for tcp */ | 413 #ifndef TCP_MAXSEG /* maxumum segment size for tcp */ |
412 #define TCP_MAXSEG _PR_NO_SUCH_SOCKOPT | 414 #define TCP_MAXSEG _PR_NO_SUCH_SOCKOPT |
413 #endif | 415 #endif |
414 | 416 |
415 #ifndef SO_BROADCAST /* enable broadcast on udp sockets */ | 417 #ifndef SO_BROADCAST /* enable broadcast on UDP sockets */ |
416 #define SO_BROADCAST _PR_NO_SUCH_SOCKOPT | 418 #define SO_BROADCAST _PR_NO_SUCH_SOCKOPT |
417 #endif | 419 #endif |
418 | 420 |
| 421 #ifndef SO_REUSEPORT /* allow local address & port reuse */ |
| 422 #define SO_REUSEPORT _PR_NO_SUCH_SOCKOPT |
| 423 #endif |
| 424 |
419 PRStatus _PR_MapOptionName( | 425 PRStatus _PR_MapOptionName( |
420 PRSockOption optname, PRInt32 *level, PRInt32 *name) | 426 PRSockOption optname, PRInt32 *level, PRInt32 *name) |
421 { | 427 { |
422 static PRInt32 socketOptions[PR_SockOpt_Last] = | 428 static PRInt32 socketOptions[PR_SockOpt_Last] = |
423 { | 429 { |
424 0, SO_LINGER, SO_REUSEADDR, SO_KEEPALIVE, SO_RCVBUF, SO_SNDBUF, | 430 0, SO_LINGER, SO_REUSEADDR, SO_KEEPALIVE, SO_RCVBUF, SO_SNDBUF, |
425 IP_TTL, IP_TOS, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, | 431 IP_TTL, IP_TOS, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, |
426 IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP, | 432 IP_MULTICAST_IF, IP_MULTICAST_TTL, IP_MULTICAST_LOOP, |
427 TCP_NODELAY, TCP_MAXSEG, SO_BROADCAST | 433 TCP_NODELAY, TCP_MAXSEG, SO_BROADCAST, SO_REUSEPORT |
428 }; | 434 }; |
429 static PRInt32 socketLevels[PR_SockOpt_Last] = | 435 static PRInt32 socketLevels[PR_SockOpt_Last] = |
430 { | 436 { |
431 0, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, | 437 0, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, SOL_SOCKET, |
432 IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, | 438 IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, |
433 IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, | 439 IPPROTO_IP, IPPROTO_IP, IPPROTO_IP, |
434 IPPROTO_TCP, IPPROTO_TCP, SOL_SOCKET | 440 IPPROTO_TCP, IPPROTO_TCP, SOL_SOCKET, SOL_SOCKET |
435 }; | 441 }; |
436 | 442 |
437 if ((optname < PR_SockOpt_Linger) | 443 if ((optname < PR_SockOpt_Linger) |
438 || (optname >= PR_SockOpt_Last)) | 444 || (optname >= PR_SockOpt_Last)) |
439 { | 445 { |
440 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); | 446 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
441 return PR_FAILURE; | 447 return PR_FAILURE; |
442 } | 448 } |
443 | 449 |
444 if (socketOptions[optname] == _PR_NO_SUCH_SOCKOPT) | 450 if (socketOptions[optname] == _PR_NO_SUCH_SOCKOPT) |
445 { | 451 { |
446 PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, 0); | 452 PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, 0); |
447 return PR_FAILURE; | 453 return PR_FAILURE; |
448 } | 454 } |
449 *name = socketOptions[optname]; | 455 *name = socketOptions[optname]; |
450 *level = socketLevels[optname]; | 456 *level = socketLevels[optname]; |
451 return PR_SUCCESS; | 457 return PR_SUCCESS; |
452 } /* _PR_MapOptionName */ | 458 } /* _PR_MapOptionName */ |
OLD | NEW |