Skip to content

Commit dfe45ea

Browse files
committed
Windows support for Unix Domain Sockets
1 parent f72b9d5 commit dfe45ea

11 files changed

Lines changed: 193 additions & 51 deletions

File tree

builds/cmake/Configure.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ set(CASE_SENSITIVITY "true")
116116
set(SUPPORT_RAW_DEVICES 1)
117117

118118
set(include_files_list
119+
afunix.h
119120
aio.h
120121
assert.h
121122
atomic.h

builds/install/misc/firebird.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,9 +783,9 @@
783783

784784
# ----------------------------
785785
# Unix domain socket path to be used for client database and service
786-
# connections on POSIX platforms. If set, the server listens on this
787-
# socket instead of the TCP service name/port. The name should not
788-
# contain colons.
786+
# connections on platforms with Unix domain socket support. If set,
787+
# the server listens on this socket instead of the TCP service name/port.
788+
# The name should not contain colons, except for a Windows drive letter.
789789
#
790790
# Event notification connections use a separate Unix domain socket in
791791
# the same directory as this socket. Firebird chooses its name as

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,7 @@ AC_CHECK_HEADERS(iconv.h)
893893
AC_CHECK_HEADERS(linux/falloc.h)
894894
AC_CHECK_HEADERS(utime.h)
895895

896-
AC_CHECK_HEADERS(socket.h sys/socket.h sys/sockio.h sys/un.h winsock2.h)
896+
AC_CHECK_HEADERS(afunix.h socket.h sys/socket.h sys/sockio.h sys/un.h winsock2.h)
897897
AC_CHECK_DECLS(SOCK_CLOEXEC,,,[[
898898
#ifdef HAVE_SYS_SOCKET_H
899899
#include <sys/socket.h>

doc/Firebird_conf.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ DeadThreadsCollection integer default 50
142142
PriorityBoost integer default 5
143143
RemoteServiceName string default gds_db
144144
RemoteServicePort integer default 3050 (TCP port number)
145-
RemoteServiceUnixSocket string default empty (Unix domain socket path, POSIX only)
145+
RemoteServiceUnixSocket string default empty (Unix domain socket path)
146146
IpcName string default "FIREBIRD" (Windows only)
147147

148148
MaxUnflushedWrites integer

doc/README.connection_strings

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ Examples:
110110
inet://C:\db\mydb.fdb
111111
inet://mydb
112112

113-
Local connection via Unix domain socket (POSIX only):
113+
Local connection via Unix domain socket:
114114

115115
unix:///run/firebird/firebird.sock:/db/mydb.fdb
116116
unix:///run/firebird/firebird.sock:mydb
117117
unix:///run/firebird/firebird.sock:service_mgr
118+
unix://C:\firebird\firebird.sock:C:\db\mydb.fdb
118119

119120
Local connection via shared memory:
120121

@@ -146,5 +147,6 @@ to connect locally using a specific transport protocol, please specify:
146147
xnet://<file path to database or alias>
147148

148149
Note: XNET (shared memory) protocol is available on Windows only.
149-
Unix domain socket protocol is available on POSIX only and the socket path
150-
must not contain ':'.
150+
Unix domain socket protocol is available on platforms with AF_UNIX support.
151+
The socket path must not contain ':' except for a Windows drive letter, as in
152+
unix://C:\firebird\firebird.sock:C:\db\mydb.fdb.

src/include/gen/autoconfig.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@
330330
/* Define to 1 if you have the <sys/signal.h> header file. */
331331
#cmakedefine HAVE_SYS_SIGNAL_H 1
332332

333+
/* Define to 1 if you have the <afunix.h> header file. */
334+
#cmakedefine HAVE_AFUNIX_H 1
335+
333336
/* Define to 1 if you have the <sys/socket.h> header file. */
334337
#cmakedefine HAVE_SYS_SOCKET_H 1
335338

src/include/gen/autoconfig_msvc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#endif
9393

9494
/* Headers */
95+
#define HAVE_AFUNIX_H
9596
#define HAVE_ASSERT_H
9697
#define HAVE_CTYPE_H
9798
#undef HAVE_UNISTD_H

src/remote/client/interface.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,14 @@
8787
#endif
8888

8989
#ifdef WIN_NT
90+
#include <winsock2.h>
9091
#include <process.h>
9192
#endif
9293

94+
#if (defined(WIN_NT) && defined(HAVE_AFUNIX_H)) || defined(HAVE_SYS_UN_H)
95+
#define HAVE_AF_UNIX_SUPPORT
96+
#endif
97+
9398
#if defined(WIN_NT)
9499
#include "../common/isc_proto.h"
95100
#include "../remote/os/win32/xnet_proto.h"
@@ -100,7 +105,7 @@ const char* const PROTOCOL_INET = "inet";
100105
const char* const PROTOCOL_INET4 = "inet4";
101106
const char* const PROTOCOL_INET6 = "inet6";
102107

103-
#if !defined(WIN_NT) && defined(HAVE_SYS_UN_H)
108+
#ifdef HAVE_AF_UNIX_SUPPORT
104109
const char* const PROTOCOL_UNIX = "unix";
105110
#endif
106111

@@ -1178,7 +1183,7 @@ static void authReceiveResponse(bool havePacket, ClntAuthBlock& authItr, rem_por
11781183

11791184
static AtomicCounter remote_event_id;
11801185

1181-
#if !defined(WIN_NT) && defined(HAVE_SYS_UN_H)
1186+
#ifdef HAVE_AF_UNIX_SUPPORT
11821187
static bool analyzeUnixProtocol(PathName& expandedName, PathName& nodeName)
11831188
{
11841189
nodeName.erase();
@@ -1194,7 +1199,17 @@ static bool analyzeUnixProtocol(PathName& expandedName, PathName& nodeName)
11941199
PathName savedName = expandedName;
11951200
expandedName.erase(0, prefix.length());
11961201

1197-
const PathName::size_type separator = expandedName.find(':');
1202+
PathName::size_type separator = expandedName.find(':');
1203+
1204+
#ifdef WIN_NT
1205+
if (separator == 1)
1206+
{
1207+
const char driveLetter = expandedName[0];
1208+
if ((driveLetter >= 'A' && driveLetter <= 'Z') || (driveLetter >= 'a' && driveLetter <= 'z'))
1209+
separator = expandedName.find(':', separator + 1);
1210+
}
1211+
#endif
1212+
11981213
if (separator == PathName::npos || separator == 0 || separator == expandedName.length() - 1)
11991214
{
12001215
expandedName = savedName;
@@ -7962,7 +7977,7 @@ static rem_port* analyze(ClntAuthBlock& cBlock, PathName& attach_name, unsigned
79627977
else
79637978
#endif
79647979

7965-
#if !defined(WIN_NT) && defined(HAVE_SYS_UN_H)
7980+
#ifdef HAVE_AF_UNIX_SUPPORT
79667981
if (analyzeUnixProtocol(attach_name, node_name))
79677982
{
79687983
ISC_utf8ToSystem(node_name);

0 commit comments

Comments
 (0)