mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-24 09:23:03 +01:00
1. Cleanup
2. Fixed known issues with event processing 3. Used new config options Although these changes seem to be unix-sockets compliant, I'm only 99% sure in it, so please let me know if it breaks any platform build.
This commit is contained in:
parent
270afc6b4c
commit
15fe1fb209
@ -41,7 +41,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
$Id: inet.cpp,v 1.59 2003-03-11 19:51:07 brodsom Exp $
|
$Id: inet.cpp,v 1.60 2003-03-12 10:13:58 dimitr Exp $
|
||||||
*/
|
*/
|
||||||
#include "firebird.h"
|
#include "firebird.h"
|
||||||
#include "../jrd/ib_stdio.h"
|
#include "../jrd/ib_stdio.h"
|
||||||
@ -348,6 +348,8 @@ static int fork(void);
|
|||||||
static int fork(SOCKET, USHORT);
|
static int fork(SOCKET, USHORT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static ULONG get_bind_address();
|
||||||
|
static hostent * get_host(const TEXT *);
|
||||||
|
|
||||||
static void copy_p_cnct_repeat_array( p_cnct::p_cnct_repeat* pDest,
|
static void copy_p_cnct_repeat_array( p_cnct::p_cnct_repeat* pDest,
|
||||||
const p_cnct::p_cnct_repeat* pSource,
|
const p_cnct::p_cnct_repeat* pSource,
|
||||||
@ -378,7 +380,6 @@ static PORT inet_try_connect( PACKET*,
|
|||||||
SSHORT);
|
SSHORT);
|
||||||
static bool_t inet_write(XDR *, int);
|
static bool_t inet_write(XDR *, int);
|
||||||
static void inet_zero(SCHAR *, int);
|
static void inet_zero(SCHAR *, int);
|
||||||
//static int initWSA(PORT);
|
|
||||||
#if !(defined WIN_NT)
|
#if !(defined WIN_NT)
|
||||||
static int parse_hosts(TEXT *, TEXT *, TEXT *);
|
static int parse_hosts(TEXT *, TEXT *, TEXT *);
|
||||||
static int parse_line(TEXT *, TEXT *, TEXT *, TEXT *);
|
static int parse_line(TEXT *, TEXT *, TEXT *, TEXT *);
|
||||||
@ -828,7 +829,6 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
#endif
|
#endif
|
||||||
int optval;
|
int optval;
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{
|
{
|
||||||
UCHAR *p;
|
UCHAR *p;
|
||||||
@ -902,7 +902,8 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
|
|
||||||
/* U N I X style sockets */
|
/* U N I X style sockets */
|
||||||
THREAD_EXIT;
|
THREAD_EXIT;
|
||||||
host = gethostbyname(name);
|
|
||||||
|
host = get_host(name);
|
||||||
|
|
||||||
/* On Windows NT/9x, gethostbyname can only accomodate
|
/* On Windows NT/9x, gethostbyname can only accomodate
|
||||||
* 1 call at a time. In this case it returns the error
|
* 1 call at a time. In this case it returns the error
|
||||||
@ -913,11 +914,9 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
* NOTE: This still does not guarantee success, but helps.
|
* NOTE: This still does not guarantee success, but helps.
|
||||||
*/
|
*/
|
||||||
if (!host) {
|
if (!host) {
|
||||||
int retry;
|
|
||||||
if (H_ERRNO == INET_RETRY_ERRNO) {
|
if (H_ERRNO == INET_RETRY_ERRNO) {
|
||||||
for (retry = 0; retry < INET_RETRY_CALL; retry++) {
|
for (int retry = 0; retry < INET_RETRY_CALL; retry++) {
|
||||||
host = gethostbyname(name);
|
if ( (host = get_host(name)) )
|
||||||
if (host)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -948,7 +947,7 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
sizeof(address.sin_addr));
|
sizeof(address.sin_addr));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
address.sin_addr.s_addr = INADDR_ANY;
|
address.sin_addr.s_addr = get_bind_address();
|
||||||
}
|
}
|
||||||
|
|
||||||
THREAD_EXIT;
|
THREAD_EXIT;
|
||||||
@ -962,11 +961,9 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
* NOTE: This still does not guarantee success, but helps.
|
* NOTE: This still does not guarantee success, but helps.
|
||||||
*/
|
*/
|
||||||
if (!service) {
|
if (!service) {
|
||||||
int retry;
|
|
||||||
if (H_ERRNO == INET_RETRY_ERRNO) {
|
if (H_ERRNO == INET_RETRY_ERRNO) {
|
||||||
for (retry = 0; retry < INET_RETRY_CALL; retry++) {
|
for (int retry = 0; retry < INET_RETRY_CALL; retry++) {
|
||||||
service = getservbyname(protocol, "tcp");
|
if ( (service = getservbyname(protocol, "tcp")) )
|
||||||
if (service)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -977,7 +974,7 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
/* Modification by luz (slightly modified by FSG)
|
/* Modification by luz (slightly modified by FSG)
|
||||||
instead of failing here, try applying hard-wired
|
instead of failing here, try applying hard-wired
|
||||||
translation of "gds_db" into "3050"
|
translation of "gds_db" into "3050"
|
||||||
This way, a connection to a remote IB server
|
This way, a connection to a remote FB server
|
||||||
works even from clients with missing "gds_db"
|
works even from clients with missing "gds_db"
|
||||||
entry in "services" file, which is important
|
entry in "services" file, which is important
|
||||||
for zero-installation clients.
|
for zero-installation clients.
|
||||||
@ -1104,8 +1101,6 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
|
|
||||||
gds__log("inet log: disabled Nagle algorithm \n");
|
gds__log("inet log: disabled Nagle algorithm \n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (n == -1) {
|
if (n == -1) {
|
||||||
inet_error(port, "setsockopt TCP_NODELAY",
|
inet_error(port, "setsockopt TCP_NODELAY",
|
||||||
isc_net_connect_listen_err, ERRNO);
|
isc_net_connect_listen_err, ERRNO);
|
||||||
@ -1115,9 +1110,6 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = bind((SOCKET) port->port_handle,
|
n = bind((SOCKET) port->port_handle,
|
||||||
@ -1163,8 +1155,7 @@ PORT DLL_EXPORT INET_connect(TEXT * name,
|
|||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
while (TRUE) {
|
|
||||||
THREAD_EXIT;
|
THREAD_EXIT;
|
||||||
l = sizeof(address);
|
l = sizeof(address);
|
||||||
s = accept((SOCKET) port->port_handle,
|
s = accept((SOCKET) port->port_handle,
|
||||||
@ -1707,22 +1698,22 @@ static PORT aux_request( PORT port, PACKET * packet)
|
|||||||
P_RESP *response;
|
P_RESP *response;
|
||||||
SOCKET n;
|
SOCKET n;
|
||||||
socklen_t length;
|
socklen_t length;
|
||||||
struct sockaddr_in address;
|
struct sockaddr_in address, port_address;
|
||||||
#ifndef VMS
|
int optval;
|
||||||
struct hostent *host;
|
|
||||||
TEXT msg[64];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Set up new socket */
|
/* Set up new socket */
|
||||||
|
|
||||||
|
address.sin_family = AF_INET;
|
||||||
|
address.sin_addr.s_addr = get_bind_address();
|
||||||
|
address.sin_port = htons(Config::getRemoteAuxPort());
|
||||||
|
|
||||||
if ((n = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
|
if ((n = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
|
||||||
inet_error(port, "socket", isc_net_event_listen_err, ERRNO);
|
inet_error(port, "socket", isc_net_event_listen_err, ERRNO);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
address.sin_family = AF_INET;
|
setsockopt(n, SOL_SOCKET, SO_REUSEADDR,
|
||||||
address.sin_addr.s_addr = INADDR_ANY;
|
(SCHAR *) &optval, sizeof(optval));
|
||||||
address.sin_port = 0;
|
|
||||||
|
|
||||||
if (bind(n, (struct sockaddr *) &address, sizeof(address)) < 0) {
|
if (bind(n, (struct sockaddr *) &address, sizeof(address)) < 0) {
|
||||||
inet_error(port, "bind", isc_net_event_listen_err, ERRNO);
|
inet_error(port, "bind", isc_net_event_listen_err, ERRNO);
|
||||||
@ -1751,31 +1742,11 @@ static PORT aux_request( PORT port, PACKET * packet)
|
|||||||
|
|
||||||
response = &packet->p_resp;
|
response = &packet->p_resp;
|
||||||
|
|
||||||
#ifdef VMS
|
if (getsockname((SOCKET) port->port_handle, (struct sockaddr *) &port_address, &length) < 0) {
|
||||||
if (getaddr(port->port_host->str_data, &address) == -1) {
|
inet_error(port, "getsockname", isc_net_event_listen_err, ERRNO);
|
||||||
inet_error(port, "gethostbyname", isc_net_event_listen_err, 0);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
address.sin_addr = port_address.sin_addr;
|
||||||
THREAD_EXIT;
|
|
||||||
host = gethostbyname(port->port_host->str_data);
|
|
||||||
THREAD_ENTER;
|
|
||||||
if (!host) {
|
|
||||||
sprintf(msg,
|
|
||||||
"INET/aux_request: gethostbyname failed, error code = %d",
|
|
||||||
H_ERRNO);
|
|
||||||
gds__log(msg, 0);
|
|
||||||
inet_gen_error(port,
|
|
||||||
isc_network_error,
|
|
||||||
isc_arg_string,
|
|
||||||
port->port_host->str_data,
|
|
||||||
isc_arg_gds,
|
|
||||||
isc_net_lookup_err, isc_arg_gds, isc_host_unknown, 0);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
inet_copy(host->h_addr, (SCHAR *) & address.sin_addr,
|
|
||||||
sizeof(address.sin_addr));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
response->p_resp_data.cstr_address = (UCHAR *) & response->p_resp_blob_id;
|
response->p_resp_data.cstr_address = (UCHAR *) & response->p_resp_blob_id;
|
||||||
response->p_resp_data.cstr_length = sizeof(response->p_resp_blob_id);
|
response->p_resp_data.cstr_length = sizeof(response->p_resp_blob_id);
|
||||||
@ -2233,6 +2204,40 @@ static int fork( SOCKET old_handle, USHORT flag)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static ULONG get_bind_address()
|
||||||
|
{
|
||||||
|
/**************************************
|
||||||
|
*
|
||||||
|
* g e t _ b i n d _ a d d r e s s
|
||||||
|
*
|
||||||
|
**************************************
|
||||||
|
*
|
||||||
|
* Functional description
|
||||||
|
* Return local address to bind sockets to.
|
||||||
|
*
|
||||||
|
**************************************/
|
||||||
|
const char* config_option = Config::getRemoteBindAddress();
|
||||||
|
ULONG config_address = (config_option) ? inet_addr(config_option) : INADDR_NONE;
|
||||||
|
return (config_address == INADDR_NONE) ? INADDR_ANY : config_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
static hostent * get_host(const TEXT * name)
|
||||||
|
{
|
||||||
|
/**************************************
|
||||||
|
*
|
||||||
|
* g e t _ h o s t
|
||||||
|
*
|
||||||
|
**************************************
|
||||||
|
*
|
||||||
|
* Functional description
|
||||||
|
* Return host information.
|
||||||
|
*
|
||||||
|
**************************************/
|
||||||
|
ULONG address = inet_addr(name);
|
||||||
|
return (address == INADDR_NONE) ?
|
||||||
|
gethostbyname(name) :
|
||||||
|
gethostbyaddr((SCHAR *) &address, sizeof(ULONG), AF_INET);
|
||||||
|
}
|
||||||
|
|
||||||
//____________________________________________________________
|
//____________________________________________________________
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user