mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
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:
parent
5124794175
commit
e038550cb2
6 changed files with 167 additions and 122 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue