mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 22:02:49 -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
|
|
@ -3,26 +3,31 @@
|
|||
using namespace Upp;
|
||||
|
||||
// Start reference/UnixSocketServer before starting this program
|
||||
String GetSocketPath()
|
||||
{
|
||||
String temp;
|
||||
#ifdef PLATFORM_WIN32
|
||||
temp = GetEnv("TEMP");
|
||||
#else
|
||||
temp = GetTempPath();
|
||||
#endif
|
||||
return AppendFileName(temp, "upp-unixsocket.socket");
|
||||
}
|
||||
|
||||
String Request(const String r)
|
||||
{
|
||||
Socket s;
|
||||
if(!s.ConnectFileSystem(GetSocketPath())) {
|
||||
Cout() << "Unable to connect to server!\n";
|
||||
SetExitCode(1);
|
||||
return String();
|
||||
}
|
||||
s.Put(r + '\n');
|
||||
return s.GetLine();
|
||||
}
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
#ifdef PLATFORM_POSIX
|
||||
auto Request = [](const String& r)
|
||||
{
|
||||
Socket s;
|
||||
if(!s.ConnectFileSystem("/tmp/upp-unixsocket.sock")) {
|
||||
Cout() << "Unable to connect to server!\n";
|
||||
SetExitCode(1);
|
||||
return String();
|
||||
}
|
||||
s.Put(r + '\n');
|
||||
return s.GetLine();
|
||||
};
|
||||
|
||||
Cout() << Request("time") << '\n';
|
||||
Cout() << Request("33") << '\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