Core/Socket: Unix domain socket (AF_UNIX) support for Windows (#328)

Refactor UnixSocket.cpp with error handling

Updated UnixSocket.cpp to include error handling and platform-specific path definitions.

UnixSocketClient: Update socket path for cross-platform compatibility

UnixSocketServer: Update socket path for Windows and Unix platforms

Core: UnixSocket example code, socket path fixed

autotest/UnixSocket: path correction and unlink.
This commit is contained in:
İsmail Yılmaz 2026-01-17 18:56:18 +00:00 committed by GitHub
parent 5124794175
commit e038550cb2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 167 additions and 122 deletions

View file

@ -2,13 +2,23 @@
using namespace Upp;
String GetSocketPath()
{
String temp;
#ifdef PLATFORM_WIN32
temp = GetEnv("TEMP");
#else
temp = GetTempPath();
#endif
return AppendFileName(temp, "upp-unixsocket.socket");
}
CONSOLE_APP_MAIN
{
#ifdef PLATFORM_POSIX
const String& path = "/tmp/upp-unixsocket.sock";
Socket server;
if(!server.ListenFileSystem(path, 5)) {
String path = GetSocketPath();
DeleteFile(path); // "unlink" existing file system socket
if(!server.ListenFileSystem(path, 5, false)) { // Reuse option is not available on Windows
Cout() << "Unable to initialize server socket!\n";
SetExitCode(1);
return;
@ -26,8 +36,4 @@ CONSOLE_APP_MAIN
s.Put("\n");
}
}
#else
Cout() << "This example requires a POSIX compliant operating system...\r\n"
SetExitCode(1);
#endif
}