| 1371 | |
| 1372 | |
| 1373 | static rem_port* alloc_port(rem_port* const parent, const USHORT flags) |
| 1374 | { |
| 1375 | /************************************** |
| 1376 | * |
| 1377 | * a l l o c _ p o r t |
| 1378 | * |
| 1379 | ************************************** |
| 1380 | * |
| 1381 | * Functional description |
| 1382 | * Allocate a port block, link it in to parent (if there is a parent), |
| 1383 | * and initialize input and output XDR streams. |
| 1384 | * |
| 1385 | **************************************/ |
| 1386 | |
| 1387 | if (!INET_initialized) |
| 1388 | { |
| 1389 | MutexLockGuard guard(init_mutex, FB_FUNCTION); |
| 1390 | if (!INET_initialized) |
| 1391 | { |
| 1392 | #ifdef WIN_NT |
| 1393 | static WSADATA wsadata; |
| 1394 | const WORD version = MAKEWORD(2, 0); |
| 1395 | const int wsaError = WSAStartup(version, &wsadata); |
| 1396 | if (wsaError) |
| 1397 | { |
| 1398 | inet_error(false, parent, "WSAStartup", isc_net_init_error, wsaError); |
| 1399 | } |
| 1400 | fb_shutdown_callback(0, wsaExitHandler, fb_shut_finish, 0); |
| 1401 | #endif |
| 1402 | INET_remote_buffer = Config::getTcpRemoteBufferSize(); |
| 1403 | if (INET_remote_buffer < MAX_DATA_LW || INET_remote_buffer > MAX_DATA_HW) |
| 1404 | { |
| 1405 | INET_remote_buffer = DEF_MAX_DATA; |
| 1406 | } |
| 1407 | #ifdef DEBUG |
| 1408 | gds__log(" Info: Remote Buffer Size set to %ld", INET_remote_buffer); |
| 1409 | #endif |
| 1410 | |
| 1411 | fb_shutdown_callback(0, cleanup_ports, fb_shut_postproviders, 0); |
| 1412 | |
| 1413 | INET_initialized = true; |
| 1414 | |
| 1415 | // This should go AFTER 'INET_initialized = true' to avoid recursion |
| 1416 | // That order of statements at the first glance appears to be possible cause of races: |
| 1417 | // Someone may pass the if (!INET_initialized) with INET_initialized == true, |
| 1418 | // but inet_async_receive still being NULL. Luckily it's not so awful actually. |
| 1419 | // Async receive is used only by network server and there is no way for it |
| 1420 | // to allocate secondary ports until completion of master port init. |
| 1421 | inet_async_receive = alloc_port(0); |
| 1422 | inet_async_receive->port_flags |= PORT_server; |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | rem_port* const port = FB_NEW rem_port(rem_port::INET, INET_remote_buffer * 2); |
| 1427 | REMOTE_get_timeout_params(port, 0); |
| 1428 | |
| 1429 | TEXT buffer[BUFFER_SMALL]; |
| 1430 | gethostname(buffer, sizeof(buffer)); |
no test coverage detected