97
97
98
98
#endif // !WIN_NT
99
99
100
- const int INET_RETRY_CALL = 5 ;
100
+ constexpr int INET_RETRY_CALL = 5 ;
101
101
102
102
#include " ../remote/remote.h"
103
103
#include " ../remote/SockAddr.h"
@@ -136,7 +136,7 @@ using namespace Firebird;
136
136
#define INET_RETRY_ERRNO WSAEINPROGRESS
137
137
#define INET_ADDR_IN_USE WSAEADDRINUSE
138
138
#define sleep (seconds ) Sleep ((seconds) * 1000 )
139
- const int NOTASOCKET = WSAENOTSOCK;
139
+ constexpr int NOTASOCKET = WSAENOTSOCK;
140
140
141
141
#else // WIN_NT
142
142
@@ -184,9 +184,9 @@ static void SOCLOSE(SOCKET& socket)
184
184
#ifdef HAVE_SYS_TIMEB_H
185
185
# include < sys/timeb.h>
186
186
#endif
187
- const int TRACE_packets = 1 << 0 ; // bit 0
188
- const int TRACE_operations = 1 << 1 ; // bit 1
189
- const int TRACE_summary = 1 << 2 ; // bit 2
187
+ constexpr int TRACE_packets = 1 << 0 ; // bit 0
188
+ constexpr int TRACE_operations = 1 << 1 ; // bit 1
189
+ constexpr int TRACE_summary = 1 << 2 ; // bit 2
190
190
191
191
static int INET_trace = TRACE_summary | TRACE_packets | TRACE_operations;
192
192
static time_t INET_start_time = 0 ;
@@ -224,20 +224,20 @@ static ULONG inet_debug_timer()
224
224
}
225
225
#endif // DEBUG
226
226
227
- const ULONG MAX_DATA_LW = 1448 ; // Low Water mark
228
- const ULONG MAX_DATA_HW = 32768 ; // High Water mark
229
- const ULONG DEF_MAX_DATA = 8192 ;
227
+ constexpr ULONG MAX_DATA_LW = 1448 ; // Low Water mark
228
+ constexpr ULONG MAX_DATA_HW = 32768 ; // High Water mark
229
+ constexpr ULONG DEF_MAX_DATA = 8192 ;
230
230
231
- // const int MAXHOSTLEN = 64;
231
+ // constexpr int MAXHOSTLEN = 64;
232
232
233
- const int SELECT_TIMEOUT = 60 ; // Dispatch thread select timeout (sec)
233
+ constexpr int SELECT_TIMEOUT = 60 ; // Dispatch thread select timeout (sec)
234
234
235
235
class Select
236
236
{
237
237
#ifdef HAVE_POLL
238
238
private:
239
- static const int SEL_INIT_EVENTS = POLLIN;
240
- static const int SEL_CHECK_MASK = POLLIN;
239
+ static constexpr int SEL_INIT_EVENTS = POLLIN;
240
+ static constexpr int SEL_CHECK_MASK = POLLIN;
241
241
242
242
pollfd* getPollFd (int n)
243
243
{
@@ -471,7 +471,7 @@ class Select
471
471
#endif // HAVE_POLL
472
472
}
473
473
474
- int getCount ()
474
+ int getCount () noexcept
475
475
{
476
476
return slct_count;
477
477
}
@@ -696,7 +696,7 @@ rem_port* INET_analyze(ClntAuthBlock* cBlock,
696
696
697
697
// Should compression be tried?
698
698
699
- bool compression = config && (*config)->getWireCompression ();
699
+ const bool compression = config && (*config)->getWireCompression ();
700
700
701
701
// Establish connection to server
702
702
// If we want user verification, we can't speak anything less than version 7
@@ -706,7 +706,7 @@ rem_port* INET_analyze(ClntAuthBlock* cBlock,
706
706
cnct->p_cnct_user_id .cstr_length = (ULONG) user_id.getBufferLength ();
707
707
cnct->p_cnct_user_id .cstr_address = user_id.getBuffer ();
708
708
709
- static const p_cnct::p_cnct_repeat protocols_to_try[] =
709
+ static constexpr p_cnct::p_cnct_repeat protocols_to_try[] =
710
710
{
711
711
REMOTE_PROTOCOL (PROTOCOL_VERSION10, ptype_lazy_send, 1 ),
712
712
REMOTE_PROTOCOL (PROTOCOL_VERSION11, ptype_lazy_send, 2 ),
@@ -775,7 +775,7 @@ rem_port* INET_analyze(ClntAuthBlock* cBlock,
775
775
cc->p_cc_reply = 1 ;
776
776
}
777
777
UCHAR* reply = buf.getBuffer (cc->p_cc_reply );
778
- unsigned l = cryptCb->callback (cc->p_cc_data .cstr_length ,
778
+ const unsigned l = cryptCb->callback (cc->p_cc_data .cstr_length ,
779
779
cc->p_cc_data .cstr_address , cc->p_cc_reply , reply);
780
780
781
781
REMOTE_free_packet (port, packet, true );
@@ -815,7 +815,7 @@ rem_port* INET_analyze(ClntAuthBlock* cBlock,
815
815
throw ;
816
816
}
817
817
// fall through - response is not a required accept
818
-
818
+ [[fallthrough]];
819
819
default :
820
820
disconnect (port);
821
821
delete rdb;
@@ -841,7 +841,7 @@ rem_port* INET_analyze(ClntAuthBlock* cBlock,
841
841
port->port_flags |= PORT_symmetric;
842
842
}
843
843
844
- bool compress = accept->p_acpt_type & pflag_compress;
844
+ const bool compress = accept->p_acpt_type & pflag_compress;
845
845
accept->p_acpt_type &= ptype_MASK;
846
846
847
847
if (accept->p_acpt_type != ptype_out_of_band) {
@@ -955,8 +955,7 @@ rem_port* INET_connect(const TEXT* name,
955
955
// Prepare hints
956
956
const bool ipv6 = os_utils::isIPv6supported ();
957
957
958
- struct addrinfo gai_hints;
959
- memset (&gai_hints, 0 , sizeof (gai_hints));
958
+ addrinfo gai_hints {};
960
959
if (packet)
961
960
gai_hints.ai_family = af;
962
961
else
@@ -1082,7 +1081,7 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
1082
1081
*
1083
1082
**************************************/
1084
1083
1085
- int ipv6_v6only = port->getPortConfig ()->getIPv6V6Only () ? 1 : 0 ;
1084
+ const int ipv6_v6only = port->getPortConfig ()->getIPv6V6Only () ? 1 : 0 ;
1086
1085
1087
1086
int n = setsockopt (port->port_handle , IPPROTO_IPV6, IPV6_V6ONLY,
1088
1087
(SCHAR*) &ipv6_v6only, sizeof (ipv6_v6only));
@@ -1097,7 +1096,7 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
1097
1096
// e.g. while it's listening. This is surely not what we want.
1098
1097
// We set this options for any kind of listener, including standalone Classic.
1099
1098
1100
- int optval = TRUE ;
1099
+ constexpr int optval = TRUE ;
1101
1100
n = setsockopt (port->port_handle , SOL_SOCKET, SO_REUSEADDR,
1102
1101
(SCHAR*) &optval, sizeof (optval));
1103
1102
if (n == -1 )
@@ -1108,9 +1107,7 @@ static rem_port* listener_socket(rem_port* port, USHORT flag, const addrinfo* pa
1108
1107
1109
1108
if (flag & SRVR_multi_client)
1110
1109
{
1111
- struct linger lingerInfo;
1112
- lingerInfo.l_onoff = 0 ;
1113
- lingerInfo.l_linger = 0 ;
1110
+ const linger lingerInfo {};
1114
1111
1115
1112
// Get any values for SO_LINGER so that they can be reset during
1116
1113
// disconnect. SO_LINGER should be set by default on the socket
@@ -1393,7 +1390,7 @@ static rem_port* alloc_port(rem_port* const parent, const USHORT flags)
1393
1390
{
1394
1391
#ifdef WIN_NT
1395
1392
static WSADATA wsadata;
1396
- const WORD version = MAKEWORD (2 , 0 );
1393
+ constexpr WORD version = MAKEWORD (2 , 0 );
1397
1394
const int wsaError = WSAStartup (version, &wsadata);
1398
1395
if (wsaError)
1399
1396
{
@@ -1493,9 +1490,8 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet)
1493
1490
1494
1491
if (port->port_server_flags )
1495
1492
{
1496
- struct timeval timeout;
1493
+ timeval timeout {} ;
1497
1494
timeout.tv_sec = port->port_connect_timeout ;
1498
- timeout.tv_usec = 0 ;
1499
1495
1500
1496
Select slct;
1501
1497
slct.set (port->port_channel );
@@ -1515,7 +1511,7 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet)
1515
1511
1516
1512
const ISC_STATUS error_code =
1517
1513
(count == 0 ) ? isc_net_event_connect_timeout : isc_net_event_connect_err;
1518
- int savedError = inetErrNo;
1514
+ const int savedError = inetErrNo;
1519
1515
SOCLOSE (port->port_channel );
1520
1516
inet_error (false , port, " select" , error_code, savedError);
1521
1517
}
@@ -1529,7 +1525,7 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet)
1529
1525
1530
1526
if (n == INVALID_SOCKET)
1531
1527
{
1532
- int savedError = inetErrNo;
1528
+ const int savedError = inetErrNo;
1533
1529
SOCLOSE (port->port_channel );
1534
1530
inet_error (false , port, " accept" , isc_net_event_connect_err, savedError);
1535
1531
}
@@ -1563,7 +1559,7 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet)
1563
1559
int status = address.getpeername (port->port_handle );
1564
1560
if (status != 0 )
1565
1561
{
1566
- int savedError = INET_ERRNO;
1562
+ const int savedError = INET_ERRNO;
1567
1563
port->auxAcceptError (packet);
1568
1564
inet_error (false , port, " socket" , isc_net_event_connect_err, savedError);
1569
1565
}
@@ -1576,7 +1572,7 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet)
1576
1572
SOCKET n = os_utils::socket (address.family (), SOCK_STREAM, 0 );
1577
1573
if (n == INVALID_SOCKET)
1578
1574
{
1579
- int savedError = INET_ERRNO;
1575
+ const int savedError = INET_ERRNO;
1580
1576
port->auxAcceptError (packet);
1581
1577
inet_error (false , port, " socket" , isc_net_event_connect_err, savedError);
1582
1578
}
@@ -1586,7 +1582,7 @@ static rem_port* aux_connect(rem_port* port, PACKET* packet)
1586
1582
status = address.connect (n);
1587
1583
if (status < 0 )
1588
1584
{
1589
- int savedError = INET_ERRNO;
1585
+ const int savedError = INET_ERRNO;
1590
1586
SOCLOSE (n);
1591
1587
port->auxAcceptError (packet);
1592
1588
inet_error (false , port, " connect" , isc_net_event_connect_err, savedError);
@@ -1621,10 +1617,10 @@ static rem_port* aux_request( rem_port* port, PACKET* packet)
1621
1617
gds__log (" INET/aux_request: failed to get local address of the original socket" );
1622
1618
inet_error (false , port, " getsockname" , isc_net_event_listen_err, INET_ERRNO);
1623
1619
}
1624
- unsigned short aux_port = port->getPortConfig ()->getRemoteAuxPort ();
1620
+ const unsigned short aux_port = port->getPortConfig ()->getRemoteAuxPort ();
1625
1621
our_address.setPort (aux_port); // may be 0
1626
1622
1627
- SOCKET n = os_utils::socket (our_address.family (), SOCK_STREAM, 0 );
1623
+ const SOCKET n = os_utils::socket (our_address.family (), SOCK_STREAM, 0 );
1628
1624
if (n == INVALID_SOCKET)
1629
1625
{
1630
1626
inet_error (false , port, " socket" , isc_net_event_listen_err, INET_ERRNO);
@@ -1686,19 +1682,20 @@ static rem_port* aux_request( rem_port* port, PACKET* packet)
1686
1682
// Here we try to make this case work. However it's not bullet-proof for others platforms and architectures.
1687
1683
// A proper solution would be to just send the port number in a protocol friendly way.
1688
1684
1689
- bool macOsClient =
1685
+ const bool macOsClient =
1690
1686
port->port_client_arch == arch_darwin_ppc ||
1691
1687
port->port_client_arch == arch_darwin_x64 ||
1692
1688
port->port_client_arch == arch_darwin_ppc64;
1693
1689
1694
- bool macOsServer =
1690
+ if constexpr (
1695
1691
ARCHITECTURE == arch_darwin_ppc ||
1696
1692
ARCHITECTURE == arch_darwin_x64 ||
1697
- ARCHITECTURE == arch_darwin_ppc64;
1698
-
1699
- if (macOsServer && !macOsClient)
1700
- port_address.convertFromMacOsToPosixWindows ();
1701
- else if (!macOsServer && macOsClient)
1693
+ ARCHITECTURE == arch_darwin_ppc64)
1694
+ {
1695
+ if (!macOsClient)
1696
+ port_address.convertFromMacOsToPosixWindows ();
1697
+ }
1698
+ else if (macOsClient)
1702
1699
port_address.convertFromPosixWindowsToMacOs ();
1703
1700
1704
1701
response->p_resp_data .cstr_length = (ULONG) port_address.length ();
@@ -2211,7 +2208,7 @@ static void select_port(rem_port* main_port, Select* selct, RemPortPtr& port)
2211
2208
MutexLockGuard guard (port_mutex, FB_FUNCTION);
2212
2209
while (true )
2213
2210
{
2214
- Select::HandleState result = selct->checkNext (port);
2211
+ const Select::HandleState result = selct->checkNext (port);
2215
2212
if (!port)
2216
2213
return ;
2217
2214
@@ -2254,7 +2251,6 @@ static bool select_wait( rem_port* main_port, Select* selct)
2254
2251
* to read from them.
2255
2252
*
2256
2253
**************************************/
2257
- struct timeval timeout;
2258
2254
bool checkPorts = false ;
2259
2255
2260
2256
for (;;)
@@ -2305,13 +2301,12 @@ static bool select_wait( rem_port* main_port, Select* selct)
2305
2301
// in current fdset. Search and return it to caller to close
2306
2302
// broken connection correctly
2307
2303
2308
- struct linger lngr;
2304
+ linger lngr {} ;
2309
2305
socklen_t optlen = sizeof (lngr);
2310
- const bool badSocket =
2311
2306
#ifdef WIN_NT
2312
- false ;
2307
+ constexpr bool badSocket = false ;
2313
2308
#else
2314
- (port->port_handle < 0 || port->port_handle >= FD_SETSIZE);
2309
+ const bool badSocket = (port->port_handle < 0 || port->port_handle >= FD_SETSIZE);
2315
2310
#endif
2316
2311
2317
2312
if (badSocket || getsockopt (port->port_handle ,
@@ -2365,9 +2360,8 @@ static bool select_wait( rem_port* main_port, Select* selct)
2365
2360
2366
2361
// Some platforms change the timeout in the select call.
2367
2362
// Reset timeout for each iteration to avoid problems.
2363
+ timeval timeout {};
2368
2364
timeout.tv_sec = SELECT_TIMEOUT;
2369
- timeout.tv_usec = 0 ;
2370
-
2371
2365
selct->select (&timeout);
2372
2366
const int inetErrNo = INET_ERRNO;
2373
2367
@@ -2529,7 +2523,7 @@ void get_peer_info(rem_port* port)
2529
2523
address.unmapV4 (); // convert mapped IPv4 to regular IPv4
2530
2524
char host[64 ]; // 32 digits, 7 colons, 1 trailing null byte
2531
2525
char serv[16 ];
2532
- int nameinfo = getnameinfo (address.ptr (), address.length (), host, sizeof (host),
2526
+ const int nameinfo = getnameinfo (address.ptr (), address.length (), host, sizeof (host),
2533
2527
serv, sizeof (serv), NI_NUMERICHOST | NI_NUMERICSERV);
2534
2528
2535
2529
if (!nameinfo)
@@ -2969,8 +2963,7 @@ static bool packet_receive(rem_port* port, UCHAR* buffer, SSHORT buffer_length,
2969
2963
return false ;
2970
2964
}
2971
2965
2972
- timeval timeout;
2973
- timeout.tv_usec = 0 ;
2966
+ timeval timeout{};
2974
2967
timeval* time_ptr = NULL ;
2975
2968
2976
2969
if (port->port_protocol == 0 )
@@ -3330,8 +3323,8 @@ static bool setNoNagleOption(rem_port* port)
3330
3323
**************************************/
3331
3324
if (port->getPortConfig ()->getTcpNoNagle ())
3332
3325
{
3333
- int optval = TRUE ;
3334
- int n = setsockopt (port->port_handle , IPPROTO_TCP, TCP_NODELAY,
3326
+ constexpr int optval = TRUE ;
3327
+ const int n = setsockopt (port->port_handle , IPPROTO_TCP, TCP_NODELAY,
3335
3328
(SCHAR*) &optval, sizeof (optval));
3336
3329
3337
3330
if (n == -1 )
@@ -3355,8 +3348,8 @@ static bool setKeepAlive(SOCKET s)
3355
3348
* in case of unexpected error
3356
3349
*
3357
3350
**************************************/
3358
- int optval = 1 ;
3359
- int n = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE,
3351
+ constexpr int optval = 1 ;
3352
+ const int n = setsockopt (s, SOL_SOCKET, SO_KEEPALIVE,
3360
3353
(SCHAR*) &optval, sizeof (optval));
3361
3354
return n != -1 ;
3362
3355
}
0 commit comments